From 60c21a1b93a56af06c60f73bb62b00bd1a17f4b5 Mon Sep 17 00:00:00 2001 From: Tim van Oostrom Date: Thu, 28 Nov 2024 12:06:18 +0100 Subject: [PATCH] Fix transactions (#1634) --- mocks/fixtures/gpass-transacties.json | 22 +++++++++++ mocks/routes/gpass.js | 12 ++---- .../hli/stadspas-gpass-service.test.ts | 38 +++++++++++++++++++ .../services/hli/stadspas-gpass-service.ts | 9 ++++- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/mocks/fixtures/gpass-transacties.json b/mocks/fixtures/gpass-transacties.json index 990e3b1339..91594cc652 100644 --- a/mocks/fixtures/gpass-transacties.json +++ b/mocks/fixtures/gpass-transacties.json @@ -134,6 +134,28 @@ "aanbieder": { "id": 222222, "naam": "Fietsenwinkel - B.V. 5" } } }, + { + "id": 66, + "transactiedatum": "2020-10-05T04:01:01.0000", + "bedrag": -19, + "pashouder": { "id": 1, "hoofd_pashouder_id": 2 }, + "pas": { + "id": 2, + "pasnummer": 6666666666666, + "pasnummer_volledig": "66666666666666", + "originele_pas": { + "id": 1, + "pasnummer": 66666666666666, + "pasnummer_volledig": "66666666666666" + } + }, + "budget": { + "id": 44, + "code": "GPAS05_19", + "naam": "Schoolactiviteiten", + "aanbieder": { "id": 222222, "naam": "Fietsenwinkel - B.V. 5" } + } + }, { "id": 7, "transactiedatum": "2020-10-05T04:01:01.0000", diff --git a/mocks/routes/gpass.js b/mocks/routes/gpass.js index b2e7c7f371..e1ae6af72b 100644 --- a/mocks/routes/gpass.js +++ b/mocks/routes/gpass.js @@ -1,4 +1,5 @@ const UID = require('uid-safe'); + const settings = require('../settings'); const RESPONSES = { PASHOUDER: require('../fixtures/gpass-pashouders.json'), @@ -29,15 +30,10 @@ module.exports = [ variants: [ { id: 'standard', - type: 'middleware', + type: 'json', options: { - middleware(req, res, next) { - return res.send( - Object.assign(RESPONSES.STADSPAS, { - id: `stadspas-${UID.sync(18)}`, - }) - ); - }, + status: 200, + body: RESPONSES.STADSPAS, }, }, ], diff --git a/src/server/services/hli/stadspas-gpass-service.test.ts b/src/server/services/hli/stadspas-gpass-service.test.ts index 0487a70e99..a479e26b3e 100644 --- a/src/server/services/hli/stadspas-gpass-service.test.ts +++ b/src/server/services/hli/stadspas-gpass-service.test.ts @@ -227,6 +227,34 @@ describe('stadspas-gpass-service', () => { }, }, }, + { + id: 1, + budget: { + aanbieder: { + naam: 'Provider', + id: 0, + }, + naam: 'Budget Name', + code: '123', + id: 0, + }, + bedrag: 100, + transactiedatum: '2023-01-01', + pashouder: { + id: 0, + hoofd_pashouder_id: 0, + }, + pas: { + id: 0, + pasnummer: 0, + pasnummer_volledig: '', + originele_pas: { + id: 0, + pasnummer: 0, + pasnummer_volledig: '', + }, + }, + }, ], number_of_items: 0, total_items: 0, @@ -240,6 +268,16 @@ describe('stadspas-gpass-service', () => { id: '1', title: 'Provider', amount: -100, + amountFormatted: '+ €100,00', + datePublished: '2023-01-01', + datePublishedFormatted: '01 januari 2023', + budget: 'Budget Name', + budgetCode: '123', + }, + { + id: '1', + title: 'Provider', + amount: 100, amountFormatted: '- €100,00', datePublished: '2023-01-01', datePublishedFormatted: '01 januari 2023', diff --git a/src/server/services/hli/stadspas-gpass-service.ts b/src/server/services/hli/stadspas-gpass-service.ts index 5cc827fcf1..9b96568cd1 100644 --- a/src/server/services/hli/stadspas-gpass-service.ts +++ b/src/server/services/hli/stadspas-gpass-service.ts @@ -99,7 +99,7 @@ function transformStadspasResponse( balanceFormatted: `€${displayAmount(balance)}`, passNumber: gpassStadspasResonseData.pasnummer, passNumberComplete: gpassStadspasResonseData.pasnummer_volledig, - securityCode + securityCode, }; return stadspasTransformed; @@ -217,11 +217,16 @@ function transformGpassTransactionsResponse( if (Array.isArray(responseSource.transacties)) { return responseSource.transacties.map( (transactie: StadspasTransactieSource) => { + const isCredited = transactie.bedrag < 0; + const amountFormatted = isCredited + ? `+ €${displayAmount(Math.abs(transactie.bedrag))}` + : `- €${displayAmount(transactie.bedrag)}`; + const transaction: StadspasBudgetTransaction = { id: String(transactie.id), title: transactie.budget.aanbieder.naam, amount: transactie.bedrag, - amountFormatted: `- €${displayAmount(Math.abs(transactie.bedrag))}`, + amountFormatted, datePublished: transactie.transactiedatum, datePublishedFormatted: defaultDateFormat(transactie.transactiedatum), budget: transactie.budget.naam,