Skip to content

Commit

Permalink
feat(DTFS2-7052): changing variables to use plural
Browse files Browse the repository at this point in the history
  • Loading branch information
avaitonis committed Apr 25, 2024
1 parent 15743c0 commit c020867
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
10 changes: 5 additions & 5 deletions src/modules/geospatial/geospatial.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('GeospatialController', () => {
let controller: GeospatialController;

const valueGenerator = new RandomValueGenerator();
const { getAddressByPostcodeResponse, getAddressByPostcodeMultipleResponse } = new GetGeospatialAddressesGenerator(valueGenerator).generate({
const { getAddressesByPostcodeResponse, getAddressesByPostcodeMultipleResponse } = new GetGeospatialAddressesGenerator(valueGenerator).generate({
numberToGenerate: 2,
});

Expand All @@ -33,21 +33,21 @@ describe('GeospatialController', () => {
const postcode = GEOSPATIAL.EXAMPLES.POSTCODE;

it('returns a single address for the postcode when the service returns a single address', async () => {
when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressByPostcodeResponse[0]);
when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesByPostcodeResponse[0]);

const response = await controller.getAddressesByPostcode({ postcode });

expect(geospatialServiceGetAddressesByPostcode).toHaveBeenCalledTimes(1);
expect(response).toEqual(getAddressByPostcodeResponse[0]);
expect(response).toEqual(getAddressesByPostcodeResponse[0]);
});

it('returns multiple addresses for the postcode when the service returns multiple addresses', async () => {
when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressByPostcodeMultipleResponse);
when(geospatialServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesByPostcodeMultipleResponse);

const response = await controller.getAddressesByPostcode({ postcode });

expect(geospatialServiceGetAddressesByPostcode).toHaveBeenCalledTimes(1);
expect(response).toEqual(getAddressByPostcodeMultipleResponse);
expect(response).toEqual(getAddressesByPostcodeMultipleResponse);
});

it('returns an empty response for the postcode when the service returns an empty response', async () => {
Expand Down
24 changes: 12 additions & 12 deletions src/modules/geospatial/geospatial.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@ describe('GeospatialService', () => {

describe('getAddressesByPostcode', () => {
const {
getAddressByPostcodeResponse,
getAddressByPostcodeMultipleResponse,
getAddressOrdnanceSurveyResponse,
getAddressOrdnanceSurveyMultipleResponse,
getAddressOrdnanceSurveyEmptyResponse,
getAddressesByPostcodeResponse,
getAddressesByPostcodeMultipleResponse,
getAddressesOrdnanceSurveyResponse,
getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse,
getAddressesOrdnanceSurveyEmptyResponse,
} = new GetGeospatialAddressesGenerator(valueGenerator).generate({
numberToGenerate: 2,
});
const postcode = getAddressByPostcodeResponse[0][0].postalCode;
const postcode = getAddressesByPostcodeResponse[0][0].postalCode;

it('returns a single address from the backend service', async () => {
when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressOrdnanceSurveyResponse[0]);
when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesOrdnanceSurveyResponse[0]);

const response = await service.getAddressesByPostcode(postcode);

expect(response).toEqual(getAddressByPostcodeResponse[0]);
expect(response).toEqual(getAddressesByPostcodeResponse[0]);
});

it('returns multiple addressess from the backend service', async () => {
when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressOrdnanceSurveyMultipleResponse);
when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse);

const response = await service.getAddressesByPostcode(postcode);

expect(response).toEqual(getAddressByPostcodeMultipleResponse);
expect(response).toEqual(getAddressesByPostcodeMultipleResponse);
});

it('can handle empty backend response', async () => {
when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressOrdnanceSurveyEmptyResponse[0]);
when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(getAddressesOrdnanceSurveyEmptyResponse[0]);

const response = await service.getAddressesByPostcode(postcode);

expect(response).toEqual([]);
});

it('returns addressLine1 formatted correctly even if middle value is missing', async () => {
const [modifiedOrdnanceSurveyResponse] = structuredClone(getAddressOrdnanceSurveyResponse);
const [modifiedOrdnanceSurveyResponse] = structuredClone(getAddressesOrdnanceSurveyResponse);
modifiedOrdnanceSurveyResponse.results[0].DPA.BUILDING_NUMBER = null;
const address = modifiedOrdnanceSurveyResponse.results[0].DPA;
when(ordnanceSurveyServiceGetAddressesByPostcode).calledWith(postcode).mockResolvedValueOnce(modifiedOrdnanceSurveyResponse);
Expand Down
50 changes: 25 additions & 25 deletions test/geospatial/get-address-by-postcode.api-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => {
let api: Api;

const {
ordnanceSurveyPath,
mdmPath,
getAddressByPostcodeResponse,
getAddressByPostcodeMultipleResponse,
getAddressOrdnanceSurveyResponse,
getAddressOrdnanceSurveyEmptyResponse,
getAddressOrdnanceSurveyMultipleResponse,
ordnanceSurveyPaths,
mdmPaths,
getAddressesByPostcodeResponse,
getAddressesByPostcodeMultipleResponse,
getAddressesOrdnanceSurveyResponse,
getAddressesOrdnanceSurveyEmptyResponse,
getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse,
ordnanceSurveyAuthErrorResponse,
} = new GetGeospatialAddressesGenerator(valueGenerator).generate({
postcode: GEOSPATIAL.EXAMPLES.POSTCODE,
Expand All @@ -44,42 +44,42 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => {
// MDM auth tests
withClientAuthenticationTests({
givenTheRequestWouldOtherwiseSucceed: () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyResponse[0]);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyResponse[0]);
},
makeRequestWithoutAuth: (incorrectAuth?: IncorrectAuthArg) => api.getWithoutAuth(mdmPath[0], incorrectAuth?.headerName, incorrectAuth?.headerValue),
makeRequestWithoutAuth: (incorrectAuth?: IncorrectAuthArg) => api.getWithoutAuth(mdmPaths[0], incorrectAuth?.headerName, incorrectAuth?.headerValue),
});

it('returns a 200 response with the address if it is returned by Ordnance Survey API', async () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyResponse[0]);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyResponse[0]);

const { status, body } = await api.get(mdmPath[0]);
const { status, body } = await api.get(mdmPaths[0]);

expect(status).toBe(200);
expect(body).toStrictEqual(getAddressByPostcodeResponse[0]);
expect(body).toStrictEqual(getAddressesByPostcodeResponse[0]);
});

it('returns a 200 response with the addresses if they are returned by Ordnance Survey API', async () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyMultipleResponse);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse);

const { status, body } = await api.get(mdmPath[0]);
const { status, body } = await api.get(mdmPaths[0]);

expect(status).toBe(200);
expect(body).toStrictEqual(getAddressByPostcodeMultipleResponse);
expect(body).toStrictEqual(getAddressesByPostcodeMultipleResponse);
});

it('returns an empty 200 response if Ordnance Survey API returns a 200 without results', async () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(200, getAddressOrdnanceSurveyEmptyResponse[0]);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(200, getAddressesOrdnanceSurveyEmptyResponse[0]);

const { status, body } = await api.get(mdmPath[0]);
const { status, body } = await api.get(mdmPaths[0]);

expect(status).toBe(200);
expect(body).toStrictEqual([]);
});

