inlaweb-lib-dynamodb 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/clover.xml +127 -119
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/index.html +7 -7
- package/coverage/lcov-report/index.ts.html +64 -25
- package/coverage/lcov.info +194 -182
- package/dist/index.js +12 -0
- package/package.json +1 -1
- package/src/index.ts +13 -0
- package/tests/index.test.ts +21 -11
package/tests/index.test.ts
CHANGED
|
@@ -102,8 +102,8 @@ describe('DynamoLib', () => {
|
|
|
102
102
|
|
|
103
103
|
const result = await dynamoLib.query({tableName, searchParameters});
|
|
104
104
|
|
|
105
|
-
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "filter1"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "filter1"}, "KeyConditionExpression": "#key0 = :value0 and #key1 = :value1", "TableName": "testTable"});
|
|
106
|
-
expect(mockSend).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "filter1"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "filter1"}, "KeyConditionExpression": "#key0 = :value0 and #key1 = :value1", "TableName": "testTable"});
|
|
105
|
+
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "filter1"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "filter1"}, "IndexName": "GSI2", "KeyConditionExpression": "#key0 = :value0 and #key1 = :value1", "TableName": "testTable"});
|
|
106
|
+
expect(mockSend).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "filter1"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "filter1"}, "IndexName": "GSI2", "KeyConditionExpression": "#key0 = :value0 and #key1 = :value1", "TableName": "testTable"});
|
|
107
107
|
expect(result).toEqual(items);
|
|
108
108
|
});
|
|
109
109
|
it('should call QueryCommand with filterexpressions', async () => {
|
|
@@ -116,7 +116,7 @@ describe('DynamoLib', () => {
|
|
|
116
116
|
|
|
117
117
|
await dynamoLib.query({tableName, searchParameters});
|
|
118
118
|
|
|
119
|
-
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "filter1", "#key2": "filter2", "#key3": "filter3", "#key4": "filter4", "#key5": "filter5"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "filter1", ":value2": "filter", ":value3": "filter3", ":value4": "filter4", ":value5": "filter5"}, "FilterExpression": "#key1 = :value1 and contains (#key2, :value2) and begins_with(#key3, :value3) and attribute_exists (#key4) and attribute_not_exists (#key5)", "KeyConditionExpression": "#key0 = :value0", "TableName": "testTable"});
|
|
119
|
+
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "filter1", "#key2": "filter2", "#key3": "filter3", "#key4": "filter4", "#key5": "filter5"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "filter1", ":value2": "filter", ":value3": "filter3", ":value4": "filter4", ":value5": "filter5"}, "IndexName": "GSI2", "FilterExpression": "#key1 = :value1 and contains (#key2, :value2) and begins_with(#key3, :value3) and attribute_exists (#key4) and attribute_not_exists (#key5)", "KeyConditionExpression": "#key0 = :value0", "TableName": "testTable"});
|
|
120
120
|
});
|
|
121
121
|
it('should call QueryCommand with filterexpression for own registers', async () => {
|
|
122
122
|
const permission = 'OWNS';
|
|
@@ -125,7 +125,7 @@ describe('DynamoLib', () => {
|
|
|
125
125
|
|
|
126
126
|
await dynamoLib.query({tableName, searchParameters, permission, username});
|
|
127
127
|
|
|
128
|
-
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "creationUser"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "testUser"}, "FilterExpression": "#key1 = :value1", "KeyConditionExpression": "#key0 = :value0", "TableName": "testTable"});
|
|
128
|
+
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity", "#key1": "creationUser"}, "ExpressionAttributeValues": {":value0": "entity", ":value1": "testUser"}, "IndexName": "GSI2", "FilterExpression": "#key1 = :value1", "KeyConditionExpression": "#key0 = :value0", "TableName": "testTable"});
|
|
129
129
|
});
|
|
130
130
|
it('should call QueryCommand with keyCondition begins_with', async () => {
|
|
131
131
|
searchParameters.parameters[0].operator = "begins_with";
|
|
@@ -133,12 +133,7 @@ describe('DynamoLib', () => {
|
|
|
133
133
|
|
|
134
134
|
await dynamoLib.query({tableName, searchParameters});
|
|
135
135
|
|
|
136
|
-
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity"}, "ExpressionAttributeValues": {":value0": "entity"}, "KeyConditionExpression": "begins_with(#key0, :value0)", "TableName": "testTable"});
|
|
137
|
-
});
|
|
138
|
-
it('should throw error', async () => {
|
|
139
|
-
mockSend.mockRejectedValue(new Error("error"));
|
|
140
|
-
|
|
141
|
-
await expect(dynamoLib.query({tableName, searchParameters})).rejects.toThrow('error');
|
|
136
|
+
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity"}, "ExpressionAttributeValues": {":value0": "entity"}, "IndexName": "GSI2", "KeyConditionExpression": "begins_with(#key0, :value0)", "TableName": "testTable"});
|
|
142
137
|
});
|
|
143
138
|
it('should call QueryCommand with keyCondition between', async () => {
|
|
144
139
|
searchParameters.parameters[0].operator = "BETWEEN";
|
|
@@ -148,7 +143,17 @@ describe('DynamoLib', () => {
|
|
|
148
143
|
|
|
149
144
|
await dynamoLib.query({tableName, searchParameters});
|
|
150
145
|
|
|
151
|
-
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity"}, "ExpressionAttributeValues": {":value0": "2025-01-01", ":value10": "2025-01-31"}, "KeyConditionExpression": "#key0 BETWEEN :value0 AND :value10", "TableName": "testTable"});
|
|
146
|
+
expect(QueryCommand).toHaveBeenCalledWith({"ExpressionAttributeNames": {"#key0": "entity"}, "ExpressionAttributeValues": {":value0": "2025-01-01", ":value10": "2025-01-31"}, "IndexName": "GSI2", "KeyConditionExpression": "#key0 BETWEEN :value0 AND :value10", "TableName": "testTable"});
|
|
147
|
+
});
|
|
148
|
+
it('should call QueryCommand with optional parameters', async () => {
|
|
149
|
+
searchParameters.exclusiveStartKey = {"PK": "PK", "SK": "SK"};
|
|
150
|
+
searchParameters.limit = 10;
|
|
151
|
+
searchParameters.scanIndexForward = true;
|
|
152
|
+
mockSend.mockResolvedValue({ Items: items });
|
|
153
|
+
|
|
154
|
+
await dynamoLib.query({tableName, searchParameters});
|
|
155
|
+
|
|
156
|
+
expect(QueryCommand).toHaveBeenCalledWith({"ExclusiveStartKey": {"PK": "PK", "SK": "SK"}, "ExpressionAttributeNames": {"#key0": "entity"}, "ExpressionAttributeValues": {":value0": "entity"}, "IndexName": "GSI2", "KeyConditionExpression": "#key0 = :value0", "Limit": 10, "ScanIndexForward": true, "TableName": "testTable"});
|
|
152
157
|
});
|
|
153
158
|
it('should return undefined if items is not found', async () => {
|
|
154
159
|
|
|
@@ -158,6 +163,11 @@ describe('DynamoLib', () => {
|
|
|
158
163
|
|
|
159
164
|
expect(result).toEqual(undefined);
|
|
160
165
|
});
|
|
166
|
+
it('should throw error', async () => {
|
|
167
|
+
mockSend.mockRejectedValueOnce(new Error("error"));
|
|
168
|
+
|
|
169
|
+
await expect(dynamoLib.query({tableName, searchParameters})).rejects.toThrow('error');
|
|
170
|
+
});
|
|
161
171
|
});
|
|
162
172
|
|
|
163
173
|
describe('saveBatch', () => {
|