Skip to content

Commit

Permalink
test: api-tests on update chosen fsp AB#31025 (#6006)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisvisser authored Oct 31, 2024
1 parent dd35603 commit 862a1b8
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Update chosen FSP of PA should fail when updating chosen FSP when a required property of new FSP is not yet present 1`] = `
{
"message": "addressStreet: Cannot update 'addressStreet' is required for the FSP: 'Intersolve-visa', addressHouseNumber: Cannot update 'addressHouseNumber' is required for the FSP: 'Intersolve-visa', addressPostalCode: Cannot update 'addressPostalCode' is required for the FSP: 'Intersolve-visa', addressCity: Cannot update 'addressCity' is required for the FSP: 'Intersolve-visa'",
"statusCode": 400,
}
`;
124 changes: 124 additions & 0 deletions services/121-service/test/registrations/update-chosen-fsp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { HttpStatus } from '@nestjs/common';

import { SeedScript } from '@121-service/src/scripts/seed-script.enum';
import { registrationVisa } from '@121-service/src/seed-data/mock/visa-card.data';
import {
importRegistrations,
updateRegistration,
} from '@121-service/test/helpers/registration.helper';
import {
getAccessToken,
resetDB,
} from '@121-service/test/helpers/utility.helper';
import { registrationPvScoped } from '@121-service/test/registrations/pagination/pagination-data';

const programIdPv = 2;
const programIdOcw = 3;

async function setupNlrcEnvironment() {
await resetDB(SeedScript.nlrcMultiple);
const accessToken = await getAccessToken();

await importRegistrations(programIdOcw, [registrationVisa], accessToken);
await importRegistrations(programIdPv, [registrationPvScoped], accessToken);

return accessToken;
}

describe('Update chosen FSP of PA', () => {
let accessToken: string;

beforeEach(async () => {
accessToken = await setupNlrcEnvironment();
});

it('should succeed when updating chosen FSP when all required properties of new FSP are already present', async () => {
// Arrange
await setupNlrcEnvironment();

// Intersolve-visa and Intersolve-voucher-whatsapp both have 'whatsappPhoneNumber' as required
const newProgramFinancialServiceProviderConfigurationName =
'Intersolve-voucher-whatsapp';
const dataUpdate = {
programFinancialServiceProviderConfigurationName:
newProgramFinancialServiceProviderConfigurationName,
};
const reason = 'automated test';

// Act
const response = await updateRegistration(
programIdOcw,
registrationVisa.referenceId,
dataUpdate,
reason,
accessToken,
);

// Assert
expect(response.statusCode).toBe(HttpStatus.OK);
expect(response.body.financialServiceProviderName).toBe(
newProgramFinancialServiceProviderConfigurationName,
);
});

it('should fail when updating chosen FSP when a required property of new FSP is not yet present', async () => {
// Arrange
await setupNlrcEnvironment();

// Intersolve-voucher-whtatsapp does not have e.g. addressStreet which is required for Intersolve-visa
const newProgramFinancialServiceProviderConfigurationName =
'Intersolve-visa';
const dataUpdate = {
programFinancialServiceProviderConfigurationName:
newProgramFinancialServiceProviderConfigurationName,
};
const reason = 'automated test';

// Act
const response = await updateRegistration(
programIdPv,
registrationPvScoped.referenceId,
dataUpdate,
reason,
accessToken,
);

// Assert
expect(response.statusCode).toBe(HttpStatus.BAD_REQUEST);
expect(response.body).toMatchSnapshot();
});

it('should succeed when updating chosen FSP when missing required properties of new FSP are passed along with the request', async () => {
// Arrange
await setupNlrcEnvironment();

// Intersolve-voucher-whtatsapp does not have e.g. addressStreet which is required for Intersolve-visa
// The missing attributes can be passed along (or can be updated first)
const newProgramFinancialServiceProviderConfigurationName =
'Intersolve-visa';
const dataUpdate = {
programFinancialServiceProviderConfigurationName:
newProgramFinancialServiceProviderConfigurationName,
addressStreet: 'Teststraat 1',
addressHouseNumber: '1',
addressCity: 'Teststad',
addressPostalCode: '1234AB',
};
const reason = 'automated test';

// Act
const response = await updateRegistration(
programIdPv,
registrationPvScoped.referenceId,
dataUpdate,
reason,
accessToken,
);

// Assert
expect(response.statusCode).toBe(HttpStatus.OK);
expect(response.body.financialServiceProviderName).toBe(
newProgramFinancialServiceProviderConfigurationName,
);
});
});

0 comments on commit 862a1b8

Please sign in to comment.