-
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.
fix(EMS-3524): no pdf - data migration - eligibility section review c…
…ondition (#2677) * fix(EMS-3524): no pdf - data migration - migratedV1toV2 flag * fix(EMS-3524): no pdf - data migration - eligibility sectionReview condition
- Loading branch information
Showing
21 changed files
with
123 additions
and
13 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
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
18 changes: 18 additions & 0 deletions
18
...ta-migration/version-1-to-version-2/update-applications/add-application-migrated-field.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,18 @@ | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from '../execute-sql-query'; | ||
|
||
/** | ||
* addApplicationMigratedField | ||
* Add a migratedV1toV2 field to the application table. | ||
* @param {Connection} connection: SQL database connection | ||
* @returns {Promise<Array<object>>} executeSqlQuery response | ||
*/ | ||
const addApplicationMigratedField = (connection: Connection) => { | ||
const loggingMessage = 'Adding FIELD migratedV1toV2 to application table'; | ||
|
||
const query = `ALTER TABLE Application ADD migratedV1toV2 tinyint(1) DEFAULT NULL`; | ||
|
||
return executeSqlQuery({ connection, query, loggingMessage }); | ||
}; | ||
|
||
export default addApplicationMigratedField; |
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
23 changes: 23 additions & 0 deletions
23
.../data-migration/version-1-to-version-2/update-applications/update-application-migrated.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,23 @@ | ||
import { Connection } from 'mysql2/promise'; | ||
import { APPLICATION } from '../../../constants'; | ||
import executeSqlQuery from '../execute-sql-query'; | ||
|
||
const { STATUS } = APPLICATION; | ||
|
||
/** | ||
* updateApplicationMigrated | ||
* Update IN_PROGRESS applications migratedV1toV2 fields to have a value of 1/true | ||
* @param {Connection} connection: SQL database connection | ||
* @returns {Promise<Array<object>>} executeSqlQuery response | ||
*/ | ||
const updateApplicationMigrated = (connection: Connection) => { | ||
const loggingMessage = `Updating migratedV1toV2 FIELD to true in the application table`; | ||
|
||
const query = ` | ||
UPDATE Application SET migratedV1toV2 = 1 WHERE status = '${STATUS.IN_PROGRESS}' | ||
`; | ||
|
||
return executeSqlQuery({ connection, query, loggingMessage }); | ||
}; | ||
|
||
export default updateApplicationMigrated; |
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
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
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
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
39 changes: 35 additions & 4 deletions
39
src/ui/server/helpers/required-fields/section-review/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 |
---|---|---|
@@ -1,10 +1,41 @@ | ||
import requiredFields from '.'; | ||
import FIELD_IDS from '../../../constants/field-ids/insurance/check-your-answers'; | ||
import FIELD_IDS from '../../../constants/field-ids/insurance'; | ||
import flattenApplicationData from '../../flatten-application-data'; | ||
import { mockApplication } from '../../../test-mocks'; | ||
|
||
const { | ||
MIGRATED_FROM_V1_TO_V2, | ||
CHECK_YOUR_ANSWERS: { ELIGIBILITY, EXPORTER_BUSINESS, BUYER, POLICY, EXPORT_CONTRACT }, | ||
} = FIELD_IDS; | ||
|
||
describe('server/helpers/required-fields/section-review', () => { | ||
it('should return array of required fields', () => { | ||
const expected = Object.values(FIELD_IDS); | ||
describe(`when application.${MIGRATED_FROM_V1_TO_V2} is true`, () => { | ||
it(`should return array of required fields, without ${ELIGIBILITY}`, () => { | ||
const application = flattenApplicationData({ | ||
...mockApplication, | ||
[MIGRATED_FROM_V1_TO_V2]: true, | ||
}); | ||
|
||
const result = requiredFields(application); | ||
|
||
const expected = [EXPORTER_BUSINESS, BUYER, POLICY, EXPORT_CONTRACT]; | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe(`when application.${MIGRATED_FROM_V1_TO_V2} is false`, () => { | ||
it(`should return array of required fields, with ${ELIGIBILITY}`, () => { | ||
const application = flattenApplicationData({ | ||
...mockApplication, | ||
[MIGRATED_FROM_V1_TO_V2]: false, | ||
}); | ||
|
||
const result = requiredFields(application); | ||
|
||
const expected = [ELIGIBILITY, EXPORTER_BUSINESS, BUYER, POLICY, EXPORT_CONTRACT]; | ||
|
||
expect(requiredFields).toEqual(expected); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
}); |
18 changes: 16 additions & 2 deletions
18
src/ui/server/helpers/required-fields/section-review/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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
import FIELD_IDS from '../../../constants/field-ids/insurance/check-your-answers'; | ||
import { ApplicationFlat } from '../../../../types'; | ||
|
||
const { ELIGIBILITY, EXPORTER_BUSINESS, BUYER, POLICY, EXPORT_CONTRACT } = FIELD_IDS; | ||
|
||
/** | ||
* requiredFields | ||
* Required fields for the insurance - check your answers section | ||
* Required fields for the insurance - check your answers section. | ||
* If an application has been migrated from V1 to V2, ELIGIBILITY is NOT required. | ||
* Otherwise, ELIGIBILITY is required. | ||
* This is because: | ||
* - In V1, there is no ability to check the ELIGIBILITY answers. | ||
* - In V2, there is the ability to check the ELIGIBILITY answers. | ||
* @returns {Array<string>} Required field IDs | ||
*/ | ||
const requiredFields = Object.values(FIELD_IDS); | ||
const requiredFields = (application: ApplicationFlat) => { | ||
if (application.migratedV1toV2) { | ||
return [EXPORTER_BUSINESS, BUYER, POLICY, EXPORT_CONTRACT]; | ||
} | ||
|
||
return [ELIGIBILITY, EXPORTER_BUSINESS, BUYER, POLICY, EXPORT_CONTRACT]; | ||
}; | ||
|
||
export default requiredFields; |
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