Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
fix: fix update query for Subscriptions (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
carvantes committed Mar 7, 2022
1 parent 0313b08 commit 3c41f05
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/dataServices/dynamoDbParamBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,64 @@ describe('buildUpdateDocumentStatusParam', () => {
expect(actualParam).toEqual(getExpectedParamForUpdateWithoutOldStatus(DOCUMENT_STATUS.LOCKED, id, vid));
});

test('Update Subscription', () => {
const id = '8cafa46d-08b4-4ee4-b51b-803e20ae8126';
const vid = 1;
const actualParam = DynamoDbParamBuilder.buildUpdateDocumentStatusParam(
null,
DOCUMENT_STATUS.AVAILABLE,
id,
vid,
'Subscription',
);

expect(actualParam).toMatchInlineSnapshot(
{
Update: {
ExpressionAttributeValues: {
':futureEndTs': {
N: expect.stringMatching(timeFromEpochInMsRegExp),
},
},
},
},
`
Object {
"Update": Object {
"ConditionExpression": "resourceType = :resourceType",
"ExpressionAttributeNames": Object {
"#subscriptionStatus": "_subscriptionStatus",
},
"ExpressionAttributeValues": Object {
":futureEndTs": Object {
"N": StringMatching /\\\\d\\{13\\}/,
},
":newStatus": Object {
"S": "AVAILABLE",
},
":resourceType": Object {
"S": "Subscription",
},
":subscriptionStatus": Object {
"S": "active",
},
},
"Key": Object {
"id": Object {
"S": "8cafa46d-08b4-4ee4-b51b-803e20ae8126",
},
"vid": Object {
"N": "1",
},
},
"TableName": "",
"UpdateExpression": "set documentStatus = :newStatus, lockEndTs = :futureEndTs, #subscriptionStatus = :subscriptionStatus",
},
}
`,
);
});

test('Update status correctly when there is NO requirement for what the old status needs to be', () => {
const id = '8cafa46d-08b4-4ee4-b51b-803e20ae8126';
const vid = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/dataServices/dynamoDbParamBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class DynamoDbParamBuilder {
};

if (expressionAttributeNames) {
params.ExpressionAttributeNames = expressionAttributeNames;
params.Update.ExpressionAttributeNames = expressionAttributeNames;
}

return params;
Expand Down

0 comments on commit 3c41f05

Please sign in to comment.