Skip to content
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
8 changes: 7 additions & 1 deletion resources-domain/lambdas/s3-importer/src/uschMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ export type UschCsvResource = {
Coverage: string;
Comment: string;
HoursFormatted: string;
Inactive: string;
};

export type UschExpandedResource = Partial<
Omit<UschCsvResource, 'Categories' | 'Coverage'> & {
Omit<UschCsvResource, 'Categories' | 'Coverage' | 'Inactive'> & {
Categories: string[];
Coverage: string[];
Inactive: boolean;
}
>;

Expand Down Expand Up @@ -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;
Expand All @@ -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() : '',
),
Comment on lines +221 to +223
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why if Inactive is a boolean above, here's is a "current timestamp"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the target field is deletedAt - but USCH want a simple flag, so we set deletedAt to the current time if inactive = true, or blank it out if false

AlternateName: translatableAttributeMapping('alternateName', { language: 'en' }),
Address: attributeMapping('stringAttributes', 'address/street'),
City: attributeMapping('stringAttributes', 'address/city', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export const EMPTY_CSV_LINE: UschCsvResource = {
StateProvince: '',
UpdatedOn: '',
WebsiteAddress: '',
Inactive: '',
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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,
});
},
);
});

/**
Expand Down Expand Up @@ -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 }) => {
Expand Down
6 changes: 5 additions & 1 deletion resources-domain/resources-service/create-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
);
Expand Down
Loading