Skip to content

Commit

Permalink
feat(EMS-3687): application submission - xlsx - how was contract awar…
Browse files Browse the repository at this point in the history
…ded (#2907)

* feat(EMS-3687): application submission - xlsx - how was contract awarded

* feat(EMS-3687): add missing content string

* chore(e2e): fix typo
  • Loading branch information
ttbarnes authored Aug 6, 2024
1 parent 1805850 commit 40ea2f4
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 5 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

## [2.34.0](https://github.com/UK-Export-Finance/exip/compare/v2.33.0...v2.34.0) (2024-08-06)


### Features

* **EMS-3722-3723:** data migration - eligibility, export contract ([#2901](https://github.com/UK-Export-Finance/exip/issues/2901)) ([0c16bc1](https://github.com/UK-Export-Finance/exip/commit/0c16bc18b52bf1a6a0737a124d693203a8eba96a))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ context(
beforeEach(() => {
cy.navigateToUrl(url);

// select DIRECT_AWARD
// change to DIRECT_AWARD
summaryList.field(FIELD_ID).changeLink().click();
cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ context(
beforeEach(() => {
cy.navigateToUrl(checkYourAnswersUrl);

// select DIRECT_AWARD
// change to DIRECT_AWARD
summaryList.field(FIELD_ID).changeLink().click();
cy.completeAndSubmitHowWasTheContractAwardedForm({ directAward: true });

Expand Down
31 changes: 29 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 @@ -41,6 +41,9 @@ export const EXPORT_CONTRACT_FIELDS = {
TEXT: OTHER.VALUE,
},
},
SUMMARY: {
TITLE: 'How was the contract awarded',
},
},
},
ABOUT_GOODS_OR_SERVICES: {
Expand Down
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 40ea2f4

Please sign in to comment.