-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(EMS-3687): application submission - xlsx - how was contract awar…
…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
Showing
11 changed files
with
196 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ap-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
...lsx/map-application-to-XLSX/map-export-contract/map-how-was-the-contract-awarded/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters