Skip to content

Commit

Permalink
Added securityCode field and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RoanPaulus committed Nov 7, 2024
1 parent 155e18d commit 58c08e3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ describe('hli/router-external-consumer', async () => {
content: [
{
foo: 'bar',
securityCode: null,
transactionsKeyEncrypted: TRANSACTIONS_KEY_ENCRYPTED,
},
],
Expand Down
1 change: 0 additions & 1 deletion src/server/routing/router-stadspas-external-consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ async function sendStadspassenResponse(
return {
...stadspas,
// AMSAPP wants this extra field because GPASS promises to deliver this in the fourth quarter (Q4).
securityCode: null,
transactionsKeyEncrypted,
};
});
Expand Down
42 changes: 38 additions & 4 deletions src/server/services/hli/stadspas-gpass-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ describe('stadspas-gpass-service', () => {
id: 0,
naam: '',
},
pashouder: {
initialen: '',
achternaam: '',
tussenvoegsel: '',
voornaam: '',
passen: [],
volledige_naam: '',
},
};
const pashouder: StadspasHouderSource = {
voornaam: 'John',
Expand All @@ -131,7 +139,8 @@ describe('stadspas-gpass-service', () => {
};
const transformedResponse = forTesting.transformStadspasResponse(
gpassStadspasResonseData,
pashouder
pashouder,
'0123456'
);
expect(transformedResponse).toStrictEqual({
id: '1',
Expand Down Expand Up @@ -160,6 +169,7 @@ describe('stadspas-gpass-service', () => {
balanceFormatted: '€500,00',
passNumber: 12345,
passNumberComplete: '12345-67890',
securityCode: '0123456',
});
});

Expand All @@ -178,7 +188,8 @@ describe('stadspas-gpass-service', () => {

const transformedResponse = forTesting.transformStadspasResponse(
gpassStadspasResonseData,
pashouder
pashouder,
'0123456'
);
expect(transformedResponse).toEqual(gpassStadspasResonseData);
});
Expand Down Expand Up @@ -458,8 +469,18 @@ describe('stadspas-gpass-service', () => {
initialen: 'J.D.',
passen: [
{
pasnummer: 999999999,
actief: true,
budgetten: [],
categorie: '',
categorie_code: '',
expiry_date: '',
heeft_budget: false,
id: 1,
pasnummer: 999999999,
pasnummer_volledig: '',
passoort: { id: 1, naam: '' },
securitycode: '0123456',
vervangen: false,
},
],
};
Expand Down Expand Up @@ -504,6 +525,14 @@ describe('stadspas-gpass-service', () => {
id: 0,
naam: '',
},
pashouder: {
initialen: '',
achternaam: '',
tussenvoegsel: '',
voornaam: '',
passen: [],
volledige_naam: '',
},
};

(requestData as Mock)
Expand All @@ -514,7 +543,11 @@ describe('stadspas-gpass-service', () => {
.mockResolvedValueOnce({
status: 'OK',
content: [
forTesting.transformStadspasResponse(stadspasDetail, pashouder),
forTesting.transformStadspasResponse(
stadspasDetail,
pashouder,
'0123456'
),
],
});

Expand Down Expand Up @@ -553,6 +586,7 @@ describe('stadspas-gpass-service', () => {
balanceFormatted: '€500,00',
passNumber: 999999999,
passNumberComplete: '12345-67890',
securityCode: '0123456',
},
],
administratienummer: '12345',
Expand Down
7 changes: 5 additions & 2 deletions src/server/services/hli/stadspas-gpass-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import memoizee from 'memoizee';
import { fetchAdministratienummer } from './hli-zorgned-service';
import { GPASS_API_TOKEN } from './stadspas-config-and-content';
import {
SecurityCode,
Stadspas,
StadspasAanbiedingSource,
StadspasBudget,
Expand Down Expand Up @@ -73,7 +74,8 @@ function transformBudget(budget: StadspasDetailBudgetSource) {

function transformStadspasResponse(
gpassStadspasResonseData: StadspasDetailSource,
pashouder: StadspasHouderSource
pashouder: StadspasHouderSource,
securityCode: SecurityCode
) {
if (
typeof gpassStadspasResonseData === 'object' &&
Expand All @@ -97,6 +99,7 @@ function transformStadspasResponse(
balanceFormatted: `€${displayAmount(balance)}`,
passNumber: gpassStadspasResonseData.pasnummer,
passNumberComplete: gpassStadspasResonseData.pasnummer_volledig,
securityCode
};

return stadspasTransformed;
Expand Down Expand Up @@ -154,7 +157,7 @@ export async function fetchStadspassenByAdministratienummer(
...dataRequestConfig,
url,
transformResponse: (stadspas) =>
transformStadspasResponse(stadspas, pashouder),
transformStadspasResponse(stadspas, pashouder, pas.securitycode),
headers,
params: {
include_balance: true,
Expand Down
5 changes: 4 additions & 1 deletion src/server/services/hli/stadspas-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export interface StadspasDiscountTransactionsResponseSource {
transacties: StadspasAanbiedingSource[];
}

export type SecurityCode = string;

export interface StadspasHouderPasSource {
actief: boolean;
budgetten: unknown[]; // Did not see the exact shape of this data, encountered an empty array.
Expand All @@ -92,7 +94,7 @@ export interface StadspasHouderPasSource {
pasnummer: number;
pasnummer_volledig: string;
passoort: { id: number, naam: string };
securitycode: string;
securitycode: SecurityCode;
vervangen: boolean;
}

Expand Down Expand Up @@ -171,6 +173,7 @@ export interface Stadspas {
budgets: StadspasBudget[];
balanceFormatted: string;
balance: number;
securityCode: SecurityCode;
}

export interface StadspasFrontend extends Stadspas {
Expand Down
10 changes: 10 additions & 0 deletions src/server/services/hli/stadspas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ const pashouderResponse = {
{
actief: false,
pasnummer: 444444444444,
securitycode: '012345',
},
{
actief: true,
pasnummer: 333333333333,
securitycode: '012345',
},
],
sub_pashouders: [
Expand All @@ -35,10 +37,12 @@ const pashouderResponse = {
{
actief: true,
pasnummer: 666666666666,
securitycode: '012345',
},
{
actief: false,
pasnummer: 555555555555,
securitycode: '012345',
},
],
},
Expand All @@ -50,10 +54,12 @@ const pashouderResponse = {
{
actief: true,
pasnummer: 777777777777,
securitycode: '012345',
},
{
actief: false,
pasnummer: 888888888888,
securitycode: '012345',
},
],
},
Expand Down Expand Up @@ -224,6 +230,7 @@ describe('stadspas services', () => {
},
"passNumber": 6666666666666,
"passNumberComplete": "6666666666666666666",
"securityCode": "012345",
},
],
},
Expand Down Expand Up @@ -297,6 +304,7 @@ describe('stadspas services', () => {
},
"passNumber": 6666666666666,
"passNumberComplete": "6666666666666666666",
"securityCode": "012345",
},
{
"balance": 0,
Expand Down Expand Up @@ -325,6 +333,7 @@ describe('stadspas services', () => {
},
"passNumber": 6666666666666,
"passNumberComplete": "6666666666666666666",
"securityCode": "012345",
},
{
"balance": 0,
Expand Down Expand Up @@ -353,6 +362,7 @@ describe('stadspas services', () => {
},
"passNumber": 6666666666666,
"passNumberComplete": "6666666666666666666",
"securityCode": "012345",
},
],
},
Expand Down

0 comments on commit 58c08e3

Please sign in to comment.