Skip to content
Open
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
73 changes: 0 additions & 73 deletions frontend/src/__tests__/utils/routing-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,6 @@ describe('getSelectedLanguageTemplateIds', () => {
]);
});

it('should filter out language templates with null templateId', () => {
const cascadeItem: CascadeItem = {
cascadeGroups: ['translations'],
channel: 'LETTER',
channelType: 'primary',
defaultTemplateId: 'default-template',
conditionalTemplates: [
{ templateId: 'template-1', language: 'fr' },
{ templateId: null, language: 'pl' },
{ templateId: 'template-3', language: 'es' },
],
};

const result = getSelectedLanguageTemplateIds(cascadeItem);

expect(result).toEqual([
{ language: 'fr', templateId: 'template-1' },
{ language: 'es', templateId: 'template-3' },
]);
});

it('should return empty array when no conditional templates exist', () => {
const cascadeItem: CascadeItem = {
cascadeGroups: ['standard'],
Expand Down Expand Up @@ -287,20 +266,6 @@ describe('removeTemplatesFromConditionalTemplates', () => {
expect(result).toEqual([{ templateId: 'template-2', language: 'es' }]);
});

it('should keep templates with null templateId', () => {
const conditionalTemplates: ConditionalTemplate[] = [
{ templateId: 'template-1', language: 'fr' },
{ templateId: null, language: 'es' },
];

const result = removeTemplatesFromConditionalTemplates(
conditionalTemplates,
['template-1']
);

expect(result).toEqual([{ templateId: null, language: 'es' }]);
});

it('should return empty array when all templates are removed', () => {
const conditionalTemplates: ConditionalTemplate[] = [
{ templateId: 'template-1', language: 'fr' },
Expand Down Expand Up @@ -512,26 +477,6 @@ describe('getConditionalTemplatesForItem', () => {
});
});

it('should filter out templates with a missing/invalid templateId', () => {
const cascadeItem: CascadeItem = {
cascadeGroups: ['standard', 'translations'],
channel: 'LETTER',
channelType: 'primary',
defaultTemplateId: 'template-1',
conditionalTemplates: [
{ templateId: 'template-2', language: 'fr' },
{ templateId: null, language: 'es' },
{ accessibleFormat: 'x1' } as ConditionalTemplate,
],
};

const result = getConditionalTemplatesForItem(cascadeItem, templates);

expect(result).toEqual({
'template-2': templates['template-2'],
});
});

it('should not include templates that are missing from templates object', () => {
const cascadeItem: CascadeItem = {
cascadeGroups: ['standard', 'translations'],
Expand Down Expand Up @@ -635,24 +580,6 @@ describe('buildCascadeGroupsForItem', () => {
]);
});

it('should return only standard group when conditional templates have missing templateIds', () => {
const cascadeItem: CascadeItem = {
cascadeGroups: ['standard'],
channel: 'LETTER',
channelType: 'primary',
defaultTemplateId: 'template-1',
conditionalTemplates: [
{ templateId: null, accessibleFormat: 'q4' },
{ templateId: 'template-2', language: 'fr' },
],
};

expect(buildCascadeGroupsForItem(cascadeItem)).toEqual([
'standard',
'translations',
]);
});

it('should return only standard when conditional templates array is empty', () => {
const cascadeItem: CascadeItem = {
cascadeGroups: ['standard'],
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/utils/routing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getConditionalTemplatesForItem(

return Object.fromEntries(
conditionalTemplateIds
.filter((id): id is string => id != null && id in templates)
.filter((id) => id in templates)
.map((id) => [id, templates[id]])
);
}
Expand Down Expand Up @@ -90,10 +90,8 @@ export function getSelectedLanguageTemplateIds(

return cascadeItem.conditionalTemplates
.filter(
(
template
): template is ConditionalTemplateLanguage & { templateId: string } =>
'language' in template && template.templateId !== null
(template): template is ConditionalTemplateLanguage =>
'language' in template
)
.map(({ language, templateId }) => ({
language,
Expand Down Expand Up @@ -137,10 +135,10 @@ export function buildCascadeGroupsForItem(
cascadeItem.conditionalTemplates.length > 0
) {
const hasAccessibleFormat = cascadeItem.conditionalTemplates.some(
(template) => 'accessibleFormat' in template && template.templateId
(template) => 'accessibleFormat' in template
);
const hasLanguage = cascadeItem.conditionalTemplates.some(
(template) => 'language' in template && template.templateId
(template) => 'language' in template
);

if (hasAccessibleFormat) {
Expand Down Expand Up @@ -190,7 +188,6 @@ export function removeTemplatesFromCascadeItem(

return updatedCascadeItem;
}

/**
* Add default template to cascade at specific index
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ data "aws_iam_policy_document" "submit_routing_config_lambda_policy" {
effect = "Allow"

actions = [
"dynamodb:GetItem",
"dynamodb:UpdateItem",
]

Expand All @@ -49,6 +50,21 @@ data "aws_iam_policy_document" "submit_routing_config_lambda_policy" {
]
}

statement {
sid = "AllowConditionCheckDynamoAccess"
effect = "Allow"

actions = [
"dynamodb:BatchGetItem",
"dynamodb:UpdateItem",
"dynamodb:ConditionCheckItem",
]

resources = [
aws_dynamodb_table.templates.arn,
]
}

statement {
sid = "AllowKMSAccess"
effect = "Allow"
Expand Down
2 changes: 0 additions & 2 deletions infrastructure/terraform/modules/backend-api/spec.tmpl.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@
},
"templateId": {
"format": "uuid",
"nullable": true,
"type": "string"
}
},
Expand All @@ -409,7 +408,6 @@
},
"templateId": {
"format": "uuid",
"nullable": true,
"type": "string"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('Delete Routing Config Handler', () => {
errorMeta: {
code: 409,
description:
'Lock number mismatch - Message Plan has been modified since last read',
'Lock number mismatch - Routing configuration has been modified since last read',
},
},
});
Expand All @@ -192,7 +192,7 @@ describe('Delete Routing Config Handler', () => {
body: JSON.stringify({
statusCode: 409,
technicalMessage:
'Lock number mismatch - Message Plan has been modified since last read',
'Lock number mismatch - Routing configuration has been modified since last read',
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('Submit Routing Config Handler', () => {
errorMeta: {
code: 409,
description:
'Lock number mismatch - Message Plan has been modified since last read',
'Lock number mismatch - Routing configuration has been modified since last read',
},
},
});
Expand All @@ -196,7 +196,7 @@ describe('Submit Routing Config Handler', () => {
body: JSON.stringify({
statusCode: 409,
technicalMessage:
'Lock number mismatch - Message Plan has been modified since last read',
'Lock number mismatch - Routing configuration has been modified since last read',
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('Update Routing Config Handler', () => {
errorMeta: {
code: 409,
description:
'Lock number mismatch - Message Plan has been modified since last read',
'Lock number mismatch - Routing configuration has been modified since last read',
},
},
});
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('Update Routing Config Handler', () => {
body: JSON.stringify({
statusCode: 409,
technicalMessage:
'Lock number mismatch - Message Plan has been modified since last read',
'Lock number mismatch - Routing configuration has been modified since last read',
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ describe('RoutingConfigClient', () => {

expect(result).toEqual({
error: {
errorMeta: { code: 404, description: 'Routing Config not found' },
errorMeta: {
code: 404,
description: 'Routing configuration not found',
},
},
});

Expand Down Expand Up @@ -516,6 +519,7 @@ describe('RoutingConfigClient', () => {

const completed: RoutingConfig = {
...routingConfig,
id,
status: 'COMPLETED',
};

Expand All @@ -536,6 +540,36 @@ describe('RoutingConfigClient', () => {
});
});

test('returns failures from repository', async () => {
const { client, mocks } = setup();

mocks.clientConfigRepository.get.mockResolvedValueOnce({
data: { features: { routing: true } },
});

mocks.routingConfigRepository.submit.mockResolvedValueOnce({
error: {
errorMeta: {
code: 400,
description:
'All cascade items must have either a defaultTemplateId or conditionalTemplates',
},
},
});

const result = await client.submitRoutingConfig('some-id', user, '42');

expect(result).toEqual({
error: {
errorMeta: {
code: 400,
description:
'All cascade items must have either a defaultTemplateId or conditionalTemplates',
},
},
});
});

test('returns failures from client config repository', async () => {
const { client, mocks } = setup();

Expand Down
Loading