Skip to content

Commit 52ced5c

Browse files
authored
CCM-10385: retrieve client-owned templates (#581)
1 parent 4f9b220 commit 52ced5c

File tree

40 files changed

+754
-321
lines changed

40 files changed

+754
-321
lines changed

frontend/src/__tests__/app/create-letter-template/page.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe('CreateLetterTemplatePage', () => {
2222
mockGetSessionServer.mockResolvedValueOnce({
2323
accessToken: 'mocktoken',
2424
clientId: 'client1',
25-
userSub: 'sub',
2625
});
2726
mockFetchClient.mockResolvedValueOnce({
2827
data: {
@@ -40,7 +39,6 @@ describe('CreateLetterTemplatePage', () => {
4039
mockGetSessionServer.mockResolvedValueOnce({
4140
accessToken: 'mocktoken',
4241
clientId: 'client1',
43-
userSub: 'sub',
4442
});
4543
mockFetchClient.mockResolvedValueOnce({
4644
data: {
@@ -61,7 +59,6 @@ describe('CreateLetterTemplatePage', () => {
6159
mockGetSessionServer.mockResolvedValueOnce({
6260
accessToken: 'mocktoken',
6361
clientId: undefined,
64-
userSub: 'sub',
6562
});
6663
mockFetchClient.mockResolvedValueOnce({
6764
data: {
@@ -84,7 +81,6 @@ describe('CreateLetterTemplatePage', () => {
8481
mockGetSessionServer.mockResolvedValueOnce({
8582
accessToken: 'mocktoken',
8683
clientId: 'client2',
87-
userSub: 'sub',
8884
});
8985
mockFetchClient.mockResolvedValueOnce({
9086
data: {

frontend/src/__tests__/app/preview-letter-template/page.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ const redirectMock = jest.mocked(redirect);
2121
const getTemplateMock = jest.mocked(getTemplate);
2222

2323
const templateDTO = {
24-
id: 'template-id',
25-
templateType: 'LETTER',
26-
templateStatus: 'NOT_YET_SUBMITTED',
27-
name: 'template-name',
2824
createdAt: '2025-01-13T10:19:25.579Z',
29-
updatedAt: '2025-01-13T10:19:25.579Z',
30-
letterType: 'x0',
31-
language: 'en',
3225
files: {
3326
pdfTemplate: {
3427
fileName: 'template.pdf',
@@ -41,6 +34,13 @@ const templateDTO = {
4134
virusScanStatus: 'FAILED',
4235
},
4336
},
37+
id: 'template-id',
38+
language: 'en',
39+
letterType: 'x0',
40+
name: 'template-name',
41+
templateStatus: 'NOT_YET_SUBMITTED',
42+
templateType: 'LETTER',
43+
updatedAt: '2025-01-13T10:19:25.579Z',
4444
} satisfies TemplateDto;
4545

4646
const letterTemplate: LetterTemplate = {

frontend/src/__tests__/app/preview-submitted-letter-template/page.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ describe('PreviewSubmittedLetterTemplatePage', () => {
3030

3131
it('should load page', async () => {
3232
const templateDTO = {
33-
templateType: 'LETTER',
34-
id: 'template-id',
35-
templateStatus: 'SUBMITTED',
36-
name: 'template-name',
33+
createdAt: '2025-01-13T10:19:25.579Z',
3734
files: {
3835
pdfTemplate: {
3936
fileName: 'file.pdf',
4037
currentVersion: 'b',
4138
virusScanStatus: 'PASSED',
4239
},
4340
},
44-
createdAt: '2025-01-13T10:19:25.579Z',
45-
updatedAt: '2025-01-13T10:19:25.579Z',
46-
letterType: 'x0',
41+
id: 'template-id',
4742
language: 'en',
43+
letterType: 'x0',
44+
name: 'template-name',
45+
templateStatus: 'SUBMITTED',
46+
templateType: 'LETTER',
47+
updatedAt: '2025-01-13T10:19:25.579Z',
4848
} satisfies TemplateDto;
4949

5050
const submittedLetterTemplate: LetterTemplate = {

frontend/src/__tests__/components/molecules/PreviewTemplateDetails.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ describe('PreviewTemplateDetailsLetter', () => {
132132
<PreviewTemplateDetailsLetter
133133
template={{
134134
id: 'template-id',
135+
owner: 'owner',
135136
name: 'Example letter',
136137
templateStatus: 'PROOF_AVAILABLE',
137138
templateType: 'LETTER',
@@ -200,4 +201,42 @@ describe('PreviewTemplateDetailsLetter', () => {
200201

201202
expect(container.asFragment()).toMatchSnapshot();
202203
});
204+
205+
it('If the template is client-owned, the clientId is used to construct download link', () => {
206+
const { getByTestId } = render(
207+
<PreviewTemplateDetailsLetter
208+
template={{
209+
createdAt: '2025-01-13T10:19:25.579Z',
210+
files: {
211+
pdfTemplate: {
212+
fileName: 'file.pdf',
213+
currentVersion: '4C728B7D-A028-4BA2-B180-A63CDD2AE1E9',
214+
virusScanStatus: 'PASSED',
215+
},
216+
proofs: {
217+
'a.pdf': {
218+
fileName: 'a.pdf',
219+
virusScanStatus: 'PASSED',
220+
supplier: 'MBA',
221+
},
222+
},
223+
},
224+
id: 'template-id',
225+
language: 'en',
226+
letterType: 'x0',
227+
name: 'Example letter',
228+
owner: 'CLIENT#client',
229+
templateStatus: 'PROOF_AVAILABLE',
230+
templateType: 'LETTER',
231+
updatedAt: '2025-01-13T10:19:25.579Z',
232+
}}
233+
/>
234+
);
235+
236+
const link = getByTestId('proof-link_a.pdf');
237+
expect(link).toHaveAttribute(
238+
'href',
239+
'/templates/files/client/proofs/template-id/a.pdf'
240+
);
241+
});
203242
});

frontend/src/__tests__/components/molecules/ViewLetterTemplate.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('ViewLetterTemplate component', () => {
1010
{
1111
templateType: 'LETTER',
1212
id: 'template-id',
13+
owner: 'owner',
1314
name: 'Example template',
1415
templateStatus: 'SUBMITTED',
1516
createdAt: '2025-03-28T12:30:54.684Z',

frontend/src/__tests__/components/molecules/__snapshots__/PreviewTemplateDetails.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ exports[`PreviewTemplateDetailsLetter matches snapshot when proofs are present,
373373
<li>
374374
<a
375375
data-testid="proof-link_a.pdf"
376-
href="/templates/files/undefined/proofs/template-id/a.pdf"
376+
href="/templates/files/owner/proofs/template-id/a.pdf"
377377
rel="noopener noreferrer"
378378
target="_blank"
379379
>
@@ -404,7 +404,7 @@ exports[`PreviewTemplateDetailsLetter matches snapshot when proofs are present,
404404
<li>
405405
<a
406406
data-testid="proof-link_b.pdf"
407-
href="/templates/files/undefined/proofs/template-id/b.pdf"
407+
href="/templates/files/owner/proofs/template-id/b.pdf"
408408
rel="noopener noreferrer"
409409
target="_blank"
410410
>

frontend/src/__tests__/components/molecules/__snapshots__/ViewLetterTemplate.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ exports[`ViewLetterTemplate component matches submitted snapshot 1`] = `
151151
<li>
152152
<a
153153
data-testid="proof-link_supplier-proof.pdf"
154-
href="/templates/files/undefined/proofs/template-id/supplier-proof.pdf"
154+
href="/templates/files/owner/proofs/template-id/supplier-proof.pdf"
155155
rel="noopener noreferrer"
156156
target="_blank"
157157
>

frontend/src/__tests__/components/organisms/PreviewLetterTemplate.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ describe('PreviewLetterTemplate component', () => {
8686
<PreviewLetterTemplate
8787
template={{
8888
id: '2C56C5F6-B3AD-4FF8-A8A2-52E4FA8AF2BE',
89+
owner: 'owner',
8990
name: 'letter',
9091
templateType: 'LETTER',
9192
templateStatus: 'PROOF_AVAILABLE',
@@ -119,6 +120,7 @@ describe('PreviewLetterTemplate component', () => {
119120
<PreviewLetterTemplate
120121
template={{
121122
id: '0A097DCD-35F9-4DAD-A37E-AC358B71B74D',
123+
owner: 'owner',
122124
name: 'letter',
123125
templateType: 'LETTER',
124126
templateStatus: 'NOT_YET_SUBMITTED',

frontend/src/__tests__/components/organisms/__snapshots__/PreviewLetterTemplate.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ exports[`PreviewLetterTemplate component matches snapshot when template status i
753753
<li>
754754
<a
755755
data-testid="proof-link_your-proof.pdf"
756-
href="/templates/files/undefined/proofs/2C56C5F6-B3AD-4FF8-A8A2-52E4FA8AF2BE/your-proof.pdf"
756+
href="/templates/files/owner/proofs/2C56C5F6-B3AD-4FF8-A8A2-52E4FA8AF2BE/your-proof.pdf"
757757
rel="noopener noreferrer"
758758
target="_blank"
759759
>

frontend/src/__tests__/middleware.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ describe('middleware function', () => {
3636
getTokenMock.mockResolvedValueOnce({
3737
accessToken: undefined,
3838
clientId: undefined,
39-
userSub: undefined,
4039
});
4140

4241
const response = await middleware(request);
@@ -55,7 +54,6 @@ describe('middleware function', () => {
5554
getTokenMock.mockResolvedValueOnce({
5655
accessToken: 'token',
5756
clientId: 'client1',
58-
userSub: 'sub',
5957
});
6058

6159
const url = new URL('https://url.com/message-templates');

0 commit comments

Comments
 (0)