diff --git a/apps/api/src/tasks/bank-import/import-transactions.task.spec.ts b/apps/api/src/tasks/bank-import/import-transactions.task.spec.ts index cce78f1af..8602e1a59 100644 --- a/apps/api/src/tasks/bank-import/import-transactions.task.spec.ts +++ b/apps/api/src/tasks/bank-import/import-transactions.task.spec.ts @@ -559,8 +559,7 @@ describe('ImportTransactionsTask', () => { it('should handle USD currency and parse the BGN equivalent from the transactionId', () => { const eurTransaction: IrisTransactionInfo = { - transactionId: - 'Booked_6516347588_70001524349032963FTRO23184809601C2023010361.12_20230103', + transactionId: 'Booked_6516347588_70001524349032963FTRO23184809601C2023010361.12_20230103', bookingDate: '2023-01-03', creditorAccount: { iban: 'BG66UNCR70001524349032', @@ -764,8 +763,14 @@ describe('ImportTransactionsTask', () => { consents: [ { iban: IBAN, + status: 'valid', validUntil: DateTime.now().plus({ days: 3 }).toFormat('yyyy-MM-dd'), }, + { + iban: IBAN, + status: 'expired', + validUntil: DateTime.now().minus({ days: 3 }).toFormat('yyyy-MM-dd'), + }, ], }, }) @@ -781,6 +786,7 @@ describe('ImportTransactionsTask', () => { // 3 < 5 => notify for expiring consent expect(getConsentLinkSpy).toHaveBeenCalled() + expect(emailService.sendFromTemplate).toHaveBeenCalled() }) }) @@ -805,6 +811,7 @@ describe('ImportTransactionsTask', () => { consents: [ { iban: IBAN, + status: 'valid', validUntil: DateTime.now().plus({ days: 6 }).toFormat('yyyy-MM-dd'), }, ], diff --git a/apps/api/src/tasks/bank-import/import-transactions.task.ts b/apps/api/src/tasks/bank-import/import-transactions.task.ts index 1d5332517..9ff1ac896 100644 --- a/apps/api/src/tasks/bank-import/import-transactions.task.ts +++ b/apps/api/src/tasks/bank-import/import-transactions.task.ts @@ -90,13 +90,15 @@ export class IrisTasks { }) ).data - // Filter to current IBAN - const consent = consents.consents.find((consent) => consent.iban.trim() === this.IBAN) + // Filter valid consents to the current IBAN + const consent = consents.consents.find( + (consent) => consent.iban.trim() === this.IBAN && consent.status === 'valid', + ) - if (!consent) return - - const expDate = DateTime.fromFormat(consent.validUntil, 'yyyy-MM-dd') - const daysToExpire = Math.ceil(expDate.diff(DateTime.local(), 'days').toObject().days || 0) + const expDate = consent + ? DateTime.fromFormat(consent.validUntil, 'yyyy-MM-dd') + : DateTime.local() //if no valid consent use today to send mail with days to expire 0 + const daysToExpire = Math.ceil(expDate.diff(DateTime.local(), 'days').days || 0) // If less than 5 days till expiration -> notify if (daysToExpire <= this.daysToExpCondition) { @@ -107,7 +109,7 @@ export class IrisTasks { const recepient = { to: [this.billingAdminEmail] } const mail = new ExpiringIrisConsentEmailDto({ daysToExpire, - expiresAt: consent.validUntil, + expiresAt: expDate.toISODate(), renewLink, })