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

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

Merged
merged 5 commits into from
Aug 6, 2024
Merged
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
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
Zainzzkk marked this conversation as resolved.
Show resolved Hide resolved
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
Loading