Skip to content

Commit c2bda1f

Browse files
committed
CCM-11494 Update routing config factory to support conditional templates
1 parent b21525b commit c2bda1f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/test-team/helpers/factories/routing-config-factory.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
ChannelType,
66
CreateRoutingConfig,
77
RoutingConfig,
8+
Language,
9+
LetterType,
810
} from 'nhs-notify-backend-client';
911
import type {
1012
FactoryRoutingConfigWithModifiers,
@@ -74,6 +76,45 @@ export const RoutingConfigFactory = {
7476
}
7577
return this;
7678
},
79+
80+
addLanguageTemplate(language: Language, templateId?: string) {
81+
const id = templateId ?? randomUUID();
82+
for (const key of ['apiPayload', 'apiResponse', 'dbEntry'] as const) {
83+
for (const cascadeItem of this[key].cascade) {
84+
if (cascadeItem.channel === 'LETTER') {
85+
if (!cascadeItem.conditionalTemplates) {
86+
cascadeItem.conditionalTemplates = [];
87+
}
88+
cascadeItem.conditionalTemplates.push({
89+
language: language as Language,
90+
templateId: id,
91+
});
92+
}
93+
}
94+
}
95+
return this;
96+
},
97+
98+
addAccessibleFormatTemplate(
99+
accessibleFormat: LetterType,
100+
templateId?: string
101+
) {
102+
const id = templateId ?? randomUUID();
103+
for (const key of ['apiPayload', 'apiResponse', 'dbEntry'] as const) {
104+
for (const cascadeItem of this[key].cascade) {
105+
if (cascadeItem.channel === 'LETTER') {
106+
if (!cascadeItem.conditionalTemplates) {
107+
cascadeItem.conditionalTemplates = [];
108+
}
109+
cascadeItem.conditionalTemplates.push({
110+
accessibleFormat: accessibleFormat as LetterType,
111+
templateId: id,
112+
});
113+
}
114+
}
115+
}
116+
return this;
117+
},
77118
};
78119

79120
return factoryObj;

tests/test-team/helpers/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type {
22
Channel,
33
CreateRoutingConfig,
44
RoutingConfig,
5+
Language,
6+
LetterType,
57
} from 'nhs-notify-backend-client';
68

79
export const templateTypeDisplayMappings: Record<string, string> = {
@@ -101,4 +103,12 @@ export type FactoryRoutingConfigWithModifiers = FactoryRoutingConfig & {
101103
templateId?: string
102104
) => FactoryRoutingConfigWithModifiers;
103105
withTemplates: (...channels: Channel[]) => FactoryRoutingConfigWithModifiers;
106+
addLanguageTemplate: (
107+
language: Language,
108+
templateId?: string
109+
) => FactoryRoutingConfigWithModifiers;
110+
addAccessibleFormatTemplate: (
111+
accessibleFormat: LetterType,
112+
templateId?: string
113+
) => FactoryRoutingConfigWithModifiers;
104114
};

0 commit comments

Comments
 (0)