it('returns a 500 response if Ordnance Survey API returns a status code 401', async () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(401);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(401);

const { status, body } = await api.get(mdmPath[0]);
const { status, body } = await api.get(mdmPaths[0]);

expect(status).toBe(500);
expect(body).toStrictEqual({
Expand All @@ -89,9 +89,9 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => {
});

it('returns a 500 response if Ordnance Survey API returns a status code 404', async () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(404);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(404);

const { status, body } = await api.get(mdmPath[0]);
const { status, body } = await api.get(mdmPaths[0]);

expect(status).toBe(500);
expect(body).toStrictEqual({
Expand All @@ -101,9 +101,9 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => {
});

it('returns a 500 response if Ordnance Survey API times out', async () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).delay(TIME_EXCEEDING_ORDNANCE_SURVEY_TIMEOUT).reply(200, getAddressOrdnanceSurveyResponse[0]);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).delay(TIME_EXCEEDING_ORDNANCE_SURVEY_TIMEOUT).reply(200, getAddressesOrdnanceSurveyResponse[0]);

const { status, body } = await api.get(mdmPath[0]);
const { status, body } = await api.get(mdmPaths[0]);

expect(status).toBe(500);
expect(body).toStrictEqual({
Expand All @@ -113,9 +113,9 @@ describe('GET /geospatial/addresses/postcode?postcode=', () => {
});

it('returns a 500 response if Ordnance Survey API returns error', async () => {
requestToGetAddressesByPostcode(ordnanceSurveyPath[0]).reply(401, ordnanceSurveyAuthErrorResponse);
requestToGetAddressesByPostcode(ordnanceSurveyPaths[0]).reply(401, ordnanceSurveyAuthErrorResponse);

const { status, body } = await api.get(mdmPath[0]);
const { status, body } = await api.get(mdmPaths[0]);

expect(status).toBe(500);
expect(body).toStrictEqual({
Expand Down
28 changes: 14 additions & 14 deletions test/support/generator/get-geospatial-addresses-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ export class GetGeospatialAddressesGenerator extends AbstractGenerator<AddressVa

return {
requests,
ordnanceSurveyPath: ordnanceSurveyPaths,
mdmPath: mdmPaths,
getAddressByPostcodeResponse: getAddressesByPostcodeResponse,
getAddressByPostcodeMultipleResponse: getAddressesByPostcodeMultipleResponse,
getAddressOrdnanceSurveyResponse: getAddressesOrdnanceSurveyResponse,
getAddressOrdnanceSurveyEmptyResponse: getAddressesOrdnanceSurveyEmptyResponse,
getAddressOrdnanceSurveyMultipleResponse: getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse,
ordnanceSurveyPaths,
mdmPaths,
getAddressesByPostcodeResponse,
getAddressesByPostcodeMultipleResponse,
getAddressesOrdnanceSurveyResponse,
getAddressesOrdnanceSurveyEmptyResponse,
getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse,
ordnanceSurveyAuthErrorResponse,
};
}
Expand All @@ -219,12 +219,12 @@ interface GenerateOptions {

interface GenerateResult {
requests: GetAddressesByPostcodeQueryDto[];
ordnanceSurveyPath: string[];
mdmPath: string[];
getAddressByPostcodeResponse: GetAddressesResponse[];
getAddressByPostcodeMultipleResponse: GetAddressesResponse;
getAddressOrdnanceSurveyResponse: GetAddressesOrdnanceSurveyResponse[];
getAddressOrdnanceSurveyMultipleResponse: GetAddressesOrdnanceSurveyResponse;
getAddressOrdnanceSurveyEmptyResponse: GetAddressesOrdnanceSurveyResponse;
ordnanceSurveyPaths: string[];
mdmPaths: string[];
getAddressesByPostcodeResponse: GetAddressesResponse[];
getAddressesByPostcodeMultipleResponse: GetAddressesResponse;
getAddressesOrdnanceSurveyResponse: GetAddressesOrdnanceSurveyResponse[];
getAddressesOrdnanceSurveyMultipleMatchingAddressesResponse: GetAddressesOrdnanceSurveyResponse;
getAddressesOrdnanceSurveyEmptyResponse: GetAddressesOrdnanceSurveyResponse;
ordnanceSurveyAuthErrorResponse: OrdnanceSurveyAuthErrorResponse;
}

0 comments on commit c020867

Please sign in to comment.