diff --git a/resources-domain/lambdas/s3-importer/src/uschMappings.ts b/resources-domain/lambdas/s3-importer/src/uschMappings.ts index bd34e35c4..9be54f1b5 100644 --- a/resources-domain/lambdas/s3-importer/src/uschMappings.ts +++ b/resources-domain/lambdas/s3-importer/src/uschMappings.ts @@ -163,12 +163,14 @@ export type UschCsvResource = { Coverage: string; Comment: string; HoursFormatted: string; + Inactive: string; }; export type UschExpandedResource = Partial< - Omit & { + Omit & { Categories: string[]; Coverage: string[]; + Inactive: boolean; } >; @@ -202,6 +204,7 @@ export const expandCsvLine = (csv: UschCsvResource): UschExpandedResource => { ...csv, Categories: csv.Categories?.split(';').filter(Boolean), Coverage: csv.Coverage?.split(';').filter(Boolean), + Inactive: Boolean(csv.Inactive && csv.Inactive.toLowerCase() === 'true'), }; for (const key in expanded) { const validKey = key as keyof UschExpandedResource; @@ -215,6 +218,9 @@ export const expandCsvLine = (csv: UschCsvResource): UschExpandedResource => { export const USCH_MAPPING_NODE: MappingNode = { ResourceID: resourceFieldMapping('id'), Name: resourceFieldMapping('name'), + Inactive: resourceFieldMapping('deletedAt', context => + context.currentValue ? new Date().toISOString() : '', + ), AlternateName: translatableAttributeMapping('alternateName', { language: 'en' }), Address: attributeMapping('stringAttributes', 'address/street'), City: attributeMapping('stringAttributes', 'address/city', { diff --git a/resources-domain/lambdas/s3-importer/tests/fixtures/sampleResources.ts b/resources-domain/lambdas/s3-importer/tests/fixtures/sampleResources.ts index 5cdfd781b..7d8473025 100644 --- a/resources-domain/lambdas/s3-importer/tests/fixtures/sampleResources.ts +++ b/resources-domain/lambdas/s3-importer/tests/fixtures/sampleResources.ts @@ -65,4 +65,5 @@ export const EMPTY_CSV_LINE: UschCsvResource = { StateProvince: '', UpdatedOn: '', WebsiteAddress: '', + Inactive: '', }; diff --git a/resources-domain/lambdas/s3-importer/tests/unit/uschMappings.test.ts b/resources-domain/lambdas/s3-importer/tests/unit/uschMappings.test.ts index 8557bf9fc..f3825bb2e 100644 --- a/resources-domain/lambdas/s3-importer/tests/unit/uschMappings.test.ts +++ b/resources-domain/lambdas/s3-importer/tests/unit/uschMappings.test.ts @@ -33,6 +33,7 @@ describe('expandCsvLine', () => { ResourceID: TEST_RESOURCE_ID, Coverage: [], Categories: [], + Inactive: false, }); }); test('Csv line with single category - outputs expanded resource with single item category array', async () => { @@ -45,6 +46,7 @@ describe('expandCsvLine', () => { ResourceID: TEST_RESOURCE_ID, Coverage: [], Categories: ['One category'], + Inactive: false, }); }); test('Csv line with multiple categories seperated by semi-colons - outputs expanded resource with category array without trimming', async () => { @@ -57,6 +59,7 @@ describe('expandCsvLine', () => { ResourceID: TEST_RESOURCE_ID, Coverage: [], Categories: ['A ', 'few', ' categories'], + Inactive: false, }); }); test('Csv line with single coverage item - outputs expanded resource with single item coverage array', async () => { @@ -69,6 +72,7 @@ describe('expandCsvLine', () => { ResourceID: TEST_RESOURCE_ID, Coverage: ['One coverage'], Categories: [], + Inactive: false, }); }); test('Csv line with multiple coverage seperated by semi-colons - outputs expanded resource with coverage array without trimming', async () => { @@ -81,8 +85,43 @@ describe('expandCsvLine', () => { ResourceID: TEST_RESOURCE_ID, Coverage: ['A ', 'few', ' coverages'], Categories: [], + Inactive: false, }); }); + test('Csv line with Inactive set false, sets Inactive as false', async () => { + const result: UschExpandedResource = expandCsvLine({ + ...EMPTY_CSV_LINE, + ResourceID: TEST_RESOURCE_ID, + Inactive: 'false', + }); + expect(result).toStrictEqual({ + ResourceID: TEST_RESOURCE_ID, + Coverage: [], + Categories: [], + Inactive: false, + }); + }); + each([ + { inactiveCsvValue: 'true' }, + { inactiveCsvValue: 'TRUE' }, + { inactiveCsvValue: 'True' }, + { inactiveCsvValue: 'tRuE' }, + ]).test( + "Csv line with Inactive set '$inactiveCsvValue', sets Inactive as true", + async ({ inactiveCsvValue }) => { + const result: UschExpandedResource = expandCsvLine({ + ...EMPTY_CSV_LINE, + ResourceID: TEST_RESOURCE_ID, + Inactive: inactiveCsvValue, + }); + expect(result).toStrictEqual({ + ResourceID: TEST_RESOURCE_ID, + Coverage: [], + Categories: [], + Inactive: true, + }); + }, + ); }); /** @@ -154,6 +193,14 @@ describe('Mapping valid sample resources should produce no warnings', () => { Coverage: ['COVERAGE 1', 'COVERAGE 2', 'COVERAGE 3'], }, }, + { + description: 'Resource with coverage and inactive flag', + resource: { + ResourceID: 'EMPTY_RESOURCE', + Coverage: ['COVERAGE 1', 'COVERAGE 2', 'COVERAGE 3'], + Inactive: true, + }, + }, ]; each(testCases).test('$description has no warnings', ({ resource }) => { diff --git a/resources-domain/resources-service/create-db.js b/resources-domain/resources-service/create-db.js index b8309aeab..cddbb1d49 100644 --- a/resources-domain/resources-service/create-db.js +++ b/resources-domain/resources-service/create-db.js @@ -65,7 +65,11 @@ async function create() { break; } catch (err) { // Catch and ECONNRESET, ECONNREFUSED or messages with 'connection' / 'connect' in. Cast a broad net! - if (err.message?.toLowerCase()?.includes('conn')) { + const errorMessage = err.message?.toLowerCase() ?? ''; + if ( + errorMessage.includes('conn') || + errorMessage.includes('the database system is starting up') + ) { console.debug( "Creation failed connecting to DB, assuming it's not ready yet & retrying...", );