@nsshunt/stsdatamanagement 1.18.178 → 1.18.179
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/dist/cliworker.js +10 -17
- package/dist/cliworker.js.map +1 -1
- package/dist/commonTypes.js +11 -14
- package/dist/commonTypes.js.map +1 -1
- package/dist/dalUserManager.js +7 -11
- package/dist/dalUserManager.js.map +1 -1
- package/dist/dalUserManager.test.js +45 -51
- package/dist/dalUserManager.test.js.map +1 -1
- package/dist/databaseutils.js +19 -26
- package/dist/databaseutils.js.map +1 -1
- package/dist/datagenerator.js +26 -33
- package/dist/datagenerator.js.map +1 -1
- package/dist/dbAccessLayerManager.js +5 -9
- package/dist/dbAccessLayerManager.js.map +1 -1
- package/dist/dbaccess.js +7 -23
- package/dist/dbaccess.js.map +1 -1
- package/dist/dbbuild.test.js +42 -47
- package/dist/dbbuild.test.js.map +1 -1
- package/dist/dberrors.js +13 -22
- package/dist/dberrors.js.map +1 -1
- package/dist/pcaccesslayer-entity.test.js +166 -171
- package/dist/pcaccesslayer-entity.test.js.map +1 -1
- package/dist/pcaccesslayer.test.js +208 -213
- package/dist/pcaccesslayer.test.js.map +1 -1
- package/dist/pgaccesslayer-old.js +114 -154
- package/dist/pgaccesslayer-old.js.map +1 -1
- package/dist/pgaccesslayer.js +131 -135
- package/dist/pgaccesslayer.js.map +1 -1
- package/dist/pgpoolmanager.js +32 -39
- package/dist/pgpoolmanager.js.map +1 -1
- package/dist/pgutils.js +10 -14
- package/dist/pgutils.js.map +1 -1
- package/dist/setupdb.js +8 -14
- package/dist/setupdb.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
1
|
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
import { beforeAll, afterAll, test, describe, expect } from 'vitest';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { goptions, $ResetOptions } from '@nsshunt/stsconfig';
|
|
5
|
+
import { JestSleep, defaultLogger, Sleep, edbaction } from '@nsshunt/stsutils';
|
|
6
|
+
import { DatabaseUtils } from './databaseutils.js';
|
|
7
|
+
import { GenericContainer } from "testcontainers";
|
|
8
|
+
import winston from 'winston';
|
|
9
|
+
import { DBAccessLayerManager } from './dbAccessLayerManager.js';
|
|
10
|
+
import { accessLayerType, eOperations } from './commonTypes.js';
|
|
11
|
+
import { StatusCodes } from 'http-status-codes';
|
|
17
12
|
const dbactionuser = 'jesttest';
|
|
18
13
|
const sort = (a, b) => {
|
|
19
14
|
if (a.detail && b.detail) {
|
|
@@ -23,20 +18,20 @@ const sort = (a, b) => {
|
|
|
23
18
|
return -1;
|
|
24
19
|
}
|
|
25
20
|
};
|
|
26
|
-
|
|
21
|
+
describe("Test pgaccesslayer", () => {
|
|
27
22
|
let postgresContainer;
|
|
28
23
|
let accessLayer;
|
|
29
24
|
const finalResults = {};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const logger =
|
|
25
|
+
beforeAll(async () => {
|
|
26
|
+
winston.format.combine(winston.format.colorize(), winston.format.simple());
|
|
27
|
+
const logger = winston.createLogger({
|
|
33
28
|
level: 'silly',
|
|
34
|
-
format:
|
|
29
|
+
format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
|
|
35
30
|
transports: [
|
|
36
|
-
new
|
|
31
|
+
new winston.transports.Console(),
|
|
37
32
|
]
|
|
38
33
|
});
|
|
39
|
-
postgresContainer = await new
|
|
34
|
+
postgresContainer = await new GenericContainer("postgres")
|
|
40
35
|
.withExposedPorts(5432)
|
|
41
36
|
.withEnvironment({
|
|
42
37
|
POSTGRES_PASSWORD: "postgres",
|
|
@@ -44,16 +39,16 @@ const sort = (a, b) => {
|
|
|
44
39
|
})
|
|
45
40
|
.withCommand(['-c', 'max_connections=20'])
|
|
46
41
|
.start();
|
|
47
|
-
await
|
|
42
|
+
await Sleep(1000);
|
|
48
43
|
const postgresHttpPort = postgresContainer.getMappedPort(5432);
|
|
49
44
|
const postgresHost = postgresContainer.getHost();
|
|
50
45
|
process.env.DB_HOST = `${postgresHost}:${postgresHttpPort}`;
|
|
51
46
|
process.env.POOL_SIZE = '10';
|
|
52
|
-
|
|
53
|
-
logger.info(
|
|
54
|
-
logger.info(
|
|
55
|
-
logger.info(
|
|
56
|
-
logger.info(
|
|
47
|
+
$ResetOptions();
|
|
48
|
+
logger.info(chalk.green(`httpPort: [${postgresHttpPort}]`));
|
|
49
|
+
logger.info(chalk.green(`host: [${postgresHost}]`));
|
|
50
|
+
logger.info(chalk.yellow(`connectionString: [${goptions.connectionString}]`));
|
|
51
|
+
logger.info(chalk.yellow(`defaultDatabaseConnectionString: [${goptions.defaultDatabaseConnectionString}]`));
|
|
57
52
|
const dbOptions = {
|
|
58
53
|
start: 0,
|
|
59
54
|
iterations: 10000,
|
|
@@ -62,26 +57,26 @@ const sort = (a, b) => {
|
|
|
62
57
|
workerScriptFolder: './dist', //@@
|
|
63
58
|
useMultiBar: false
|
|
64
59
|
};
|
|
65
|
-
const dbUtils = new
|
|
60
|
+
const dbUtils = new DatabaseUtils({
|
|
66
61
|
logger
|
|
67
62
|
});
|
|
68
63
|
await dbUtils.CreateDatabase(dbOptions);
|
|
69
|
-
await
|
|
70
|
-
logger.info(
|
|
71
|
-
accessLayer = new
|
|
72
|
-
accessLayerType:
|
|
64
|
+
await Sleep(1000);
|
|
65
|
+
logger.info(chalk.green(`Starting accessLayer`));
|
|
66
|
+
accessLayer = new DBAccessLayerManager().CreateAccessLayer({
|
|
67
|
+
accessLayerType: accessLayerType.postgresql,
|
|
73
68
|
accessLayerOptions: {
|
|
74
|
-
logger:
|
|
69
|
+
logger: defaultLogger,
|
|
75
70
|
usedefaultdb: false
|
|
76
71
|
}
|
|
77
72
|
});
|
|
78
|
-
logger.info(
|
|
73
|
+
logger.info(chalk.green(`accessLayer:startdatabase()`));
|
|
79
74
|
await accessLayer.StartDatabase();
|
|
80
75
|
}, 120000);
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
test('Testing Database Resource create, update, patch, read and delete', async () => {
|
|
77
|
+
expect.assertions(22);
|
|
83
78
|
const initialCount = await accessLayer.GetResourceCount();
|
|
84
|
-
|
|
79
|
+
expect(initialCount.detail).toEqual(20000);
|
|
85
80
|
// Create Record -------------------------------------------------------------------------------------
|
|
86
81
|
const userResourceType = {
|
|
87
82
|
name: `user`,
|
|
@@ -96,9 +91,9 @@ const sort = (a, b) => {
|
|
|
96
91
|
};
|
|
97
92
|
const userResourceTypeCreateRecord = await accessLayer.CreateResource(userResourceOptions, userResourceType);
|
|
98
93
|
const matchCreateResource = {
|
|
99
|
-
operation:
|
|
94
|
+
operation: eOperations.CreateResource,
|
|
100
95
|
options: userResourceOptions,
|
|
101
|
-
status:
|
|
96
|
+
status: StatusCodes.CREATED,
|
|
102
97
|
detail: {
|
|
103
98
|
dbaction: 1,
|
|
104
99
|
dbactionuser,
|
|
@@ -109,25 +104,25 @@ const sort = (a, b) => {
|
|
|
109
104
|
}
|
|
110
105
|
};
|
|
111
106
|
const createdResource = userResourceTypeCreateRecord.detail;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
expect(userResourceTypeCreateRecord).toMatchObject(matchCreateResource);
|
|
108
|
+
expect(createdResource.oid).not.toBeNull();
|
|
109
|
+
expect(new Date(createdResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
115
110
|
// Get Resource Count -------------------------------------------------------------------------------------
|
|
116
111
|
const count = await accessLayer.GetResourceCount();
|
|
117
|
-
|
|
112
|
+
expect(count.detail).toEqual(20001);
|
|
118
113
|
const matchGetResourceCount = {
|
|
119
|
-
operation:
|
|
114
|
+
operation: eOperations.GetResourceCount,
|
|
120
115
|
options: {},
|
|
121
|
-
status:
|
|
116
|
+
status: StatusCodes.OK,
|
|
122
117
|
detail: 20001
|
|
123
118
|
};
|
|
124
|
-
|
|
119
|
+
expect(count).toMatchObject(matchGetResourceCount);
|
|
125
120
|
// Get Record -------------------------------------------------------------------------------------
|
|
126
121
|
const getRecord1 = await accessLayer.GetResource(userResourceOptions);
|
|
127
122
|
const matchGetResource = {
|
|
128
|
-
operation:
|
|
123
|
+
operation: eOperations.GetResource,
|
|
129
124
|
options: userResourceOptions,
|
|
130
|
-
status:
|
|
125
|
+
status: StatusCodes.OK,
|
|
131
126
|
detail: {
|
|
132
127
|
dbaction: 1,
|
|
133
128
|
dbactionuser,
|
|
@@ -138,9 +133,9 @@ const sort = (a, b) => {
|
|
|
138
133
|
}
|
|
139
134
|
};
|
|
140
135
|
const getResource = getRecord1.detail;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
expect(getRecord1).toMatchObject(matchGetResource);
|
|
137
|
+
expect(getResource.oid).not.toBeNull();
|
|
138
|
+
expect(new Date(getResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
144
139
|
// Update Record -------------------------------------------------------------------------------------
|
|
145
140
|
const updateUserResource = {
|
|
146
141
|
name: userResourceType.name,
|
|
@@ -149,9 +144,9 @@ const sort = (a, b) => {
|
|
|
149
144
|
};
|
|
150
145
|
const userResourceTypeUpdateRecord = await accessLayer.UpdateResource(userResourceOptions, updateUserResource);
|
|
151
146
|
const matchUpdateResource = {
|
|
152
|
-
operation:
|
|
147
|
+
operation: eOperations.UpdateResource,
|
|
153
148
|
options: userResourceOptions,
|
|
154
|
-
status:
|
|
149
|
+
status: StatusCodes.OK,
|
|
155
150
|
detail: {
|
|
156
151
|
dbaction: 2,
|
|
157
152
|
dbactionuser,
|
|
@@ -162,9 +157,9 @@ const sort = (a, b) => {
|
|
|
162
157
|
}
|
|
163
158
|
};
|
|
164
159
|
const updatedResource = userResourceTypeUpdateRecord.detail;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
160
|
+
expect(userResourceTypeUpdateRecord).toMatchObject(matchUpdateResource);
|
|
161
|
+
expect(updatedResource.oid).not.toBeNull();
|
|
162
|
+
expect(new Date(updatedResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
168
163
|
// Patch Record -------------------------------------------------------------------------------------
|
|
169
164
|
const patchUserResource = {
|
|
170
165
|
name: userResourceType.name,
|
|
@@ -172,9 +167,9 @@ const sort = (a, b) => {
|
|
|
172
167
|
};
|
|
173
168
|
const patchResourceRecord = await accessLayer.PatchResource(userResourceOptions, patchUserResource);
|
|
174
169
|
const matchPatchResource = {
|
|
175
|
-
operation:
|
|
170
|
+
operation: eOperations.PatchResource,
|
|
176
171
|
options: userResourceOptions,
|
|
177
|
-
status:
|
|
172
|
+
status: StatusCodes.OK,
|
|
178
173
|
detail: {
|
|
179
174
|
dbaction: 2,
|
|
180
175
|
dbactionuser,
|
|
@@ -189,15 +184,15 @@ const sort = (a, b) => {
|
|
|
189
184
|
}
|
|
190
185
|
};
|
|
191
186
|
const patchedResource = patchResourceRecord.detail;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
expect(patchResourceRecord).toMatchObject(matchPatchResource);
|
|
188
|
+
expect(patchedResource.oid).not.toBeNull();
|
|
189
|
+
expect(new Date(patchedResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
195
190
|
// Delete Record -------------------------------------------------------------------------------------
|
|
196
191
|
const userResourceTypeDeleteRecord = await accessLayer.DeleteResource(userResourceOptions);
|
|
197
192
|
const matchDeleteResource = {
|
|
198
|
-
operation:
|
|
193
|
+
operation: eOperations.DeleteResource,
|
|
199
194
|
options: userResourceOptions,
|
|
200
|
-
status:
|
|
195
|
+
status: StatusCodes.OK,
|
|
201
196
|
detail: {
|
|
202
197
|
dbaction: 3,
|
|
203
198
|
dbactionuser,
|
|
@@ -212,32 +207,32 @@ const sort = (a, b) => {
|
|
|
212
207
|
}
|
|
213
208
|
};
|
|
214
209
|
const deletedResource = userResourceTypeDeleteRecord.detail;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
210
|
+
expect(userResourceTypeDeleteRecord).toMatchObject(matchDeleteResource);
|
|
211
|
+
expect(deletedResource.oid).not.toBeNull();
|
|
212
|
+
expect(new Date(deletedResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
218
213
|
// Get a Deleted Record -------------------------------------------------------------------------------------
|
|
219
214
|
const getDeletedRecord = await accessLayer.GetResource(userResourceOptions);
|
|
220
215
|
const matchNotFoundResource = {
|
|
221
|
-
operation:
|
|
216
|
+
operation: eOperations.GetResource,
|
|
222
217
|
options: userResourceOptions,
|
|
223
|
-
status:
|
|
218
|
+
status: StatusCodes.NOT_FOUND,
|
|
224
219
|
detail: null,
|
|
225
220
|
error: {
|
|
226
|
-
operation:
|
|
227
|
-
status:
|
|
221
|
+
operation: eOperations.GetResource,
|
|
222
|
+
status: StatusCodes.NOT_FOUND
|
|
228
223
|
}
|
|
229
224
|
};
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
expect(getDeletedRecord).toMatchObject(matchNotFoundResource);
|
|
226
|
+
expect(getDeletedRecord.error?.errorMessage).toMatch(/\(current version\) not found/);
|
|
232
227
|
// Get Resource Count -------------------------------------------------------------------------------------
|
|
233
228
|
const resourceCountPostDelete = await accessLayer.GetResourceCount();
|
|
234
229
|
const matchResourceCountPostDelete = {
|
|
235
|
-
operation:
|
|
230
|
+
operation: eOperations.GetResourceCount,
|
|
236
231
|
options: {},
|
|
237
|
-
status:
|
|
232
|
+
status: StatusCodes.OK,
|
|
238
233
|
detail: 20000
|
|
239
234
|
};
|
|
240
|
-
|
|
235
|
+
expect(resourceCountPostDelete).toMatchObject(matchResourceCountPostDelete);
|
|
241
236
|
// Get Resources using filter -------------------------------------------------------------------------------------
|
|
242
237
|
const resources = await accessLayer.GetResources({
|
|
243
238
|
filters: {
|
|
@@ -245,10 +240,10 @@ const sort = (a, b) => {
|
|
|
245
240
|
limit: '10',
|
|
246
241
|
}
|
|
247
242
|
});
|
|
248
|
-
|
|
243
|
+
expect(resources.detail.length).toEqual(10);
|
|
249
244
|
}, 120000);
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
test('Testing Database Entity create, update, patch, read and delete', async () => {
|
|
246
|
+
expect.assertions(30);
|
|
252
247
|
const userResourceType = {
|
|
253
248
|
name: 'user-t2',
|
|
254
249
|
notes: 'user-t2 notes',
|
|
@@ -262,11 +257,11 @@ const sort = (a, b) => {
|
|
|
262
257
|
};
|
|
263
258
|
const userResourceTypeCreateRecord = await accessLayer.CreateResource(userResourceOptions, userResourceType);
|
|
264
259
|
const matchCreateResource = {
|
|
265
|
-
operation:
|
|
260
|
+
operation: eOperations.CreateResource,
|
|
266
261
|
options: userResourceOptions,
|
|
267
|
-
status:
|
|
262
|
+
status: StatusCodes.CREATED,
|
|
268
263
|
detail: {
|
|
269
|
-
dbaction:
|
|
264
|
+
dbaction: edbaction.created,
|
|
270
265
|
dbactionuser,
|
|
271
266
|
resdesc: userResourceType,
|
|
272
267
|
resname: userResourceType.name,
|
|
@@ -275,9 +270,9 @@ const sort = (a, b) => {
|
|
|
275
270
|
}
|
|
276
271
|
};
|
|
277
272
|
const createdResource = userResourceTypeCreateRecord.detail;
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
273
|
+
expect(userResourceTypeCreateRecord).toMatchObject(matchCreateResource);
|
|
274
|
+
expect(createdResource.oid).not.toBeNull();
|
|
275
|
+
expect(new Date(createdResource.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
281
276
|
const resOid = createdResource.oid;
|
|
282
277
|
const userEntity01 = {
|
|
283
278
|
userId: 'user01',
|
|
@@ -295,12 +290,12 @@ const sort = (a, b) => {
|
|
|
295
290
|
// Create Record -------------------------------------------------------------------------------------
|
|
296
291
|
const entityUser01CreateRecord = await accessLayer.CreateEntity(entityResourceOptions, userEntity01);
|
|
297
292
|
const matchCreateEntity = {
|
|
298
|
-
operation:
|
|
293
|
+
operation: eOperations.CreateEntity,
|
|
299
294
|
options: entityResourceOptions,
|
|
300
|
-
status:
|
|
295
|
+
status: StatusCodes.CREATED,
|
|
301
296
|
detail: {
|
|
302
297
|
resourceoid: resOid,
|
|
303
|
-
dbaction:
|
|
298
|
+
dbaction: edbaction.created,
|
|
304
299
|
dbactionuser,
|
|
305
300
|
entvalue: userEntity01,
|
|
306
301
|
entname: userEntity01.userId,
|
|
@@ -309,27 +304,27 @@ const sort = (a, b) => {
|
|
|
309
304
|
}
|
|
310
305
|
};
|
|
311
306
|
const createdEntity = entityUser01CreateRecord.detail;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
307
|
+
expect(entityUser01CreateRecord).toMatchObject(matchCreateEntity);
|
|
308
|
+
expect(createdEntity.oid).not.toBeNull();
|
|
309
|
+
expect(new Date(createdEntity.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
315
310
|
// Get Entity Count Post Create -------------------------------------------------------------------------------------
|
|
316
311
|
const entityCountPostCreate = await accessLayer.GetEntityCount(entityResourceOptions);
|
|
317
312
|
const matchEntityCountPostCreate = {
|
|
318
|
-
operation:
|
|
313
|
+
operation: eOperations.GetEntityCount,
|
|
319
314
|
options: entityResourceOptions,
|
|
320
|
-
status:
|
|
315
|
+
status: StatusCodes.OK,
|
|
321
316
|
detail: 1
|
|
322
317
|
};
|
|
323
|
-
|
|
318
|
+
expect(entityCountPostCreate).toMatchObject(matchEntityCountPostCreate);
|
|
324
319
|
// Get Record -------------------------------------------------------------------------------------
|
|
325
320
|
const getRecord1 = await accessLayer.GetEntity(entityResourceOptions);
|
|
326
321
|
const matchGetEntity = {
|
|
327
|
-
operation:
|
|
322
|
+
operation: eOperations.GetEntity,
|
|
328
323
|
options: entityResourceOptions,
|
|
329
|
-
status:
|
|
324
|
+
status: StatusCodes.OK,
|
|
330
325
|
detail: {
|
|
331
326
|
resourceoid: resOid,
|
|
332
|
-
dbaction:
|
|
327
|
+
dbaction: edbaction.created,
|
|
333
328
|
dbactionuser,
|
|
334
329
|
entvalue: userEntity01,
|
|
335
330
|
entname: userEntity01.userId,
|
|
@@ -338,9 +333,9 @@ const sort = (a, b) => {
|
|
|
338
333
|
}
|
|
339
334
|
};
|
|
340
335
|
const getEntityRecord = getRecord1.detail;
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
336
|
+
expect(getRecord1).toMatchObject(matchGetEntity);
|
|
337
|
+
expect(getEntityRecord.oid).not.toBeNull();
|
|
338
|
+
expect(new Date(getEntityRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
344
339
|
// Update Record -------------------------------------------------------------------------------------
|
|
345
340
|
const updateEntityResource = {
|
|
346
341
|
userId: userEntity01.userId,
|
|
@@ -350,12 +345,12 @@ const sort = (a, b) => {
|
|
|
350
345
|
};
|
|
351
346
|
const userEntity01UpdateRecord = await accessLayer.UpdateEntity(entityResourceOptions, updateEntityResource);
|
|
352
347
|
const matchUpdateEntity = {
|
|
353
|
-
operation:
|
|
348
|
+
operation: eOperations.UpdateEntity,
|
|
354
349
|
options: entityResourceOptions,
|
|
355
|
-
status:
|
|
350
|
+
status: StatusCodes.OK,
|
|
356
351
|
detail: {
|
|
357
352
|
resourceoid: resOid,
|
|
358
|
-
dbaction:
|
|
353
|
+
dbaction: edbaction.updated,
|
|
359
354
|
dbactionuser,
|
|
360
355
|
entvalue: updateEntityResource,
|
|
361
356
|
entname: updateEntityResource.userId,
|
|
@@ -364,9 +359,9 @@ const sort = (a, b) => {
|
|
|
364
359
|
}
|
|
365
360
|
};
|
|
366
361
|
const updateEntityRecord = userEntity01UpdateRecord.detail;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
362
|
+
expect(userEntity01UpdateRecord).toMatchObject(matchUpdateEntity);
|
|
363
|
+
expect(updateEntityRecord.oid).not.toBeNull();
|
|
364
|
+
expect(new Date(updateEntityRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
370
365
|
// Patch Record -------------------------------------------------------------------------------------
|
|
371
366
|
const patchEntityResource = {
|
|
372
367
|
userId: userEntity01.userId,
|
|
@@ -374,12 +369,12 @@ const sort = (a, b) => {
|
|
|
374
369
|
};
|
|
375
370
|
const userEntity01PatchRecord = await accessLayer.PatchEntity(entityResourceOptions, patchEntityResource);
|
|
376
371
|
const matchPatchedEntity = {
|
|
377
|
-
operation:
|
|
372
|
+
operation: eOperations.PatchEntity,
|
|
378
373
|
options: entityResourceOptions,
|
|
379
|
-
status:
|
|
374
|
+
status: StatusCodes.OK,
|
|
380
375
|
detail: {
|
|
381
376
|
resourceoid: resOid,
|
|
382
|
-
dbaction:
|
|
377
|
+
dbaction: edbaction.updated,
|
|
383
378
|
dbactionuser,
|
|
384
379
|
entvalue: { ...updateEntityResource, ...patchEntityResource },
|
|
385
380
|
entname: patchEntityResource.userId,
|
|
@@ -388,18 +383,18 @@ const sort = (a, b) => {
|
|
|
388
383
|
}
|
|
389
384
|
};
|
|
390
385
|
const patchedEntityRecord = userEntity01PatchRecord.detail;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
386
|
+
expect(userEntity01PatchRecord).toMatchObject(matchPatchedEntity);
|
|
387
|
+
expect(patchedEntityRecord.oid).not.toBeNull();
|
|
388
|
+
expect(new Date(patchedEntityRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
394
389
|
// Delete Record -------------------------------------------------------------------------------------
|
|
395
390
|
const userEntity01DeleteRecord = await accessLayer.DeleteEntity(entityResourceOptions);
|
|
396
391
|
const matchDeletedEntity = {
|
|
397
|
-
operation:
|
|
392
|
+
operation: eOperations.DeleteEntity,
|
|
398
393
|
options: entityResourceOptions,
|
|
399
|
-
status:
|
|
394
|
+
status: StatusCodes.OK,
|
|
400
395
|
detail: {
|
|
401
396
|
resourceoid: resOid,
|
|
402
|
-
dbaction:
|
|
397
|
+
dbaction: edbaction.deleted,
|
|
403
398
|
dbactionuser,
|
|
404
399
|
entvalue: { ...updateEntityResource, ...patchEntityResource },
|
|
405
400
|
entname: patchEntityResource.userId,
|
|
@@ -408,32 +403,32 @@ const sort = (a, b) => {
|
|
|
408
403
|
}
|
|
409
404
|
};
|
|
410
405
|
const deletedEntityRecord = userEntity01DeleteRecord.detail;
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
406
|
+
expect(userEntity01DeleteRecord).toMatchObject(matchDeletedEntity);
|
|
407
|
+
expect(deletedEntityRecord.oid).not.toBeNull();
|
|
408
|
+
expect(new Date(deletedEntityRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
414
409
|
// Get a Deleted Record -------------------------------------------------------------------------------------
|
|
415
410
|
const getDeleted = await accessLayer.GetEntity(entityResourceOptions);
|
|
416
411
|
const matchGetDeletedEntity = {
|
|
417
|
-
operation:
|
|
412
|
+
operation: eOperations.GetEntity,
|
|
418
413
|
options: entityResourceOptions,
|
|
419
|
-
status:
|
|
414
|
+
status: StatusCodes.NOT_FOUND,
|
|
420
415
|
detail: null,
|
|
421
416
|
error: {
|
|
422
|
-
operation:
|
|
423
|
-
status:
|
|
417
|
+
operation: eOperations.GetEntity,
|
|
418
|
+
status: StatusCodes.NOT_FOUND
|
|
424
419
|
}
|
|
425
420
|
};
|
|
426
|
-
|
|
427
|
-
|
|
421
|
+
expect(getDeleted).toMatchObject(matchGetDeletedEntity);
|
|
422
|
+
expect(getDeleted.error?.errorMessage).toMatch(/\(current version\) not found/);
|
|
428
423
|
// Get Entity Count Post Delete -------------------------------------------------------------------------------------
|
|
429
424
|
const entityCountPostDelete = await accessLayer.GetEntityCount(entityResourceOptions);
|
|
430
425
|
const matchEntityCountPostDelete = {
|
|
431
|
-
operation:
|
|
426
|
+
operation: eOperations.GetEntityCount,
|
|
432
427
|
options: entityResourceOptions,
|
|
433
|
-
status:
|
|
428
|
+
status: StatusCodes.OK,
|
|
434
429
|
detail: 0
|
|
435
430
|
};
|
|
436
|
-
|
|
431
|
+
expect(entityCountPostDelete).toMatchObject(matchEntityCountPostDelete);
|
|
437
432
|
// Create Additional Entities -------------------------------------------------------------------------------------
|
|
438
433
|
const expDetail = [];
|
|
439
434
|
const createCount = 2;
|
|
@@ -454,12 +449,12 @@ const sort = (a, b) => {
|
|
|
454
449
|
const entityCreateRecord = await accessLayer.CreateEntity(entityResourceOptions, userEntity);
|
|
455
450
|
expDetail.push(entityCreateRecord.detail);
|
|
456
451
|
const matchCreateEntity = {
|
|
457
|
-
operation:
|
|
452
|
+
operation: eOperations.CreateEntity,
|
|
458
453
|
options: entityResourceOptions,
|
|
459
|
-
status:
|
|
454
|
+
status: StatusCodes.CREATED,
|
|
460
455
|
detail: {
|
|
461
456
|
resourceoid: resOid,
|
|
462
|
-
dbaction:
|
|
457
|
+
dbaction: edbaction.created,
|
|
463
458
|
dbactionuser,
|
|
464
459
|
entvalue: userEntity,
|
|
465
460
|
entname: userEntity.userId,
|
|
@@ -468,9 +463,9 @@ const sort = (a, b) => {
|
|
|
468
463
|
}
|
|
469
464
|
};
|
|
470
465
|
const createdEntityRecord = entityCreateRecord.detail;
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
466
|
+
expect(entityCreateRecord).toMatchObject(matchCreateEntity);
|
|
467
|
+
expect(createdEntityRecord.oid).not.toBeNull();
|
|
468
|
+
expect(new Date(createdEntityRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
474
469
|
}
|
|
475
470
|
// Get Entities (using filters) -------------------------------------------------------------------------------------
|
|
476
471
|
const entities = await accessLayer.GetEntities({
|
|
@@ -479,7 +474,7 @@ const sort = (a, b) => {
|
|
|
479
474
|
filter: '%'
|
|
480
475
|
}
|
|
481
476
|
});
|
|
482
|
-
|
|
477
|
+
expect(entities.detail).toMatchObject(expDetail);
|
|
483
478
|
// Get Entity Count Post Delete -------------------------------------------------------------------------------------
|
|
484
479
|
const entityCountOptions = {
|
|
485
480
|
filters: {
|
|
@@ -488,12 +483,12 @@ const sort = (a, b) => {
|
|
|
488
483
|
};
|
|
489
484
|
const entityCountPostMultiCreate = await accessLayer.GetEntityCount(entityCountOptions);
|
|
490
485
|
const matchEntityCountPostMultiCreate = {
|
|
491
|
-
operation:
|
|
486
|
+
operation: eOperations.GetEntityCount,
|
|
492
487
|
options: entityCountOptions,
|
|
493
|
-
status:
|
|
488
|
+
status: StatusCodes.OK,
|
|
494
489
|
detail: createCount
|
|
495
490
|
};
|
|
496
|
-
|
|
491
|
+
expect(entityCountPostMultiCreate).toMatchObject(matchEntityCountPostMultiCreate);
|
|
497
492
|
}, 120000);
|
|
498
493
|
/*
|
|
499
494
|
test('Testing Database Resource create and patch', async () => {
|
|
@@ -1106,10 +1101,10 @@ const sort = (a, b) => {
|
|
|
1106
1101
|
});
|
|
1107
1102
|
}, 120000);
|
|
1108
1103
|
*/
|
|
1109
|
-
|
|
1104
|
+
test('Testing Database Resource Batch Create', async () => {
|
|
1110
1105
|
const createStart = 100;
|
|
1111
1106
|
const createNum = 60;
|
|
1112
|
-
|
|
1107
|
+
expect.assertions(180);
|
|
1113
1108
|
for (let i = createStart; i < createStart + createNum; i++) {
|
|
1114
1109
|
const userResourceType = {
|
|
1115
1110
|
name: `user_patch_test_${i}`,
|
|
@@ -1123,27 +1118,27 @@ const sort = (a, b) => {
|
|
|
1123
1118
|
}
|
|
1124
1119
|
}, userResourceType);
|
|
1125
1120
|
const checkObject = {
|
|
1126
|
-
status:
|
|
1121
|
+
status: StatusCodes.CREATED,
|
|
1127
1122
|
detail: {
|
|
1128
1123
|
resname: userResourceType.name,
|
|
1129
1124
|
resdesc: userResourceType,
|
|
1130
1125
|
vnum: '1',
|
|
1131
1126
|
validto: null,
|
|
1132
|
-
dbaction:
|
|
1127
|
+
dbaction: edbaction.created,
|
|
1133
1128
|
dbactionuser
|
|
1134
1129
|
}
|
|
1135
1130
|
};
|
|
1136
1131
|
const createdResourceRecord = userResourceTypeCreateRecord.detail;
|
|
1137
1132
|
finalResults[createdResourceRecord.resname] = createdResourceRecord;
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1133
|
+
expect(userResourceTypeCreateRecord).toMatchObject(checkObject);
|
|
1134
|
+
expect(new Date(createdResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
1135
|
+
expect(parseInt(createdResourceRecord.oid)).toBeGreaterThan(0);
|
|
1141
1136
|
}
|
|
1142
1137
|
}, 120000);
|
|
1143
|
-
|
|
1138
|
+
test('Testing Database Resource Batch Create using Update', async () => {
|
|
1144
1139
|
const updateStart = 100;
|
|
1145
1140
|
const updateNum = 5;
|
|
1146
|
-
|
|
1141
|
+
expect.assertions(15);
|
|
1147
1142
|
const resourceParameterPatchRecord = [];
|
|
1148
1143
|
const testRecords = [];
|
|
1149
1144
|
for (let i = updateStart; i < updateStart + updateNum; i++) {
|
|
@@ -1164,16 +1159,16 @@ const sort = (a, b) => {
|
|
|
1164
1159
|
};
|
|
1165
1160
|
resourceParameterPatchRecord.push(resourceParameterRecord);
|
|
1166
1161
|
const testObject = {
|
|
1167
|
-
status:
|
|
1162
|
+
status: StatusCodes.CREATED,
|
|
1168
1163
|
detail: {
|
|
1169
1164
|
resname: name,
|
|
1170
1165
|
resdesc: userResourceTypePatch,
|
|
1171
1166
|
vnum: "1",
|
|
1172
1167
|
validto: null,
|
|
1173
|
-
dbaction:
|
|
1168
|
+
dbaction: edbaction.created,
|
|
1174
1169
|
dbactionuser
|
|
1175
1170
|
},
|
|
1176
|
-
operation:
|
|
1171
|
+
operation: eOperations.UpdateResources,
|
|
1177
1172
|
options: {}
|
|
1178
1173
|
};
|
|
1179
1174
|
testRecords.push(testObject);
|
|
@@ -1184,18 +1179,18 @@ const sort = (a, b) => {
|
|
|
1184
1179
|
testRecords.sort(sort);
|
|
1185
1180
|
if (retVal.length === testRecords.length) {
|
|
1186
1181
|
for (let i = 0; i < retVal.length; i++) {
|
|
1187
|
-
|
|
1182
|
+
expect(retVal[i]).toMatchObject(testRecords[i]);
|
|
1188
1183
|
const updatedResourceRecord = retVal[i].detail;
|
|
1189
1184
|
finalResults[updatedResourceRecord.resname] = updatedResourceRecord;
|
|
1190
|
-
|
|
1191
|
-
|
|
1185
|
+
expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
1186
|
+
expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
|
|
1192
1187
|
}
|
|
1193
1188
|
}
|
|
1194
1189
|
}, 120000);
|
|
1195
|
-
|
|
1190
|
+
test('Testing Database Resource Batch Update', async () => {
|
|
1196
1191
|
const updateStart = 100;
|
|
1197
1192
|
const updateNum = 5;
|
|
1198
|
-
|
|
1193
|
+
expect.assertions(15);
|
|
1199
1194
|
const resourceParameterPatchRecord = [];
|
|
1200
1195
|
const testRecords = [];
|
|
1201
1196
|
for (let i = updateStart; i < updateStart + updateNum; i++) {
|
|
@@ -1216,16 +1211,16 @@ const sort = (a, b) => {
|
|
|
1216
1211
|
};
|
|
1217
1212
|
resourceParameterPatchRecord.push(resourceParameterRecord);
|
|
1218
1213
|
const testObject = {
|
|
1219
|
-
status:
|
|
1214
|
+
status: StatusCodes.OK,
|
|
1220
1215
|
detail: {
|
|
1221
1216
|
resname: name,
|
|
1222
1217
|
resdesc: userResourceTypePatch,
|
|
1223
1218
|
vnum: "2",
|
|
1224
1219
|
validto: null,
|
|
1225
|
-
dbaction:
|
|
1220
|
+
dbaction: edbaction.updated,
|
|
1226
1221
|
dbactionuser
|
|
1227
1222
|
},
|
|
1228
|
-
operation:
|
|
1223
|
+
operation: eOperations.UpdateResources,
|
|
1229
1224
|
options: {}
|
|
1230
1225
|
};
|
|
1231
1226
|
testRecords.push(testObject);
|
|
@@ -1236,19 +1231,19 @@ const sort = (a, b) => {
|
|
|
1236
1231
|
testRecords.sort(sort);
|
|
1237
1232
|
if (retVal.length === testRecords.length) {
|
|
1238
1233
|
for (let i = 0; i < retVal.length; i++) {
|
|
1239
|
-
|
|
1234
|
+
expect(retVal[i]).toMatchObject(testRecords[i]);
|
|
1240
1235
|
const updatedResourceRecord = retVal[i].detail;
|
|
1241
1236
|
finalResults[updatedResourceRecord.resname] = updatedResourceRecord;
|
|
1242
|
-
|
|
1243
|
-
|
|
1237
|
+
expect(new Date(updatedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
1238
|
+
expect(parseInt(updatedResourceRecord.oid)).toBeGreaterThan(0);
|
|
1244
1239
|
}
|
|
1245
1240
|
}
|
|
1246
1241
|
}, 120000);
|
|
1247
|
-
|
|
1242
|
+
test('Testing Database Resource Batch Update with Errors', async () => {
|
|
1248
1243
|
const updateErrorStart = 110;
|
|
1249
1244
|
const updateErrorNum = 5;
|
|
1250
1245
|
const updateErrorIndex = 112;
|
|
1251
|
-
|
|
1246
|
+
expect.assertions(6);
|
|
1252
1247
|
const resourceParameterPatchRecord = [];
|
|
1253
1248
|
const testRecords = [];
|
|
1254
1249
|
for (let i = updateErrorStart; i < updateErrorStart + updateErrorNum; i++) {
|
|
@@ -1274,22 +1269,22 @@ const sort = (a, b) => {
|
|
|
1274
1269
|
resourceParameterPatchRecord.push(resourceParameterRecord);
|
|
1275
1270
|
if (i === updateErrorIndex) {
|
|
1276
1271
|
const testObject = {
|
|
1277
|
-
status:
|
|
1272
|
+
status: StatusCodes.NOT_FOUND,
|
|
1278
1273
|
detail: null,
|
|
1279
|
-
operation:
|
|
1274
|
+
operation: eOperations.GetResource,
|
|
1280
1275
|
options: {},
|
|
1281
1276
|
error: {
|
|
1282
|
-
operation:
|
|
1283
|
-
status:
|
|
1277
|
+
operation: eOperations.GetResource,
|
|
1278
|
+
status: StatusCodes.NOT_FOUND
|
|
1284
1279
|
}
|
|
1285
1280
|
};
|
|
1286
1281
|
testRecords.push(testObject);
|
|
1287
1282
|
}
|
|
1288
1283
|
else {
|
|
1289
1284
|
const testObject = {
|
|
1290
|
-
status:
|
|
1285
|
+
status: StatusCodes.OK,
|
|
1291
1286
|
detail: null,
|
|
1292
|
-
operation:
|
|
1287
|
+
operation: eOperations.UpdateResources,
|
|
1293
1288
|
options: {}
|
|
1294
1289
|
};
|
|
1295
1290
|
testRecords.push(testObject);
|
|
@@ -1301,12 +1296,12 @@ const sort = (a, b) => {
|
|
|
1301
1296
|
testRecords.sort(sort);
|
|
1302
1297
|
if (retVal.length === testRecords.length) {
|
|
1303
1298
|
for (let i = 0; i < retVal.length; i++) {
|
|
1304
|
-
|
|
1299
|
+
expect(retVal[i]).toMatchObject(testRecords[i]);
|
|
1305
1300
|
if (retVal[i].error) {
|
|
1306
1301
|
const updatedResourceRecordError = retVal[i].error;
|
|
1307
1302
|
const resName = retVal[i].options.filters.resname;
|
|
1308
1303
|
finalResults[resName] = updatedResourceRecordError;
|
|
1309
|
-
|
|
1304
|
+
expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
|
|
1310
1305
|
}
|
|
1311
1306
|
else {
|
|
1312
1307
|
const resName = retVal[i].options.filters.resname;
|
|
@@ -1316,10 +1311,10 @@ const sort = (a, b) => {
|
|
|
1316
1311
|
}
|
|
1317
1312
|
}
|
|
1318
1313
|
}, 120000);
|
|
1319
|
-
|
|
1314
|
+
test('Testing Database Resource Batch Patch', async () => {
|
|
1320
1315
|
const patchStart = 120;
|
|
1321
1316
|
const patchNum = 5;
|
|
1322
|
-
|
|
1317
|
+
expect.assertions(15);
|
|
1323
1318
|
const resourceParameterPatchRecord = [];
|
|
1324
1319
|
const testRecords = [];
|
|
1325
1320
|
for (let i = patchStart; i < patchStart + patchNum; i++) {
|
|
@@ -1344,16 +1339,16 @@ const sort = (a, b) => {
|
|
|
1344
1339
|
};
|
|
1345
1340
|
resourceParameterPatchRecord.push(resourceParameterRecord);
|
|
1346
1341
|
const testObject = {
|
|
1347
|
-
status:
|
|
1342
|
+
status: StatusCodes.OK,
|
|
1348
1343
|
detail: {
|
|
1349
1344
|
resname: name,
|
|
1350
1345
|
resdesc: userResourceTypePostPatch,
|
|
1351
1346
|
vnum: "2",
|
|
1352
1347
|
validto: null,
|
|
1353
|
-
dbaction:
|
|
1348
|
+
dbaction: edbaction.updated,
|
|
1354
1349
|
dbactionuser
|
|
1355
1350
|
},
|
|
1356
|
-
operation:
|
|
1351
|
+
operation: eOperations.PatchResources,
|
|
1357
1352
|
options: {}
|
|
1358
1353
|
};
|
|
1359
1354
|
testRecords.push(testObject);
|
|
@@ -1364,19 +1359,19 @@ const sort = (a, b) => {
|
|
|
1364
1359
|
testRecords.sort(sort);
|
|
1365
1360
|
if (retVal.length === testRecords.length) {
|
|
1366
1361
|
for (let i = 0; i < retVal.length; i++) {
|
|
1367
|
-
|
|
1362
|
+
expect(retVal[i]).toMatchObject(testRecords[i]);
|
|
1368
1363
|
const patchedResourceRecord = retVal[i].detail;
|
|
1369
1364
|
finalResults[patchedResourceRecord.resname] = patchedResourceRecord;
|
|
1370
|
-
|
|
1371
|
-
|
|
1365
|
+
expect(new Date(patchedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
1366
|
+
expect(parseInt(patchedResourceRecord.oid)).toBeGreaterThan(0);
|
|
1372
1367
|
}
|
|
1373
1368
|
}
|
|
1374
1369
|
}, 120000);
|
|
1375
|
-
|
|
1370
|
+
test('Testing Database Resource Batch Patch with Errors', async () => {
|
|
1376
1371
|
const patchErrorStart = 130;
|
|
1377
1372
|
const patchErrorNum = 5;
|
|
1378
1373
|
const patchErrorIndex = 132;
|
|
1379
|
-
|
|
1374
|
+
expect.assertions(6);
|
|
1380
1375
|
const resourceParameterPatchRecord = [];
|
|
1381
1376
|
const testRecords = [];
|
|
1382
1377
|
for (let i = patchErrorStart; i < patchErrorStart + patchErrorNum; i++) {
|
|
@@ -1401,22 +1396,22 @@ const sort = (a, b) => {
|
|
|
1401
1396
|
resourceParameterPatchRecord.push(resourceParameterRecord);
|
|
1402
1397
|
if (i === patchErrorIndex) {
|
|
1403
1398
|
const testObject = {
|
|
1404
|
-
status:
|
|
1399
|
+
status: StatusCodes.NOT_FOUND,
|
|
1405
1400
|
detail: null,
|
|
1406
|
-
operation:
|
|
1401
|
+
operation: eOperations.GetResource,
|
|
1407
1402
|
options: {},
|
|
1408
1403
|
error: {
|
|
1409
|
-
operation:
|
|
1410
|
-
status:
|
|
1404
|
+
operation: eOperations.GetResource,
|
|
1405
|
+
status: StatusCodes.NOT_FOUND
|
|
1411
1406
|
}
|
|
1412
1407
|
};
|
|
1413
1408
|
testRecords.push(testObject);
|
|
1414
1409
|
}
|
|
1415
1410
|
else {
|
|
1416
1411
|
const testObject = {
|
|
1417
|
-
status:
|
|
1412
|
+
status: StatusCodes.OK,
|
|
1418
1413
|
detail: null,
|
|
1419
|
-
operation:
|
|
1414
|
+
operation: eOperations.PatchResources,
|
|
1420
1415
|
options: {}
|
|
1421
1416
|
};
|
|
1422
1417
|
testRecords.push(testObject);
|
|
@@ -1428,12 +1423,12 @@ const sort = (a, b) => {
|
|
|
1428
1423
|
testRecords.sort(sort);
|
|
1429
1424
|
if (retVal.length === testRecords.length) {
|
|
1430
1425
|
for (let i = 0; i < retVal.length; i++) {
|
|
1431
|
-
|
|
1426
|
+
expect(retVal[i]).toMatchObject(testRecords[i]);
|
|
1432
1427
|
if (retVal[i].error) {
|
|
1433
1428
|
const patchedResourceRecordError = retVal[i].error;
|
|
1434
1429
|
const resName = retVal[i].options.filters.resname;
|
|
1435
1430
|
finalResults[resName] = patchedResourceRecordError;
|
|
1436
|
-
|
|
1431
|
+
expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
|
|
1437
1432
|
}
|
|
1438
1433
|
else {
|
|
1439
1434
|
const resName = retVal[i].options.filters.resname;
|
|
@@ -1443,10 +1438,10 @@ const sort = (a, b) => {
|
|
|
1443
1438
|
}
|
|
1444
1439
|
}
|
|
1445
1440
|
}, 120000);
|
|
1446
|
-
|
|
1441
|
+
test('Testing Database Resource Batch Delete', async () => {
|
|
1447
1442
|
const deleteStart = 140;
|
|
1448
1443
|
const deleteNum = 5;
|
|
1449
|
-
|
|
1444
|
+
expect.assertions(15);
|
|
1450
1445
|
const resourceParameterPatchRecord = [];
|
|
1451
1446
|
const testRecords = [];
|
|
1452
1447
|
for (let i = deleteStart; i < deleteStart + deleteNum; i++) {
|
|
@@ -1470,16 +1465,16 @@ const sort = (a, b) => {
|
|
|
1470
1465
|
};
|
|
1471
1466
|
resourceParameterPatchRecord.push(resourceParameterRecord);
|
|
1472
1467
|
const testObject = {
|
|
1473
|
-
status:
|
|
1468
|
+
status: StatusCodes.OK,
|
|
1474
1469
|
detail: {
|
|
1475
1470
|
resname: name,
|
|
1476
1471
|
resdesc: userOriginalResourceType,
|
|
1477
1472
|
vnum: "2",
|
|
1478
1473
|
validto: null,
|
|
1479
|
-
dbaction:
|
|
1474
|
+
dbaction: edbaction.deleted,
|
|
1480
1475
|
dbactionuser
|
|
1481
1476
|
},
|
|
1482
|
-
operation:
|
|
1477
|
+
operation: eOperations.DeleteResources,
|
|
1483
1478
|
options: {}
|
|
1484
1479
|
};
|
|
1485
1480
|
testRecords.push(testObject);
|
|
@@ -1490,19 +1485,19 @@ const sort = (a, b) => {
|
|
|
1490
1485
|
testRecords.sort(sort);
|
|
1491
1486
|
if (retVal.length === testRecords.length) {
|
|
1492
1487
|
for (let i = 0; i < retVal.length; i++) {
|
|
1493
|
-
|
|
1488
|
+
expect(retVal[i]).toMatchObject(testRecords[i]);
|
|
1494
1489
|
const deletedResourceRecord = retVal[i].detail;
|
|
1495
1490
|
finalResults[deletedResourceRecord.resname] = deletedResourceRecord;
|
|
1496
|
-
|
|
1497
|
-
|
|
1491
|
+
expect(new Date(deletedResourceRecord.validfrom).getTime()).toBeLessThanOrEqual(new Date().getTime());
|
|
1492
|
+
expect(parseInt(deletedResourceRecord.oid)).toBeGreaterThan(0);
|
|
1498
1493
|
}
|
|
1499
1494
|
}
|
|
1500
1495
|
}, 120000);
|
|
1501
|
-
|
|
1496
|
+
test('Testing Database Resource Batch Delete with Error', async () => {
|
|
1502
1497
|
const deleteErrorStart = 150;
|
|
1503
1498
|
const deleteErrorNum = 5;
|
|
1504
1499
|
const deleteErrorIndex = 152;
|
|
1505
|
-
|
|
1500
|
+
expect.assertions(6);
|
|
1506
1501
|
const resourceParameterPatchRecord = [];
|
|
1507
1502
|
const testRecords = [];
|
|
1508
1503
|
for (let i = deleteErrorStart; i < deleteErrorStart + deleteErrorNum; i++) {
|
|
@@ -1525,22 +1520,22 @@ const sort = (a, b) => {
|
|
|
1525
1520
|
resourceParameterPatchRecord.push(resourceParameterRecord);
|
|
1526
1521
|
if (i === deleteErrorIndex) {
|
|
1527
1522
|
const testObject = {
|
|
1528
|
-
status:
|
|
1523
|
+
status: StatusCodes.NOT_FOUND,
|
|
1529
1524
|
detail: null,
|
|
1530
|
-
operation:
|
|
1525
|
+
operation: eOperations.GetResource,
|
|
1531
1526
|
options: {},
|
|
1532
1527
|
error: {
|
|
1533
|
-
operation:
|
|
1534
|
-
status:
|
|
1528
|
+
operation: eOperations.GetResource,
|
|
1529
|
+
status: StatusCodes.NOT_FOUND
|
|
1535
1530
|
}
|
|
1536
1531
|
};
|
|
1537
1532
|
testRecords.push(testObject);
|
|
1538
1533
|
}
|
|
1539
1534
|
else {
|
|
1540
1535
|
const testObject = {
|
|
1541
|
-
status:
|
|
1536
|
+
status: StatusCodes.OK,
|
|
1542
1537
|
detail: null,
|
|
1543
|
-
operation:
|
|
1538
|
+
operation: eOperations.DeleteResources,
|
|
1544
1539
|
options: {}
|
|
1545
1540
|
};
|
|
1546
1541
|
testRecords.push(testObject);
|
|
@@ -1552,12 +1547,12 @@ const sort = (a, b) => {
|
|
|
1552
1547
|
testRecords.sort(sort);
|
|
1553
1548
|
if (retVal.length === testRecords.length) {
|
|
1554
1549
|
for (let i = 0; i < retVal.length; i++) {
|
|
1555
|
-
|
|
1550
|
+
expect(retVal[i]).toMatchObject(testRecords[i]);
|
|
1556
1551
|
if (retVal[i].error) {
|
|
1557
1552
|
const deletedResourceRecordError = retVal[i].error;
|
|
1558
1553
|
const resName = retVal[i].options.filters.resname;
|
|
1559
1554
|
finalResults[resName] = deletedResourceRecordError;
|
|
1560
|
-
|
|
1555
|
+
expect(retVal[i].error?.errorMessage).toMatch(/\(current version\) not found/);
|
|
1561
1556
|
}
|
|
1562
1557
|
else {
|
|
1563
1558
|
const resName = retVal[i].options.filters.resname;
|
|
@@ -1567,8 +1562,8 @@ const sort = (a, b) => {
|
|
|
1567
1562
|
}
|
|
1568
1563
|
}
|
|
1569
1564
|
}, 120000);
|
|
1570
|
-
|
|
1571
|
-
|
|
1565
|
+
test('Get All user_patch_test_ Resources', async () => {
|
|
1566
|
+
expect.assertions(51);
|
|
1572
1567
|
// All Records
|
|
1573
1568
|
const AllRecords = await accessLayer.GetResources({
|
|
1574
1569
|
filters: {
|
|
@@ -1576,14 +1571,14 @@ const sort = (a, b) => {
|
|
|
1576
1571
|
limit: '50'
|
|
1577
1572
|
}
|
|
1578
1573
|
});
|
|
1579
|
-
|
|
1574
|
+
expect(AllRecords.detail.length).toEqual(50);
|
|
1580
1575
|
AllRecords.detail.forEach(u => {
|
|
1581
1576
|
const compareObject = finalResults[u.resname];
|
|
1582
1577
|
if (compareObject) {
|
|
1583
|
-
|
|
1578
|
+
expect(u).toMatchObject(compareObject);
|
|
1584
1579
|
}
|
|
1585
1580
|
});
|
|
1586
|
-
console.log(
|
|
1581
|
+
console.log(chalk.cyan(`Resource List`));
|
|
1587
1582
|
// Output formatted table
|
|
1588
1583
|
const columns = [
|
|
1589
1584
|
{
|
|
@@ -1621,9 +1616,9 @@ const sort = (a, b) => {
|
|
|
1621
1616
|
console.log(detail);
|
|
1622
1617
|
});
|
|
1623
1618
|
});
|
|
1624
|
-
|
|
1619
|
+
afterAll(async () => {
|
|
1625
1620
|
await accessLayer.EndDatabase();
|
|
1626
|
-
await
|
|
1621
|
+
await JestSleep();
|
|
1627
1622
|
await postgresContainer.stop();
|
|
1628
1623
|
}, 5000);
|
|
1629
1624
|
});
|