-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateExpressions.test.ts
61 lines (55 loc) · 1.72 KB
/
updateExpressions.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { ADD_ON, updateSetExpressions } from "./updateExpressions";
import { expect, test } from "vitest";
// Handles updates with empty set, listAppend, and setIfNotExists objects
test("should handle updates with empty set, listAppend, and setIfNotExists objects", () => {
const updates = {
set: {},
listAppend: {},
setIfNotExists: {},
};
const ExpressionAttributeValues = {};
const ExpressionAttributeNames = {};
const result = updateSetExpressions(
updates,
ExpressionAttributeValues,
ExpressionAttributeNames
);
expect(result).toBe("set ");
expect(ExpressionAttributeValues).toEqual({});
expect(ExpressionAttributeNames).toEqual({});
});
// function* incrementGenerator() {
// let i = 0;
// while (true) {
// yield i++;
// }
// }
// Generates correct set expressions when 'set' is provided
test('should generate correct set expressions when "set" is provided', () => {
const updates = {
set: {
attribute1: "value1",
attribute2: "value2",
},
};
const ExpressionAttributeValues = {};
const ExpressionAttributeNames = {};
const result = updateSetExpressions(
updates,
ExpressionAttributeValues,
ExpressionAttributeNames,
{
generateRandomId() {
return "randomId"
},
}
);
console.log('result', result)
expect(result).toBe(
`set #attribute1randomId = :randomId0${ADD_ON}valset, #attribute2randomId = :randomId1${ADD_ON}valset`
);
expect(ExpressionAttributeValues).toEqual({
[`:randomId0${ADD_ON}valset`]: "value1",
[`:randomId1${ADD_ON}valset`]: "value2",
});
});