Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIJN-9459-FEATURE-security-code-doorsturen-naar-amsterdam-app-stadspas-api-voor-app-team #1583

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mocks/fixtures/gpass-pashouders.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"expiry_date": "2023-07-31T21:59:59.000Z",
"heeft_budget": false,
"vervangen": false,
"securitycode": "012345",
"passoort": {
"id": 11,
"naam": "Digitale Stadspas"
Expand All @@ -68,6 +69,7 @@
"expiry_date": "2024-07-31T21:59:59.000Z",
"heeft_budget": false,
"vervangen": false,
"securitycode": "012346",
"passoort": {
"id": 11,
"naam": "Digitale Stadspas"
Expand Down Expand Up @@ -100,6 +102,7 @@
"actief": true,
"heeft_budget": true,
"vervangen": false,
"securitycode": "012347",
"budgetten": [
{
"code": "2023_AMSTEG_ENERGIE",
Expand All @@ -121,6 +124,7 @@
"actief": false,
"heeft_budget": false,
"vervangen": false,
"securitycode": "123458",
"budgetten": []
}
]
Expand Down Expand Up @@ -149,6 +153,7 @@
"actief": true,
"heeft_budget": true,
"vervangen": false,
"securitycode": "123459",
"budgetten": [
{
"code": "2023_AMSTEG_12-14",
Expand All @@ -170,6 +175,7 @@
"actief": false,
"heeft_budget": true,
"vervangen": false,
"securitycode": "123450",
"budgetten": []
}
]
Expand Down Expand Up @@ -198,6 +204,7 @@
"actief": true,
"heeft_budget": true,
"vervangen": false,
"securitycode": "123440",
"budgetten": [
{
"code": "2023_AMSTEG_15-17",
Expand All @@ -219,6 +226,7 @@
"actief": false,
"heeft_budget": false,
"vervangen": false,
"securitycode": "123430",
"budgetten": []
}
]
Expand Down Expand Up @@ -247,6 +255,7 @@
"actief": true,
"heeft_budget": true,
"vervangen": false,
"securitycode": "123420",
"budgetten": [
{
"code": "2023_AMSTEG_2-3_KVS",
Expand All @@ -272,6 +281,7 @@
"actief": false,
"heeft_budget": true,
"vervangen": false,
"securitycode": "123150",
"budgetten": []
}
]
Expand Down Expand Up @@ -300,6 +310,7 @@
"actief": true,
"heeft_budget": true,
"vervangen": false,
"securitycode": "122450",
"budgetten": [
{
"code": "AMSTEG_autom_laden_TEST",
Expand Down
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
14 changes: 14 additions & 0 deletions src/server/services/hli/stadspas-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,21 @@ 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De props stonden hier niet bij omdat we er niets mee doen..

categorie: string;
categorie_code: string;
expiry_date: string;
heeft_budget: boolean;
id: number;
pasnummer: number;
pasnummer_volledig: string;
passoort: { id: number, naam: string };
securitycode: SecurityCode;
vervangen: boolean;
}

export interface StadspasHouderSource {
Expand Down Expand Up @@ -128,6 +140,7 @@ export interface StadspasDetailSource {
pasnummer: number;
pasnummer_volledig: string;
passoort: { id: number; naam: string };
pashouder: StadspasHouderSource;
}

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

export interface StadspasFrontend extends Stadspas {
Expand Down
Loading