Skip to content

Commit

Permalink
feat(EMS-3687): application submission - xlsx - how was contract awarded
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbarnes committed Aug 6, 2024
1 parent aa98cf7 commit 1f4335e
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/api/.keystone/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mapExportContract from '.';
import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract';
import { XLSX } from '../../../content-strings';
import xlsxRow from '../helpers/xlsx-row';
import mapHowWasTheContractAwarded from './map-how-was-the-contract-awarded';
import mapFinalDestination from './map-final-destination';
import mapPrivateMarket from './map-private-market';
import mapAgent from './map-agent';
Expand All @@ -28,6 +29,8 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-export-contract', () =>
const expected = [
xlsxRow(String(FIELDS.EXPORT_CONTRACT[DESCRIPTION]), exportContract[DESCRIPTION]),

mapHowWasTheContractAwarded(exportContract),

...mapFinalDestination(exportContract, mockCountries),

xlsxRow(String(FIELDS.EXPORT_CONTRACT[PAYMENT_TERMS_DESCRIPTION]), exportContract[PAYMENT_TERMS_DESCRIPTION]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import FIELD_IDS from '../../../constants/field-ids/insurance/export-contract';
import { XLSX } from '../../../content-strings';
import xlsxRow from '../helpers/xlsx-row';
import mapHowWasTheContractAwarded from './map-how-was-the-contract-awarded';
import mapFinalDestination from './map-final-destination';
import mapPrivateMarket from './map-private-market';
import mapAgent from './map-agent';
Expand Down Expand Up @@ -31,6 +32,8 @@ const mapExportContract = (application: Application, countries: Array<Country>)
const mapped = [
xlsxRow(String(FIELDS.EXPORT_CONTRACT[DESCRIPTION]), exportContract[DESCRIPTION]),

mapHowWasTheContractAwarded(exportContract),

...mapFinalDestination(exportContract, countries),

xlsxRow(String(FIELDS.EXPORT_CONTRACT[PAYMENT_TERMS_DESCRIPTION]), exportContract[PAYMENT_TERMS_DESCRIPTION]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import mapHowWasTheContractAwarded from '.';
import { EXPORT_CONTRACT_AWARD_METHOD } from '../../../../constants';
import FIELD_IDS from '../../../../constants/field-ids/insurance/export-contract';
import { EXPORT_CONTRACT_FIELDS } from '../../../../content-strings/fields/insurance/export-contract';
import xlsxRow from '../../helpers/xlsx-row';
import { invalidId, mockApplication } from '../../../../test-mocks';

const { OPEN_TENDER, DIRECT_AWARD, COMPETITIVE_BIDDING, NEGOTIATED_CONTRACT, OTHER } = EXPORT_CONTRACT_AWARD_METHOD;

const CONTENT_STRINGS = EXPORT_CONTRACT_FIELDS.HOW_WAS_THE_CONTRACT_AWARDED;

const {
HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD },
} = FIELD_IDS;

const { exportContract } = mockApplication;

const expectedTitle = `${String(CONTENT_STRINGS[AWARD_METHOD].SUMMARY?.TITLE)}?`;

describe('api/generate-xlsx/map-application-to-xlsx/map-export-contract/map-how-was-the-contract-awarded', () => {
describe(`when awardMethodId is ${OTHER.DB_ID}`, () => {
const mockExportContract = {
...exportContract,
awardMethodId: OTHER.DB_ID,
};

it('should return a mapped field', () => {
const result = mapHowWasTheContractAwarded(mockExportContract);

const expected = xlsxRow(expectedTitle, mockExportContract[OTHER_AWARD_METHOD]);

expect(result).toEqual(expected);
});
});

describe(`when awardMethodId is ${NEGOTIATED_CONTRACT.DB_ID}`, () => {
const mockExportContract = {
...exportContract,
awardMethodId: NEGOTIATED_CONTRACT.DB_ID,
};

it('should return a mapped field', () => {
const result = mapHowWasTheContractAwarded(mockExportContract);

const expected = xlsxRow(expectedTitle, NEGOTIATED_CONTRACT.VALUE);

expect(result).toEqual(expected);
});
});

describe(`when awardMethodId is ${OPEN_TENDER.DB_ID}`, () => {
const mockExportContract = {
...exportContract,
awardMethodId: OPEN_TENDER.DB_ID,
};

it('should return a mapped field', () => {
const result = mapHowWasTheContractAwarded(mockExportContract);

const expected = xlsxRow(expectedTitle, OPEN_TENDER.VALUE);

expect(result).toEqual(expected);
});
});

describe(`when awardMethodId is ${DIRECT_AWARD.DB_ID}`, () => {
const mockExportContract = {
...exportContract,
awardMethodId: DIRECT_AWARD.DB_ID,
};

it('should return a mapped field', () => {
const result = mapHowWasTheContractAwarded(mockExportContract);

const expected = xlsxRow(expectedTitle, DIRECT_AWARD.VALUE);

expect(result).toEqual(expected);
});
});

describe(`when awardMethodId is ${COMPETITIVE_BIDDING.DB_ID}`, () => {
const mockExportContract = {
...exportContract,
awardMethodId: COMPETITIVE_BIDDING.DB_ID,
};

it('should return a mapped field', () => {
const result = mapHowWasTheContractAwarded(mockExportContract);

const expected = xlsxRow(expectedTitle, COMPETITIVE_BIDDING.VALUE);

expect(result).toEqual(expected);
});
});

describe('when an award method is not recognised', () => {
const mockExportContract = {
...exportContract,
awardMethodId: invalidId,
};

it('should return a mapped field with en empty answer', () => {
const result = mapHowWasTheContractAwarded(mockExportContract);

const expected = xlsxRow(expectedTitle, '');

expect(result).toEqual(expected);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { EXPORT_CONTRACT_AWARD_METHOD } from '../../../../constants';
import FIELD_IDS from '../../../../constants/field-ids/insurance/export-contract';
import { EXPORT_CONTRACT_FIELDS } from '../../../../content-strings/fields/insurance/export-contract';
import xlsxRow from '../../helpers/xlsx-row';
import { ApplicationExportContract } from '../../../../types';

const { OTHER } = EXPORT_CONTRACT_AWARD_METHOD;

const CONTENT_STRINGS = EXPORT_CONTRACT_FIELDS.HOW_WAS_THE_CONTRACT_AWARDED;

const {
HOW_WAS_THE_CONTRACT_AWARDED: { AWARD_METHOD, OTHER_AWARD_METHOD },
} = FIELD_IDS;

/**
* mapHowWasTheContractAwarded
* Map an application's export contract - AWARD_METHOD answers into an object for XLSX generation
* @param {ApplicationExportContract} application: Application export contract
* @returns {Object} xlsxRow
*/
const mapHowWasTheContractAwarded = (exportContract: ApplicationExportContract) => {
const submittedMethodId = exportContract.awardMethodId;

let answer;

if (submittedMethodId === OTHER.DB_ID) {
answer = exportContract[OTHER_AWARD_METHOD];
} else {
const allMethods = Object.values(EXPORT_CONTRACT_AWARD_METHOD);

const method = allMethods.find((methodObj) => methodObj.DB_ID === submittedMethodId);

if (method) {
answer = method.VALUE;
}
}

const title = `${String(CONTENT_STRINGS[AWARD_METHOD].SUMMARY?.TITLE)}?`;

return xlsxRow(title, answer);
};

export default mapHowWasTheContractAwarded;
2 changes: 2 additions & 0 deletions src/api/test-mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {

const now = new Date();

export const invalidId = 'invalid-id';

export const mockAccount = {
firstName: 'first',
lastName: 'last',
Expand Down
1 change: 1 addition & 0 deletions src/api/types/application-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export interface ApplicationPrivateMarket extends Relationship {

export interface ApplicationExportContract extends Relationship {
agent: ApplicationExportContractAgent;
awardMethodId: string;
id: string;
finalDestinationKnown?: boolean;
finalDestinationCountryCode?: string;
Expand Down

0 comments on commit 1f4335e

Please sign in to comment.