@expo/entity-database-adapter-knex 0.38.0 → 0.40.0
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/build/__integration-tests__/PostgresEntityIntegration-test.js +112 -38
- package/build/__integration-tests__/PostgresEntityIntegration-test.js.map +1 -1
- package/build/__integration-tests__/PostgresEntityQueryContextProvider-test.js +14 -7
- package/build/__integration-tests__/PostgresEntityQueryContextProvider-test.js.map +1 -1
- package/build/__integration-tests__/PostgresInvalidSetup-test.js +29 -9
- package/build/__integration-tests__/PostgresInvalidSetup-test.js.map +1 -1
- package/build/__integration-tests__/errors-test.js +24 -12
- package/build/__integration-tests__/errors-test.js.map +1 -1
- package/build/errors/__tests__/wrapNativePostgresCallAsync-test.js +1 -1
- package/build/errors/wrapNativePostgresCallAsync.js +1 -1
- package/build/errors/wrapNativePostgresCallAsync.js.map +1 -1
- package/build/testfixtures/PostgresTriggerTestEntity.js.map +1 -1
- package/build/testfixtures/PostgresValidatorTestEntity.js.map +1 -1
- package/package.json +17 -8
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +120 -38
- package/src/__integration-tests__/PostgresEntityQueryContextProvider-test.ts +14 -7
- package/src/__integration-tests__/PostgresInvalidSetup-test.ts +31 -11
- package/src/__integration-tests__/errors-test.ts +24 -12
- package/src/errors/__tests__/wrapNativePostgresCallAsync-test.ts +1 -1
- package/src/testfixtures/PostgresTriggerTestEntity.ts +4 -4
- package/src/testfixtures/PostgresValidatorTestEntity.ts +2 -2
|
@@ -42,13 +42,16 @@ describe('postgres entity integration', () => {
|
|
|
42
42
|
it('supports parallel partial updates', async () => {
|
|
43
43
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
44
44
|
const entity = await enforceAsyncResult(
|
|
45
|
-
PostgresTestEntity.creator(vc)
|
|
45
|
+
PostgresTestEntity.creator(vc)
|
|
46
|
+
.withAuthorizationResults()
|
|
47
|
+
.setField('name', 'hello')
|
|
48
|
+
.createAsync(),
|
|
46
49
|
);
|
|
47
50
|
|
|
48
51
|
// update two different fields at the same time (from the same entity)
|
|
49
52
|
await Promise.all([
|
|
50
|
-
PostgresTestEntity.updater(entity).setField('hasACat', true).updateAsync(),
|
|
51
|
-
PostgresTestEntity.updater(entity).setField('hasADog', false).updateAsync(),
|
|
53
|
+
PostgresTestEntity.updater(entity).enforcing().setField('hasACat', true).updateAsync(),
|
|
54
|
+
PostgresTestEntity.updater(entity).enforcing().setField('hasADog', false).updateAsync(),
|
|
52
55
|
]);
|
|
53
56
|
|
|
54
57
|
const loadedEntity = await PostgresTestEntity.loader(vc)
|
|
@@ -62,24 +65,32 @@ describe('postgres entity integration', () => {
|
|
|
62
65
|
describe('empty creates and updates', () => {
|
|
63
66
|
it('allows empty create', async () => {
|
|
64
67
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
65
|
-
const entity = await enforceAsyncResult(
|
|
68
|
+
const entity = await enforceAsyncResult(
|
|
69
|
+
PostgresTestEntity.creator(vc).withAuthorizationResults().createAsync(),
|
|
70
|
+
);
|
|
66
71
|
expect(entity.getID()).toBeTruthy();
|
|
67
72
|
});
|
|
68
73
|
|
|
69
74
|
it('throws knex error upon empty update', async () => {
|
|
70
75
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
71
76
|
const entity = await enforceAsyncResult(
|
|
72
|
-
PostgresTestEntity.creator(vc)
|
|
77
|
+
PostgresTestEntity.creator(vc)
|
|
78
|
+
.withAuthorizationResults()
|
|
79
|
+
.setField('name', 'hello')
|
|
80
|
+
.createAsync(),
|
|
73
81
|
);
|
|
74
|
-
await expect(PostgresTestEntity.updater(entity).updateAsync()).rejects.toThrow();
|
|
82
|
+
await expect(PostgresTestEntity.updater(entity).enforcing().updateAsync()).rejects.toThrow();
|
|
75
83
|
});
|
|
76
84
|
|
|
77
85
|
it('throws error upon empty update for stub database adapter to match behavior', async () => {
|
|
78
86
|
const vc = new ViewerContext(createUnitTestEntityCompanionProvider());
|
|
79
87
|
const entity = await enforceAsyncResult(
|
|
80
|
-
PostgresTestEntity.creator(vc)
|
|
88
|
+
PostgresTestEntity.creator(vc)
|
|
89
|
+
.withAuthorizationResults()
|
|
90
|
+
.setField('name', 'hello')
|
|
91
|
+
.createAsync(),
|
|
81
92
|
);
|
|
82
|
-
await expect(PostgresTestEntity.updater(entity).updateAsync()).rejects.toThrow();
|
|
93
|
+
await expect(PostgresTestEntity.updater(entity).enforcing().updateAsync()).rejects.toThrow();
|
|
83
94
|
});
|
|
84
95
|
});
|
|
85
96
|
|
|
@@ -88,7 +99,10 @@ describe('postgres entity integration', () => {
|
|
|
88
99
|
|
|
89
100
|
// put one in the DB
|
|
90
101
|
const firstEntity = await enforceAsyncResult(
|
|
91
|
-
PostgresTestEntity.creator(vc1)
|
|
102
|
+
PostgresTestEntity.creator(vc1)
|
|
103
|
+
.withAuthorizationResults()
|
|
104
|
+
.setField('name', 'hello')
|
|
105
|
+
.createAsync(),
|
|
92
106
|
);
|
|
93
107
|
|
|
94
108
|
await PostgresTestEntity.loader(vc1).enforcing().loadByIDAsync(firstEntity.getID());
|
|
@@ -101,7 +115,10 @@ describe('postgres entity integration', () => {
|
|
|
101
115
|
async (queryContext) => {
|
|
102
116
|
// put another in the DB that will be rolled back due to error thrown
|
|
103
117
|
await enforceAsyncResult(
|
|
104
|
-
PostgresTestEntity.creator(vc1, queryContext)
|
|
118
|
+
PostgresTestEntity.creator(vc1, queryContext)
|
|
119
|
+
.withAuthorizationResults()
|
|
120
|
+
.setField('name', 'hello')
|
|
121
|
+
.createAsync(),
|
|
105
122
|
);
|
|
106
123
|
|
|
107
124
|
throw errorToThrow;
|
|
@@ -125,7 +142,10 @@ describe('postgres entity integration', () => {
|
|
|
125
142
|
);
|
|
126
143
|
|
|
127
144
|
const firstEntity = await enforceAsyncResult(
|
|
128
|
-
PostgresTestEntity.creator(vc1)
|
|
145
|
+
PostgresTestEntity.creator(vc1)
|
|
146
|
+
.withAuthorizationResults()
|
|
147
|
+
.setField('name', 'hello')
|
|
148
|
+
.createAsync(),
|
|
129
149
|
);
|
|
130
150
|
|
|
131
151
|
const loadAndUpdateAsync = async (
|
|
@@ -141,8 +161,9 @@ describe('postgres entity integration', () => {
|
|
|
141
161
|
.loadByIDAsync(firstEntity.getID());
|
|
142
162
|
await setTimeout(delay);
|
|
143
163
|
await PostgresTestEntity.updater(entity, queryContext)
|
|
164
|
+
.enforcing()
|
|
144
165
|
.setField('name', entity.getField('name') + ',' + newName)
|
|
145
|
-
.
|
|
166
|
+
.updateAsync();
|
|
146
167
|
},
|
|
147
168
|
{ isolationLevel },
|
|
148
169
|
);
|
|
@@ -179,6 +200,7 @@ describe('postgres entity integration', () => {
|
|
|
179
200
|
|
|
180
201
|
const entity = await enforceAsyncResult(
|
|
181
202
|
PostgresTestEntity.creator(vc1)
|
|
203
|
+
.withAuthorizationResults()
|
|
182
204
|
.setField('stringArray', ['hello', 'world'])
|
|
183
205
|
.setField('jsonArrayField', ['hello', 'world'])
|
|
184
206
|
.createAsync(),
|
|
@@ -193,6 +215,7 @@ describe('postgres entity integration', () => {
|
|
|
193
215
|
|
|
194
216
|
const entity = await enforceAsyncResult(
|
|
195
217
|
PostgresTestEntity.creator(vc1)
|
|
218
|
+
.withAuthorizationResults()
|
|
196
219
|
.setField('jsonObjectField', { hello: 'world' })
|
|
197
220
|
.createAsync(),
|
|
198
221
|
);
|
|
@@ -205,11 +228,13 @@ describe('postgres entity integration', () => {
|
|
|
205
228
|
|
|
206
229
|
const entity1 = await enforceAsyncResult(
|
|
207
230
|
PostgresTestEntity.creator(vc1)
|
|
231
|
+
.withAuthorizationResults()
|
|
208
232
|
.setField('maybeJsonArrayField', ['hello', 'world'])
|
|
209
233
|
.createAsync(),
|
|
210
234
|
);
|
|
211
235
|
const entity2 = await enforceAsyncResult(
|
|
212
236
|
PostgresTestEntity.creator(vc1)
|
|
237
|
+
.withAuthorizationResults()
|
|
213
238
|
.setField('maybeJsonArrayField', { hello: 'world' })
|
|
214
239
|
.createAsync(),
|
|
215
240
|
);
|
|
@@ -224,17 +249,26 @@ describe('postgres entity integration', () => {
|
|
|
224
249
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
225
250
|
|
|
226
251
|
let entity = await enforceAsyncResult(
|
|
227
|
-
PostgresTestEntity.creator(vc1)
|
|
252
|
+
PostgresTestEntity.creator(vc1)
|
|
253
|
+
.withAuthorizationResults()
|
|
254
|
+
.setField('bigintField', '72057594037928038')
|
|
255
|
+
.createAsync(),
|
|
228
256
|
);
|
|
229
257
|
expect(entity.getField('bigintField')).toEqual('72057594037928038');
|
|
230
258
|
|
|
231
259
|
entity = await enforceAsyncResult(
|
|
232
|
-
PostgresTestEntity.updater(entity)
|
|
260
|
+
PostgresTestEntity.updater(entity)
|
|
261
|
+
.withAuthorizationResults()
|
|
262
|
+
.setField('bigintField', '10')
|
|
263
|
+
.updateAsync(),
|
|
233
264
|
);
|
|
234
265
|
expect(entity.getField('bigintField')).toEqual('10');
|
|
235
266
|
|
|
236
267
|
entity = await enforceAsyncResult(
|
|
237
|
-
PostgresTestEntity.updater(entity)
|
|
268
|
+
PostgresTestEntity.updater(entity)
|
|
269
|
+
.withAuthorizationResults()
|
|
270
|
+
.setField('bigintField', '-10')
|
|
271
|
+
.updateAsync(),
|
|
238
272
|
);
|
|
239
273
|
expect(entity.getField('bigintField')).toEqual('-10');
|
|
240
274
|
});
|
|
@@ -246,6 +280,7 @@ describe('postgres entity integration', () => {
|
|
|
246
280
|
|
|
247
281
|
await enforceAsyncResult(
|
|
248
282
|
PostgresTestEntity.creator(vc1)
|
|
283
|
+
.withAuthorizationResults()
|
|
249
284
|
.setField('name', 'hello')
|
|
250
285
|
.setField('hasACat', false)
|
|
251
286
|
.setField('hasADog', true)
|
|
@@ -254,6 +289,7 @@ describe('postgres entity integration', () => {
|
|
|
254
289
|
|
|
255
290
|
await enforceAsyncResult(
|
|
256
291
|
PostgresTestEntity.creator(vc1)
|
|
292
|
+
.withAuthorizationResults()
|
|
257
293
|
.setField('name', 'world')
|
|
258
294
|
.setField('hasACat', false)
|
|
259
295
|
.setField('hasADog', true)
|
|
@@ -262,6 +298,7 @@ describe('postgres entity integration', () => {
|
|
|
262
298
|
|
|
263
299
|
await enforceAsyncResult(
|
|
264
300
|
PostgresTestEntity.creator(vc1)
|
|
301
|
+
.withAuthorizationResults()
|
|
265
302
|
.setField('name', 'wat')
|
|
266
303
|
.setField('hasACat', false)
|
|
267
304
|
.setField('hasADog', false)
|
|
@@ -294,11 +331,26 @@ describe('postgres entity integration', () => {
|
|
|
294
331
|
it('supports query modifiers', async () => {
|
|
295
332
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
296
333
|
|
|
297
|
-
await enforceAsyncResult(
|
|
334
|
+
await enforceAsyncResult(
|
|
335
|
+
PostgresTestEntity.creator(vc1)
|
|
336
|
+
.withAuthorizationResults()
|
|
337
|
+
.setField('name', 'a')
|
|
338
|
+
.createAsync(),
|
|
339
|
+
);
|
|
298
340
|
|
|
299
|
-
await enforceAsyncResult(
|
|
341
|
+
await enforceAsyncResult(
|
|
342
|
+
PostgresTestEntity.creator(vc1)
|
|
343
|
+
.withAuthorizationResults()
|
|
344
|
+
.setField('name', 'b')
|
|
345
|
+
.createAsync(),
|
|
346
|
+
);
|
|
300
347
|
|
|
301
|
-
await enforceAsyncResult(
|
|
348
|
+
await enforceAsyncResult(
|
|
349
|
+
PostgresTestEntity.creator(vc1)
|
|
350
|
+
.withAuthorizationResults()
|
|
351
|
+
.setField('name', 'c')
|
|
352
|
+
.createAsync(),
|
|
353
|
+
);
|
|
302
354
|
|
|
303
355
|
const results = await PostgresTestEntity.loader(vc1)
|
|
304
356
|
.enforcing()
|
|
@@ -320,24 +372,28 @@ describe('postgres entity integration', () => {
|
|
|
320
372
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
321
373
|
await enforceAsyncResult(
|
|
322
374
|
PostgresTestEntity.creator(vc1)
|
|
375
|
+
.withAuthorizationResults()
|
|
323
376
|
.setField('name', 'a')
|
|
324
377
|
.setField('hasADog', true)
|
|
325
378
|
.createAsync(),
|
|
326
379
|
);
|
|
327
380
|
await enforceAsyncResult(
|
|
328
381
|
PostgresTestEntity.creator(vc1)
|
|
382
|
+
.withAuthorizationResults()
|
|
329
383
|
.setField('name', 'b')
|
|
330
384
|
.setField('hasADog', true)
|
|
331
385
|
.createAsync(),
|
|
332
386
|
);
|
|
333
387
|
await enforceAsyncResult(
|
|
334
388
|
PostgresTestEntity.creator(vc1)
|
|
389
|
+
.withAuthorizationResults()
|
|
335
390
|
.setField('name', null)
|
|
336
391
|
.setField('hasADog', true)
|
|
337
392
|
.createAsync(),
|
|
338
393
|
);
|
|
339
394
|
await enforceAsyncResult(
|
|
340
395
|
PostgresTestEntity.creator(vc1)
|
|
396
|
+
.withAuthorizationResults()
|
|
341
397
|
.setField('name', null)
|
|
342
398
|
.setField('hasADog', false)
|
|
343
399
|
.createAsync(),
|
|
@@ -375,6 +431,7 @@ describe('postgres entity integration', () => {
|
|
|
375
431
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
376
432
|
await enforceAsyncResult(
|
|
377
433
|
PostgresTestEntity.creator(vc1)
|
|
434
|
+
.withAuthorizationResults()
|
|
378
435
|
.setField('name', 'hello')
|
|
379
436
|
.setField('hasACat', false)
|
|
380
437
|
.setField('hasADog', true)
|
|
@@ -392,6 +449,7 @@ describe('postgres entity integration', () => {
|
|
|
392
449
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
393
450
|
await enforceAsyncResult(
|
|
394
451
|
PostgresTestEntity.creator(vc1)
|
|
452
|
+
.withAuthorizationResults()
|
|
395
453
|
.setField('name', 'hello')
|
|
396
454
|
.setField('hasACat', false)
|
|
397
455
|
.setField('hasADog', true)
|
|
@@ -410,6 +468,7 @@ describe('postgres entity integration', () => {
|
|
|
410
468
|
|
|
411
469
|
await enforceAsyncResult(
|
|
412
470
|
PostgresTestEntity.creator(vc1)
|
|
471
|
+
.withAuthorizationResults()
|
|
413
472
|
.setField('name', 'a')
|
|
414
473
|
.setField('hasADog', true)
|
|
415
474
|
.createAsync(),
|
|
@@ -417,6 +476,7 @@ describe('postgres entity integration', () => {
|
|
|
417
476
|
|
|
418
477
|
await enforceAsyncResult(
|
|
419
478
|
PostgresTestEntity.creator(vc1)
|
|
479
|
+
.withAuthorizationResults()
|
|
420
480
|
.setField('name', 'b')
|
|
421
481
|
.setField('hasADog', true)
|
|
422
482
|
.createAsync(),
|
|
@@ -424,6 +484,7 @@ describe('postgres entity integration', () => {
|
|
|
424
484
|
|
|
425
485
|
await enforceAsyncResult(
|
|
426
486
|
PostgresTestEntity.creator(vc1)
|
|
487
|
+
.withAuthorizationResults()
|
|
427
488
|
.setField('name', 'c')
|
|
428
489
|
.setField('hasADog', true)
|
|
429
490
|
.createAsync(),
|
|
@@ -483,8 +544,9 @@ describe('postgres entity integration', () => {
|
|
|
483
544
|
|
|
484
545
|
await expect(
|
|
485
546
|
PostgresTriggerTestEntity.creator(vc1)
|
|
547
|
+
.enforcing()
|
|
486
548
|
.setField('name', 'beforeCreate')
|
|
487
|
-
.
|
|
549
|
+
.createAsync(),
|
|
488
550
|
).rejects.toThrowError('name cannot have value beforeCreate');
|
|
489
551
|
await expect(
|
|
490
552
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -494,8 +556,9 @@ describe('postgres entity integration', () => {
|
|
|
494
556
|
|
|
495
557
|
await expect(
|
|
496
558
|
PostgresTriggerTestEntity.creator(vc1)
|
|
559
|
+
.enforcing()
|
|
497
560
|
.setField('name', 'afterCreate')
|
|
498
|
-
.
|
|
561
|
+
.createAsync(),
|
|
499
562
|
).rejects.toThrowError('name cannot have value afterCreate');
|
|
500
563
|
await expect(
|
|
501
564
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -504,7 +567,10 @@ describe('postgres entity integration', () => {
|
|
|
504
567
|
).resolves.toBeNull();
|
|
505
568
|
|
|
506
569
|
await expect(
|
|
507
|
-
PostgresTriggerTestEntity.creator(vc1)
|
|
570
|
+
PostgresTriggerTestEntity.creator(vc1)
|
|
571
|
+
.enforcing()
|
|
572
|
+
.setField('name', 'beforeAll')
|
|
573
|
+
.createAsync(),
|
|
508
574
|
).rejects.toThrowError('name cannot have value beforeAll');
|
|
509
575
|
await expect(
|
|
510
576
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -513,7 +579,10 @@ describe('postgres entity integration', () => {
|
|
|
513
579
|
).resolves.toBeNull();
|
|
514
580
|
|
|
515
581
|
await expect(
|
|
516
|
-
PostgresTriggerTestEntity.creator(vc1)
|
|
582
|
+
PostgresTriggerTestEntity.creator(vc1)
|
|
583
|
+
.enforcing()
|
|
584
|
+
.setField('name', 'afterAll')
|
|
585
|
+
.createAsync(),
|
|
517
586
|
).rejects.toThrowError('name cannot have value afterAll');
|
|
518
587
|
await expect(
|
|
519
588
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -523,8 +592,9 @@ describe('postgres entity integration', () => {
|
|
|
523
592
|
|
|
524
593
|
await expect(
|
|
525
594
|
PostgresTriggerTestEntity.creator(vc1)
|
|
595
|
+
.enforcing()
|
|
526
596
|
.setField('name', 'afterCommit')
|
|
527
|
-
.
|
|
597
|
+
.createAsync(),
|
|
528
598
|
).rejects.toThrowError('name cannot have value afterCommit');
|
|
529
599
|
await expect(
|
|
530
600
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -541,13 +611,15 @@ describe('postgres entity integration', () => {
|
|
|
541
611
|
);
|
|
542
612
|
|
|
543
613
|
const entity = await PostgresTriggerTestEntity.creator(vc1)
|
|
614
|
+
.enforcing()
|
|
544
615
|
.setField('name', 'blah')
|
|
545
|
-
.
|
|
616
|
+
.createAsync();
|
|
546
617
|
|
|
547
618
|
await expect(
|
|
548
619
|
PostgresTriggerTestEntity.updater(entity)
|
|
620
|
+
.enforcing()
|
|
549
621
|
.setField('name', 'beforeUpdate')
|
|
550
|
-
.
|
|
622
|
+
.updateAsync(),
|
|
551
623
|
).rejects.toThrowError('name cannot have value beforeUpdate');
|
|
552
624
|
await expect(
|
|
553
625
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -557,8 +629,9 @@ describe('postgres entity integration', () => {
|
|
|
557
629
|
|
|
558
630
|
await expect(
|
|
559
631
|
PostgresTriggerTestEntity.updater(entity)
|
|
632
|
+
.enforcing()
|
|
560
633
|
.setField('name', 'afterUpdate')
|
|
561
|
-
.
|
|
634
|
+
.updateAsync(),
|
|
562
635
|
).rejects.toThrowError('name cannot have value afterUpdate');
|
|
563
636
|
await expect(
|
|
564
637
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -568,8 +641,9 @@ describe('postgres entity integration', () => {
|
|
|
568
641
|
|
|
569
642
|
await expect(
|
|
570
643
|
PostgresTriggerTestEntity.updater(entity)
|
|
644
|
+
.enforcing()
|
|
571
645
|
.setField('name', 'beforeAll')
|
|
572
|
-
.
|
|
646
|
+
.updateAsync(),
|
|
573
647
|
).rejects.toThrowError('name cannot have value beforeAll');
|
|
574
648
|
await expect(
|
|
575
649
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -579,8 +653,9 @@ describe('postgres entity integration', () => {
|
|
|
579
653
|
|
|
580
654
|
await expect(
|
|
581
655
|
PostgresTriggerTestEntity.updater(entity)
|
|
656
|
+
.enforcing()
|
|
582
657
|
.setField('name', 'afterAll')
|
|
583
|
-
.
|
|
658
|
+
.updateAsync(),
|
|
584
659
|
).rejects.toThrowError('name cannot have value afterAll');
|
|
585
660
|
await expect(
|
|
586
661
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -590,8 +665,9 @@ describe('postgres entity integration', () => {
|
|
|
590
665
|
|
|
591
666
|
await expect(
|
|
592
667
|
PostgresTriggerTestEntity.updater(entity)
|
|
668
|
+
.enforcing()
|
|
593
669
|
.setField('name', 'afterCommit')
|
|
594
|
-
.
|
|
670
|
+
.updateAsync(),
|
|
595
671
|
).rejects.toThrowError('name cannot have value afterCommit');
|
|
596
672
|
await expect(
|
|
597
673
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -608,10 +684,11 @@ describe('postgres entity integration', () => {
|
|
|
608
684
|
);
|
|
609
685
|
|
|
610
686
|
const entityBeforeDelete = await PostgresTriggerTestEntity.creator(vc1)
|
|
687
|
+
.enforcing()
|
|
611
688
|
.setField('name', 'beforeDelete')
|
|
612
|
-
.
|
|
689
|
+
.createAsync();
|
|
613
690
|
await expect(
|
|
614
|
-
PostgresTriggerTestEntity.
|
|
691
|
+
PostgresTriggerTestEntity.deleter(entityBeforeDelete).enforcing().deleteAsync(),
|
|
615
692
|
).rejects.toThrowError('name cannot have value beforeDelete');
|
|
616
693
|
await expect(
|
|
617
694
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -620,10 +697,11 @@ describe('postgres entity integration', () => {
|
|
|
620
697
|
).resolves.not.toBeNull();
|
|
621
698
|
|
|
622
699
|
const entityAfterDelete = await PostgresTriggerTestEntity.creator(vc1)
|
|
700
|
+
.enforcing()
|
|
623
701
|
.setField('name', 'afterDelete')
|
|
624
|
-
.
|
|
702
|
+
.createAsync();
|
|
625
703
|
await expect(
|
|
626
|
-
PostgresTriggerTestEntity.
|
|
704
|
+
PostgresTriggerTestEntity.deleter(entityAfterDelete).enforcing().deleteAsync(),
|
|
627
705
|
).rejects.toThrowError('name cannot have value afterDelete');
|
|
628
706
|
await expect(
|
|
629
707
|
PostgresTriggerTestEntity.loader(vc1)
|
|
@@ -641,8 +719,9 @@ describe('postgres entity integration', () => {
|
|
|
641
719
|
|
|
642
720
|
await expect(
|
|
643
721
|
PostgresValidatorTestEntity.creator(vc1)
|
|
722
|
+
.enforcing()
|
|
644
723
|
.setField('name', 'beforeCreateAndBeforeUpdate')
|
|
645
|
-
.
|
|
724
|
+
.createAsync(),
|
|
646
725
|
).rejects.toThrowError('name cannot have value beforeCreateAndBeforeUpdate');
|
|
647
726
|
await expect(
|
|
648
727
|
PostgresValidatorTestEntity.loader(vc1)
|
|
@@ -658,13 +737,15 @@ describe('postgres entity integration', () => {
|
|
|
658
737
|
);
|
|
659
738
|
|
|
660
739
|
const entity = await PostgresValidatorTestEntity.creator(vc1)
|
|
740
|
+
.enforcing()
|
|
661
741
|
.setField('name', 'blah')
|
|
662
|
-
.
|
|
742
|
+
.createAsync();
|
|
663
743
|
|
|
664
744
|
await expect(
|
|
665
745
|
PostgresValidatorTestEntity.updater(entity)
|
|
746
|
+
.enforcing()
|
|
666
747
|
.setField('name', 'beforeCreateAndBeforeUpdate')
|
|
667
|
-
.
|
|
748
|
+
.updateAsync(),
|
|
668
749
|
).rejects.toThrowError('name cannot have value beforeCreateAndBeforeUpdate');
|
|
669
750
|
await expect(
|
|
670
751
|
PostgresValidatorTestEntity.loader(vc1)
|
|
@@ -680,9 +761,10 @@ describe('postgres entity integration', () => {
|
|
|
680
761
|
);
|
|
681
762
|
|
|
682
763
|
const entityToDelete = await PostgresValidatorTestEntity.creator(vc1)
|
|
764
|
+
.enforcing()
|
|
683
765
|
.setField('name', 'shouldBeDeleted')
|
|
684
|
-
.
|
|
685
|
-
await PostgresValidatorTestEntity.
|
|
766
|
+
.createAsync();
|
|
767
|
+
await PostgresValidatorTestEntity.deleter(entityToDelete).enforcing().deleteAsync();
|
|
686
768
|
await expect(
|
|
687
769
|
PostgresValidatorTestEntity.loader(vc1)
|
|
688
770
|
.enforcing()
|
|
@@ -34,10 +34,13 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
34
34
|
it('supports nested transactions', async () => {
|
|
35
35
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
36
36
|
|
|
37
|
-
await PostgresUniqueTestEntity.creator(vc1)
|
|
37
|
+
await PostgresUniqueTestEntity.creator(vc1)
|
|
38
|
+
.enforcing()
|
|
39
|
+
.setField('name', 'unique')
|
|
40
|
+
.createAsync();
|
|
38
41
|
|
|
39
42
|
const id = (
|
|
40
|
-
await PostgresUniqueTestEntity.creator(vc1).setField('name', 'wat').
|
|
43
|
+
await PostgresUniqueTestEntity.creator(vc1).enforcing().setField('name', 'wat').createAsync()
|
|
41
44
|
).getID();
|
|
42
45
|
|
|
43
46
|
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', async (queryContext) => {
|
|
@@ -45,8 +48,9 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
45
48
|
.enforcing()
|
|
46
49
|
.loadByIDAsync(id);
|
|
47
50
|
await PostgresUniqueTestEntity.updater(entity, queryContext)
|
|
51
|
+
.enforcing()
|
|
48
52
|
.setField('name', 'wat2')
|
|
49
|
-
.
|
|
53
|
+
.updateAsync();
|
|
50
54
|
|
|
51
55
|
// ensure the outer transaction is not aborted due to postgres error in inner transaction,
|
|
52
56
|
// in this case the error triggered is a unique constraint violation
|
|
@@ -56,8 +60,9 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
56
60
|
.enforcing()
|
|
57
61
|
.loadByIDAsync(id);
|
|
58
62
|
await PostgresUniqueTestEntity.updater(entity, innerQueryContext)
|
|
63
|
+
.enforcing()
|
|
59
64
|
.setField('name', 'unique')
|
|
60
|
-
.
|
|
65
|
+
.updateAsync();
|
|
61
66
|
});
|
|
62
67
|
} catch {}
|
|
63
68
|
|
|
@@ -65,8 +70,9 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
65
70
|
.enforcing()
|
|
66
71
|
.loadByIDAsync(id);
|
|
67
72
|
await PostgresUniqueTestEntity.updater(entity2, queryContext)
|
|
73
|
+
.enforcing()
|
|
68
74
|
.setField('name', 'wat3')
|
|
69
|
-
.
|
|
75
|
+
.updateAsync();
|
|
70
76
|
});
|
|
71
77
|
|
|
72
78
|
const entityLoaded = await PostgresUniqueTestEntity.loader(vc1).enforcing().loadByIDAsync(id);
|
|
@@ -77,7 +83,7 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
77
83
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
78
84
|
|
|
79
85
|
const id = (
|
|
80
|
-
await PostgresUniqueTestEntity.creator(vc1).setField('name', 'wat').
|
|
86
|
+
await PostgresUniqueTestEntity.creator(vc1).enforcing().setField('name', 'wat').createAsync()
|
|
81
87
|
).getID();
|
|
82
88
|
|
|
83
89
|
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', async (queryContext) => {
|
|
@@ -88,8 +94,9 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
88
94
|
.enforcing()
|
|
89
95
|
.loadByIDAsync(id);
|
|
90
96
|
await PostgresUniqueTestEntity.updater(entity, innerQueryContex3)
|
|
97
|
+
.enforcing()
|
|
91
98
|
.setField('name', 'wat3')
|
|
92
|
-
.
|
|
99
|
+
.updateAsync();
|
|
93
100
|
});
|
|
94
101
|
});
|
|
95
102
|
});
|
|
@@ -35,40 +35,60 @@ describe('postgres entity integration', () => {
|
|
|
35
35
|
it('throws after deletion of multiple rows or no rows', async () => {
|
|
36
36
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
37
37
|
const entity1 = await enforceAsyncResult(
|
|
38
|
-
InvalidTestEntity.creator(vc)
|
|
38
|
+
InvalidTestEntity.creator(vc)
|
|
39
|
+
.withAuthorizationResults()
|
|
40
|
+
.setField('id', 1)
|
|
41
|
+
.setField('name', 'hello')
|
|
42
|
+
.createAsync(),
|
|
39
43
|
);
|
|
40
44
|
await enforceAsyncResult(
|
|
41
|
-
InvalidTestEntity.creator(vc)
|
|
45
|
+
InvalidTestEntity.creator(vc)
|
|
46
|
+
.withAuthorizationResults()
|
|
47
|
+
.setField('id', 1)
|
|
48
|
+
.setField('name', 'world')
|
|
49
|
+
.createAsync(),
|
|
42
50
|
);
|
|
43
51
|
|
|
44
|
-
await expect(
|
|
45
|
-
|
|
46
|
-
);
|
|
52
|
+
await expect(
|
|
53
|
+
InvalidTestEntity.deleter(entity1).enforcing().deleteAsync(),
|
|
54
|
+
).rejects.toThrowError('Excessive deletions from database adapter delete');
|
|
47
55
|
});
|
|
48
56
|
|
|
49
57
|
it('throws after update of multiple rows', async () => {
|
|
50
58
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
51
59
|
const entity1 = await enforceAsyncResult(
|
|
52
|
-
InvalidTestEntity.creator(vc)
|
|
60
|
+
InvalidTestEntity.creator(vc)
|
|
61
|
+
.withAuthorizationResults()
|
|
62
|
+
.setField('id', 1)
|
|
63
|
+
.setField('name', 'hello')
|
|
64
|
+
.createAsync(),
|
|
53
65
|
);
|
|
54
66
|
await enforceAsyncResult(
|
|
55
|
-
InvalidTestEntity.creator(vc)
|
|
67
|
+
InvalidTestEntity.creator(vc)
|
|
68
|
+
.withAuthorizationResults()
|
|
69
|
+
.setField('id', 1)
|
|
70
|
+
.setField('name', 'world')
|
|
71
|
+
.createAsync(),
|
|
56
72
|
);
|
|
57
73
|
|
|
58
74
|
await expect(
|
|
59
|
-
InvalidTestEntity.updater(entity1).setField('name', 'blah').
|
|
75
|
+
InvalidTestEntity.updater(entity1).enforcing().setField('name', 'blah').updateAsync(),
|
|
60
76
|
).rejects.toThrowError('Excessive results from database adapter update');
|
|
61
77
|
});
|
|
62
78
|
|
|
63
79
|
it('throws after update of no rows', async () => {
|
|
64
80
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
65
81
|
const entity1 = await enforceAsyncResult(
|
|
66
|
-
InvalidTestEntity.creator(vc)
|
|
82
|
+
InvalidTestEntity.creator(vc)
|
|
83
|
+
.withAuthorizationResults()
|
|
84
|
+
.setField('id', 1)
|
|
85
|
+
.setField('name', 'hello')
|
|
86
|
+
.createAsync(),
|
|
67
87
|
);
|
|
68
|
-
await InvalidTestEntity.
|
|
88
|
+
await InvalidTestEntity.deleter(entity1).enforcing().deleteAsync();
|
|
69
89
|
|
|
70
90
|
await expect(
|
|
71
|
-
InvalidTestEntity.updater(entity1).setField('name', 'blah').
|
|
91
|
+
InvalidTestEntity.updater(entity1).enforcing().setField('name', 'blah').updateAsync(),
|
|
72
92
|
).rejects.toThrowError('Empty results from database adapter update');
|
|
73
93
|
});
|
|
74
94
|
});
|