Skip to content

Commit

Permalink
trying to fix wrong consent expiration mail (#553)
Browse files Browse the repository at this point in the history
* added: env variable for CAMPAIGN_ADMIN_MAIL in deployment config

* added filtering for valid consents when checking expiration dates

---------

Co-authored-by: igoychev <[email protected]>
  • Loading branch information
quantum-grit and igoychev authored Sep 24, 2023
1 parent 4ff31dc commit 8f3c143
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
11 changes: 9 additions & 2 deletions apps/api/src/tasks/bank-import/import-transactions.task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'),
},
],
},
})
Expand All @@ -781,6 +786,7 @@ describe('ImportTransactionsTask', () => {

// 3 < 5 => notify for expiring consent
expect(getConsentLinkSpy).toHaveBeenCalled()

expect(emailService.sendFromTemplate).toHaveBeenCalled()
})
})
Expand All @@ -805,6 +811,7 @@ describe('ImportTransactionsTask', () => {
consents: [
{
iban: IBAN,
status: 'valid',
validUntil: DateTime.now().plus({ days: 6 }).toFormat('yyyy-MM-dd'),
},
],
Expand Down
16 changes: 9 additions & 7 deletions apps/api/src/tasks/bank-import/import-transactions.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -107,7 +109,7 @@ export class IrisTasks {
const recepient = { to: [this.billingAdminEmail] }
const mail = new ExpiringIrisConsentEmailDto({
daysToExpire,
expiresAt: consent.validUntil,
expiresAt: expDate.toISODate(),
renewLink,
})

Expand Down

0 comments on commit 8f3c143

Please sign in to comment.