-
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-4015): application submission - xlsx - uk broker address (#3468
) * feat(EMS-4015): add isEmptyString helper to api * feat(EMS-4015): application submission - xlsx - uk broker address * feat(EMS-4015): improve unit test coverage
- Loading branch information
Showing
12 changed files
with
402 additions
and
86 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
107 changes: 107 additions & 0 deletions
107
...pplication-to-XLSX/map-policy/map-broker/map-broker-address/based-in-the-uk/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,107 @@ | ||
import mapBrokerAddressBasedInTheUk from '.'; | ||
import { POLICY as FIELD_IDS } from '../../../../../../constants/field-ids/insurance/policy'; | ||
import { ApplicationBroker } from '../../../../../../types'; | ||
import { mockApplication } from '../../../../../../test-mocks'; | ||
|
||
const { | ||
BROKER_DETAILS: { BUILDING_NUMBER_OR_NAME, ADDRESS_LINE_1, ADDRESS_LINE_2, TOWN, COUNTY, POSTCODE }, | ||
} = FIELD_IDS; | ||
|
||
const { broker } = mockApplication; | ||
|
||
const { buildingNumberOrName, addressLine1, addressLine2, town, county, postcode } = broker; | ||
|
||
describe('api/generate-xlsx/map-application-to-xlsx/map-policy/map-broker/map-broker-address/based-in-the-uk', () => { | ||
describe(`when a broker only has ${BUILDING_NUMBER_OR_NAME}, ${ADDRESS_LINE_1} and ${POSTCODE} generic fields`, () => { | ||
it('should return a single string containing only said fields', () => { | ||
const mockBroker: ApplicationBroker = { | ||
...broker, | ||
[ADDRESS_LINE_2]: '', | ||
[TOWN]: '', | ||
[COUNTY]: '', | ||
}; | ||
|
||
const result = mapBrokerAddressBasedInTheUk(mockBroker); | ||
|
||
const expected = `${buildingNumberOrName}\n${addressLine1}\n${postcode}`; | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe(`when a broker has generic fields and ${ADDRESS_LINE_2}`, () => { | ||
it('should return a single string containing only said fields', () => { | ||
const mockBroker: ApplicationBroker = { | ||
...broker, | ||
[TOWN]: '', | ||
[COUNTY]: '', | ||
}; | ||
|
||
const result = mapBrokerAddressBasedInTheUk(mockBroker); | ||
|
||
const expected = `${buildingNumberOrName}\n${addressLine1}\n${addressLine2}\n${postcode}`; | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe(`when a broker has generic fields and ${TOWN}`, () => { | ||
it('should return a single string containing only said fields', () => { | ||
const mockBroker: ApplicationBroker = { | ||
...broker, | ||
[ADDRESS_LINE_2]: '', | ||
[COUNTY]: '', | ||
}; | ||
|
||
const result = mapBrokerAddressBasedInTheUk(mockBroker); | ||
|
||
const expected = `${buildingNumberOrName}\n${addressLine1}\n${town}\n${postcode}`; | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe(`when a broker has generic fields and ${COUNTY}`, () => { | ||
it('should return a single string containing only said fields', () => { | ||
const mockBroker: ApplicationBroker = { | ||
...broker, | ||
[ADDRESS_LINE_2]: '', | ||
[TOWN]: '', | ||
}; | ||
|
||
const result = mapBrokerAddressBasedInTheUk(mockBroker); | ||
|
||
const expected = `${buildingNumberOrName}\n${addressLine1}\n${county}\n${postcode}`; | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('when a broker has all possible fields', () => { | ||
it('should return a single string with all fields', () => { | ||
const result = mapBrokerAddressBasedInTheUk(broker); | ||
|
||
const expected = `${buildingNumberOrName}\n${addressLine1}\n${addressLine2}\n${town}\n${county}\n${postcode}`; | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('when all broker fields are empty string', () => { | ||
it('should return a single string with all fields', () => { | ||
const mockBroker: ApplicationBroker = { | ||
...broker, | ||
[BUILDING_NUMBER_OR_NAME]: '', | ||
[ADDRESS_LINE_1]: '', | ||
[ADDRESS_LINE_2]: '', | ||
[TOWN]: '', | ||
[COUNTY]: '', | ||
[POSTCODE]: '', | ||
}; | ||
|
||
const result = mapBrokerAddressBasedInTheUk(mockBroker); | ||
|
||
expect(result).toEqual(''); | ||
}); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
...map-application-to-XLSX/map-policy/map-broker/map-broker-address/based-in-the-uk/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,41 @@ | ||
import { ApplicationBroker } from '../../../../../../types'; | ||
|
||
/** | ||
* mapBrokerAddressBasedInTheUk | ||
* Map an application's broker "based in the UK" address fields into a string for an XLSX object/column | ||
* A broker's UK address is saved in multiple fields. | ||
* The XLSX requires this data to be rendered in a single string field/column. | ||
* @param {ApplicationBroker} broker | ||
* @returns {String} Broker UK address string | ||
*/ | ||
const mapBrokerAddressBasedInTheUk = (broker: ApplicationBroker) => { | ||
const { buildingNumberOrName, addressLine1, addressLine2, town, county, postcode } = broker; | ||
|
||
let addressString = ''; | ||
|
||
if (buildingNumberOrName) { | ||
addressString += `${buildingNumberOrName}\n`; | ||
} | ||
|
||
if (addressLine1) { | ||
addressString += `${addressLine1}\n`; | ||
} | ||
|
||
if (addressLine2) { | ||
addressString += `${addressLine2}\n`; | ||
} | ||
|
||
if (town) { | ||
addressString += `${town}\n`; | ||
} | ||
|
||
if (county) { | ||
addressString += `${county}\n`; | ||
} | ||
|
||
addressString += postcode; | ||
|
||
return addressString; | ||
}; | ||
|
||
export default mapBrokerAddressBasedInTheUk; |
49 changes: 49 additions & 0 deletions
49
...erate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/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,49 @@ | ||
import mapBrokerAddress from '.'; | ||
import { POLICY as FIELD_IDS } from '../../../../../constants/field-ids/insurance/policy'; | ||
import { XLSX } from '../../../../../content-strings'; | ||
import mapBrokerAddressBasedInTheUk from './based-in-the-uk'; | ||
import xlsxRow from '../../../helpers/xlsx-row'; | ||
import { mockApplication } from '../../../../../test-mocks'; | ||
|
||
const { | ||
BROKER_DETAILS: { IS_BASED_IN_UK }, | ||
BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, | ||
} = FIELD_IDS; | ||
|
||
const { FIELDS } = XLSX; | ||
|
||
describe('api/generate-xlsx/map-application-to-xlsx/map-policy/map-broker/map-broker-address', () => { | ||
describe(`when ${IS_BASED_IN_UK} is true`, () => { | ||
const mockBroker = { | ||
...mockApplication.broker, | ||
[IS_BASED_IN_UK]: true, | ||
}; | ||
|
||
it('should return xlsxRow with the value via mapBrokerAddressBasedInTheUk', () => { | ||
const result = mapBrokerAddress(mockBroker); | ||
|
||
const expectedValue = mapBrokerAddressBasedInTheUk(mockBroker); | ||
|
||
const expected = xlsxRow(String(FIELDS[FULL_ADDRESS]), expectedValue); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe(`when ${IS_BASED_IN_UK} is false`, () => { | ||
const mockBroker = { | ||
...mockApplication.broker, | ||
[IS_BASED_IN_UK]: false, | ||
}; | ||
|
||
it(`should return xlsxRow with the value as ${FULL_ADDRESS}`, () => { | ||
const result = mapBrokerAddress(mockBroker); | ||
|
||
const expectedValue = mockBroker[FULL_ADDRESS]; | ||
|
||
const expected = xlsxRow(String(FIELDS[FULL_ADDRESS]), expectedValue); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...i/generate-xlsx/map-application-to-XLSX/map-policy/map-broker/map-broker-address/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,34 @@ | ||
import { POLICY as FIELD_IDS } from '../../../../../constants/field-ids/insurance/policy'; | ||
import { XLSX } from '../../../../../content-strings'; | ||
import mapBrokerAddressBasedInTheUk from './based-in-the-uk'; | ||
import xlsxRow from '../../../helpers/xlsx-row'; | ||
import { ApplicationBroker } from '../../../../../types'; | ||
|
||
const { | ||
BROKER_DETAILS: { IS_BASED_IN_UK }, | ||
BROKER_MANUAL_ADDRESS: { FULL_ADDRESS }, | ||
} = FIELD_IDS; | ||
|
||
const { FIELDS } = XLSX; | ||
|
||
/** | ||
* mapBrokerAddress | ||
* Map an application's broker address fields into an object for XLSX generation | ||
* - If the broker is based in the UK, consume mapBrokerAddressBasedInTheUk. | ||
* - Otherwise, simply consume the FULL_ADDRESS field. | ||
* @param {ApplicationBroker} broker | ||
* @returns {object} Object for XLSX generation | ||
*/ | ||
const mapBrokerAddress = (broker: ApplicationBroker) => { | ||
let fieldValue = ''; | ||
|
||
if (broker[IS_BASED_IN_UK]) { | ||
fieldValue = mapBrokerAddressBasedInTheUk(broker); | ||
} else { | ||
fieldValue = broker[FULL_ADDRESS]; | ||
} | ||
|
||
return xlsxRow(String(FIELDS[FULL_ADDRESS]), fieldValue); | ||
}; | ||
|
||
export default mapBrokerAddress; |
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,21 @@ | ||
import { isEmptyString } from '.'; | ||
|
||
describe('api/helpers/string', () => { | ||
describe('isEmptyString', () => { | ||
describe('when a string is empty', () => { | ||
it('should return true', () => { | ||
const result = isEmptyString(''); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when a string is not empty', () => { | ||
it('should return false', () => { | ||
const result = isEmptyString('Mock'); | ||
|
||
expect(result).toEqual(false); | ||
}); | ||
}); | ||
}); | ||
}); |
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,7 @@ | ||
/** | ||
* isEmptyString | ||
* Check if a string is empty | ||
* @param {String} | ||
* @returns {Boolean} | ||
*/ | ||
export const isEmptyString = (str: string) => str === ''; |
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