Skip to content

Commit e64c3c1

Browse files
committed
updating api tests
1 parent c1f8eb4 commit e64c3c1

File tree

19 files changed

+179
-92
lines changed

19 files changed

+179
-92
lines changed

data-migration/user-transfer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# User Transfer Data Migration
1+
# UserWithOptionalClient Transfer Data Migration
22

33
The purpose of this tool is to transfer templates stored in DynamoDB from one owner to another. It does not transfer ownership of any files in S3, this would need to be done separately.
44

infrastructure/terraform/modules/backend-api/spec.tmpl.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
},
99
{
1010
"properties": {
11+
"campaignId": {
12+
"type": "string"
13+
},
1114
"clientId": {
1215
"type": "string"
1316
},

lambdas/backend-api/src/__tests__/templates/app/template-client.test.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ describe('templateClient', () => {
145145

146146
const expectedTemplateDto: TemplateDto = {
147147
...data,
148-
id: templateId,
148+
campaignId: 'campaignId',
149149
createdAt: new Date().toISOString(),
150-
updatedAt: new Date().toISOString(),
150+
id: templateId,
151151
templateStatus: 'NOT_YET_SUBMITTED',
152+
updatedAt: new Date().toISOString(),
152153
};
153154

154155
const template: DatabaseTemplate = {
155156
...expectedTemplateDto,
156157
owner: user.userId,
157-
campaignId: 'campaignId',
158158
version: 1,
159159
};
160160

@@ -267,24 +267,24 @@ describe('templateClient', () => {
267267
const { templateClient, mocks } = setup();
268268

269269
const data: CreateUpdateTemplate = {
270-
templateType: 'EMAIL',
271-
name: 'name',
272270
message: 'message',
271+
name: 'name',
273272
subject: 'subject',
273+
templateType: 'EMAIL',
274274
};
275275

276276
const expectedTemplateDto: TemplateDto = {
277277
...data,
278-
id: templateId,
278+
campaignId: 'campaignId',
279279
createdAt: new Date().toISOString(),
280-
updatedAt: new Date().toISOString(),
280+
id: templateId,
281281
templateStatus: 'NOT_YET_SUBMITTED',
282+
updatedAt: new Date().toISOString(),
282283
};
283284

284285
const template: DatabaseTemplate = {
285286
...expectedTemplateDto,
286287
owner: user.userId,
287-
campaignId: 'campaignId',
288288
version: 1,
289289
};
290290

@@ -1539,7 +1539,7 @@ describe('templateClient', () => {
15391539
expect(result).toEqual({
15401540
error: {
15411541
code: 403,
1542-
message: 'User cannot request a proof',
1542+
message: 'UserWithOptionalClient cannot request a proof',
15431543
},
15441544
});
15451545
});
@@ -1595,7 +1595,7 @@ describe('templateClient', () => {
15951595

15961596
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
15971597
templateId,
1598-
user.userId
1598+
user
15991599
);
16001600

16011601
expect(result).toEqual({
@@ -1654,7 +1654,7 @@ describe('templateClient', () => {
16541654

16551655
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
16561656
templateId,
1657-
user.userId
1657+
user
16581658
);
16591659

16601660
expect(result).toEqual({
@@ -1703,7 +1703,7 @@ describe('templateClient', () => {
17031703

17041704
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
17051705
templateId,
1706-
user.userId
1706+
user
17071707
);
17081708

17091709
expect(result).toEqual({
@@ -1721,22 +1721,23 @@ describe('templateClient', () => {
17211721
const personalisationParameters = ['myParam'];
17221722

17231723
const template: TemplateDto = {
1724-
name: templateName,
1725-
templateStatus: 'SUBMITTED',
1726-
templateType: 'LETTER',
1727-
id: templateId,
1724+
campaignId: 'campaign-id-from-template',
17281725
createdAt: new Date().toISOString(),
1729-
updatedAt: new Date().toISOString(),
1730-
personalisationParameters,
1731-
letterType: 'x1',
1732-
language: 'en',
17331726
files: {
17341727
pdfTemplate: {
17351728
virusScanStatus: 'PASSED',
17361729
currentVersion: pdfVersionId,
17371730
fileName: 'template.pdf',
17381731
},
17391732
},
1733+
id: templateId,
1734+
language: 'en',
1735+
letterType: 'x1',
1736+
name: templateName,
1737+
personalisationParameters,
1738+
templateStatus: 'SUBMITTED',
1739+
templateType: 'LETTER',
1740+
updatedAt: new Date().toISOString(),
17401741
};
17411742

17421743
mocks.templateRepository.proofRequestUpdate.mockResolvedValueOnce({
@@ -1755,26 +1756,27 @@ describe('templateClient', () => {
17551756

17561757
mocks.clientConfigRepository.get.mockResolvedValueOnce({
17571758
data: {
1758-
campaignId: 'campaignId',
1759+
campaignId: 'campaign-id-from-ssm',
17591760
features: {
17601761
proofing: true,
17611762
},
17621763
},
17631764
});
17641765

17651766
const result = await templateClient.requestProof(templateId, user);
1767+
console.log(result);
17661768

17671769
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
17681770
templateId,
1769-
user.userId
1771+
user
17701772
);
17711773

17721774
expect(mocks.queueMock.send).toHaveBeenCalledTimes(1);
17731775
expect(mocks.queueMock.send).toHaveBeenCalledWith(
17741776
templateId,
17751777
templateName,
17761778
user,
1777-
'campaignId',
1779+
'campaign-id-from-template',
17781780
personalisationParameters,
17791781
'x1',
17801782
'en',
@@ -1811,7 +1813,7 @@ describe('templateClient', () => {
18111813
expect(result).toEqual({
18121814
error: {
18131815
code: 403,
1814-
message: 'User cannot request a proof',
1816+
message: 'UserWithOptionalClient cannot request a proof',
18151817
},
18161818
});
18171819
});
@@ -1821,29 +1823,31 @@ describe('templateClient', () => {
18211823

18221824
const pdfVersionId = 'a';
18231825
const personalisationParameters = ['myParam'];
1826+
const campaignFromTemplate = 'campaign-from-template';
18241827

18251828
const template: TemplateDto = {
1826-
name: templateName,
1827-
templateStatus: 'SUBMITTED',
1828-
templateType: 'LETTER',
1829-
id: templateId,
1829+
campaignId: campaignFromTemplate,
18301830
createdAt: new Date().toISOString(),
1831-
updatedAt: new Date().toISOString(),
1832-
personalisationParameters,
1833-
letterType: 'x1',
1834-
language: 'en',
18351831
files: {
18361832
pdfTemplate: {
18371833
virusScanStatus: 'PASSED',
18381834
currentVersion: pdfVersionId,
18391835
fileName: 'template.pdf',
18401836
},
18411837
},
1838+
id: templateId,
1839+
language: 'en',
1840+
letterType: 'x1',
1841+
name: templateName,
1842+
personalisationParameters,
1843+
templateStatus: 'SUBMITTED',
1844+
templateType: 'LETTER',
1845+
updatedAt: new Date().toISOString(),
18421846
};
18431847

18441848
mocks.clientConfigRepository.get.mockResolvedValueOnce({
18451849
data: {
1846-
campaignId: 'campaignId',
1850+
campaignId: 'campaign-from-ssm',
18471851
features: {
18481852
proofing: true,
18491853
},
@@ -1860,15 +1864,15 @@ describe('templateClient', () => {
18601864

18611865
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
18621866
templateId,
1863-
user.userId
1867+
user
18641868
);
18651869

18661870
expect(mocks.queueMock.send).toHaveBeenCalledTimes(1);
18671871
expect(mocks.queueMock.send).toHaveBeenCalledWith(
18681872
templateId,
18691873
templateName,
18701874
user,
1871-
'campaignId',
1875+
campaignFromTemplate,
18721876
personalisationParameters,
18731877
'x1',
18741878
'en',

lambdas/backend-api/src/__tests__/templates/infra/template-repository.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,28 +1490,30 @@ describe('templateRepository', () => {
14901490
});
14911491

14921492
const result = await templateRepository.proofRequestUpdate(
1493-
'template-owner',
1494-
'template-id'
1493+
'template-id',
1494+
{ userId: 'template-owner', clientId: 'client' }
14951495
);
14961496

14971497
expect(result).toEqual({ data: { id: 'template-id' } });
14981498

14991499
expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
15001500
ConditionExpression:
1501-
'#templateStatus = :condition_1_templateStatus AND #templateType = :condition_2_templateType AND attribute_exists (#id)',
1501+
'#templateStatus = :condition_1_templateStatus AND #templateType = :condition_2_templateType AND #clientId = :condition_3_clientId AND attribute_exists (#id)',
15021502
ExpressionAttributeNames: {
15031503
'#id': 'id',
1504+
'#clientId': 'clientId',
15041505
'#templateStatus': 'templateStatus',
15051506
'#templateType': 'templateType',
15061507
'#updatedAt': 'updatedAt',
15071508
},
15081509
ExpressionAttributeValues: {
15091510
':condition_1_templateStatus': 'PENDING_PROOF_REQUEST',
15101511
':condition_2_templateType': 'LETTER',
1512+
':condition_3_clientId': 'client',
15111513
':templateStatus': 'WAITING_FOR_PROOF',
15121514
':updatedAt': '2024-12-27T00:00:00.000Z',
15131515
},
1514-
Key: { id: 'template-owner', owner: 'template-id' },
1516+
Key: { id: 'template-id', owner: 'template-owner' },
15151517
ReturnValues: 'ALL_NEW',
15161518
ReturnValuesOnConditionCheckFailure: 'ALL_OLD',
15171519
TableName: 'templates',
@@ -1531,8 +1533,8 @@ describe('templateRepository', () => {
15311533
mocks.ddbDocClient.on(UpdateCommand).rejectsOnce(err);
15321534

15331535
const result = await templateRepository.proofRequestUpdate(
1534-
'template-owner',
1535-
'template-id'
1536+
'template-id',
1537+
{ userId: 'template-owner', clientId: 'client' }
15361538
);
15371539

15381540
expect(result).toEqual({
@@ -1558,8 +1560,8 @@ describe('templateRepository', () => {
15581560
mocks.ddbDocClient.on(UpdateCommand).rejectsOnce(err);
15591561

15601562
const result = await templateRepository.proofRequestUpdate(
1561-
'template-owner',
1562-
'template-id'
1563+
'template-id',
1564+
{ userId: 'template-owner', clientId: 'client' }
15631565
);
15641566

15651567
expect(result).toEqual({
@@ -1579,8 +1581,8 @@ describe('templateRepository', () => {
15791581
mocks.ddbDocClient.on(UpdateCommand).rejectsOnce(err);
15801582

15811583
const result = await templateRepository.proofRequestUpdate(
1582-
'template-owner',
1583-
'template-id'
1584+
'template-id',
1585+
{ userId: 'template-owner', clientId: 'client' }
15841586
);
15851587

15861588
expect(result).toEqual({

0 commit comments

Comments
 (0)