@expo/entity-database-adapter-knex 0.40.0 → 0.41.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 +79 -205
- package/build/__integration-tests__/PostgresEntityIntegration-test.js.map +1 -1
- package/build/__integration-tests__/PostgresEntityQueryContextProvider-test.js +9 -24
- package/build/__integration-tests__/PostgresEntityQueryContextProvider-test.js.map +1 -1
- package/build/__integration-tests__/PostgresInvalidSetup-test.js +9 -14
- package/build/__integration-tests__/PostgresInvalidSetup-test.js.map +1 -1
- package/build/__integration-tests__/errors-test.js +1 -13
- package/build/__integration-tests__/errors-test.js.map +1 -1
- package/package.json +3 -3
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +146 -240
- package/src/__integration-tests__/PostgresEntityQueryContextProvider-test.ts +15 -24
- package/src/__integration-tests__/PostgresInvalidSetup-test.ts +11 -16
- package/src/__integration-tests__/errors-test.ts +1 -13
|
@@ -35,82 +35,69 @@ describe('postgres entity integration', () => {
|
|
|
35
35
|
});
|
|
36
36
|
it('supports parallel partial updates', async () => {
|
|
37
37
|
const vc = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
38
|
-
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
39
|
-
.withAuthorizationResults()
|
|
38
|
+
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc)
|
|
40
39
|
.setField('name', 'hello')
|
|
41
40
|
.createAsync());
|
|
42
41
|
// update two different fields at the same time (from the same entity)
|
|
43
42
|
await Promise.all([
|
|
44
|
-
PostgresTestEntity_1.default.updater(entity).
|
|
45
|
-
PostgresTestEntity_1.default.updater(entity).
|
|
43
|
+
PostgresTestEntity_1.default.updater(entity).setField('hasACat', true).updateAsync(),
|
|
44
|
+
PostgresTestEntity_1.default.updater(entity).setField('hasADog', false).updateAsync(),
|
|
46
45
|
]);
|
|
47
|
-
const loadedEntity = await PostgresTestEntity_1.default.loader(vc)
|
|
48
|
-
.enforcing()
|
|
49
|
-
.loadByIDAsync(entity.getID());
|
|
46
|
+
const loadedEntity = await PostgresTestEntity_1.default.loader(vc).loadByIDAsync(entity.getID());
|
|
50
47
|
expect(loadedEntity.getField('hasACat')).toBe(true);
|
|
51
48
|
expect(loadedEntity.getField('hasADog')).toBe(false);
|
|
52
49
|
});
|
|
53
50
|
describe('empty creates and updates', () => {
|
|
54
51
|
it('allows empty create', async () => {
|
|
55
52
|
const vc = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
56
|
-
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
53
|
+
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc).createAsync());
|
|
57
54
|
expect(entity.getID()).toBeTruthy();
|
|
58
55
|
});
|
|
59
56
|
it('throws knex error upon empty update', async () => {
|
|
60
57
|
const vc = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
61
|
-
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
62
|
-
.withAuthorizationResults()
|
|
58
|
+
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc)
|
|
63
59
|
.setField('name', 'hello')
|
|
64
60
|
.createAsync());
|
|
65
|
-
await expect(PostgresTestEntity_1.default.updater(entity).
|
|
61
|
+
await expect(PostgresTestEntity_1.default.updater(entity).updateAsync()).rejects.toThrow();
|
|
66
62
|
});
|
|
67
63
|
it('throws error upon empty update for stub database adapter to match behavior', async () => {
|
|
68
64
|
const vc = new entity_1.ViewerContext((0, entity_1.createUnitTestEntityCompanionProvider)());
|
|
69
|
-
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
70
|
-
.withAuthorizationResults()
|
|
65
|
+
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc)
|
|
71
66
|
.setField('name', 'hello')
|
|
72
67
|
.createAsync());
|
|
73
|
-
await expect(PostgresTestEntity_1.default.updater(entity).
|
|
68
|
+
await expect(PostgresTestEntity_1.default.updater(entity).updateAsync()).rejects.toThrow();
|
|
74
69
|
});
|
|
75
70
|
});
|
|
76
71
|
it('supports transactions', async () => {
|
|
77
72
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
78
73
|
// put one in the DB
|
|
79
|
-
const firstEntity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
80
|
-
.withAuthorizationResults()
|
|
74
|
+
const firstEntity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
81
75
|
.setField('name', 'hello')
|
|
82
76
|
.createAsync());
|
|
83
|
-
await PostgresTestEntity_1.default.loader(vc1).
|
|
77
|
+
await PostgresTestEntity_1.default.loader(vc1).loadByIDAsync(firstEntity.getID());
|
|
84
78
|
const errorToThrow = new Error('Intentional error');
|
|
85
79
|
await expect(vc1.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', async (queryContext) => {
|
|
86
80
|
// put another in the DB that will be rolled back due to error thrown
|
|
87
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
88
|
-
.withAuthorizationResults()
|
|
81
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1, queryContext)
|
|
89
82
|
.setField('name', 'hello')
|
|
90
83
|
.createAsync());
|
|
91
84
|
throw errorToThrow;
|
|
92
85
|
}, {})).rejects.toEqual(errorToThrow);
|
|
93
|
-
const entities = await PostgresTestEntity_1.default.loader(vc1)
|
|
94
|
-
.enforcing()
|
|
95
|
-
.loadManyByFieldEqualingAsync('name', 'hello');
|
|
86
|
+
const entities = await PostgresTestEntity_1.default.loader(vc1).loadManyByFieldEqualingAsync('name', 'hello');
|
|
96
87
|
expect(entities).toHaveLength(1);
|
|
97
88
|
});
|
|
98
89
|
describe('isolation levels', () => {
|
|
99
90
|
test.each(Object.values(entity_1.TransactionIsolationLevel))('isolation level: %p', async (isolationLevel) => {
|
|
100
91
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
101
|
-
const firstEntity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
102
|
-
.withAuthorizationResults()
|
|
92
|
+
const firstEntity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
103
93
|
.setField('name', 'hello')
|
|
104
94
|
.createAsync());
|
|
105
95
|
const loadAndUpdateAsync = async (newName, delay) => {
|
|
106
96
|
try {
|
|
107
97
|
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', async (queryContext) => {
|
|
108
|
-
const entity = await PostgresTestEntity_1.default.loader(vc1, queryContext)
|
|
109
|
-
.enforcing()
|
|
110
|
-
.loadByIDAsync(firstEntity.getID());
|
|
98
|
+
const entity = await PostgresTestEntity_1.default.loader(vc1, queryContext).loadByIDAsync(firstEntity.getID());
|
|
111
99
|
await (0, promises_1.setTimeout)(delay);
|
|
112
100
|
await PostgresTestEntity_1.default.updater(entity, queryContext)
|
|
113
|
-
.enforcing()
|
|
114
101
|
.setField('name', entity.getField('name') + ',' + newName)
|
|
115
102
|
.updateAsync();
|
|
116
103
|
}, { isolationLevel });
|
|
@@ -140,8 +127,7 @@ describe('postgres entity integration', () => {
|
|
|
140
127
|
describe('JSON fields', () => {
|
|
141
128
|
it('supports both types of array fields', async () => {
|
|
142
129
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
143
|
-
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
144
|
-
.withAuthorizationResults()
|
|
130
|
+
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
145
131
|
.setField('stringArray', ['hello', 'world'])
|
|
146
132
|
.setField('jsonArrayField', ['hello', 'world'])
|
|
147
133
|
.createAsync());
|
|
@@ -150,20 +136,17 @@ describe('postgres entity integration', () => {
|
|
|
150
136
|
});
|
|
151
137
|
it('supports object field', async () => {
|
|
152
138
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
153
|
-
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
154
|
-
.withAuthorizationResults()
|
|
139
|
+
const entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
155
140
|
.setField('jsonObjectField', { hello: 'world' })
|
|
156
141
|
.createAsync());
|
|
157
142
|
expect(entity.getField('jsonObjectField')).toEqual({ hello: 'world' });
|
|
158
143
|
});
|
|
159
144
|
it('supports MaybeJSONArray field', async () => {
|
|
160
145
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
161
|
-
const entity1 = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
162
|
-
.withAuthorizationResults()
|
|
146
|
+
const entity1 = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
163
147
|
.setField('maybeJsonArrayField', ['hello', 'world'])
|
|
164
148
|
.createAsync());
|
|
165
|
-
const entity2 = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
166
|
-
.withAuthorizationResults()
|
|
149
|
+
const entity2 = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
167
150
|
.setField('maybeJsonArrayField', { hello: 'world' })
|
|
168
151
|
.createAsync());
|
|
169
152
|
expect(entity1.getField('maybeJsonArrayField')).toEqual(['hello', 'world']);
|
|
@@ -173,18 +156,15 @@ describe('postgres entity integration', () => {
|
|
|
173
156
|
describe('BIGINT fields', () => {
|
|
174
157
|
it('supports BIGINT fields', async () => {
|
|
175
158
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
176
|
-
let entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
177
|
-
.withAuthorizationResults()
|
|
159
|
+
let entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
178
160
|
.setField('bigintField', '72057594037928038')
|
|
179
161
|
.createAsync());
|
|
180
162
|
expect(entity.getField('bigintField')).toEqual('72057594037928038');
|
|
181
|
-
entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
182
|
-
.withAuthorizationResults()
|
|
163
|
+
entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.updaterWithAuthorizationResults(entity)
|
|
183
164
|
.setField('bigintField', '10')
|
|
184
165
|
.updateAsync());
|
|
185
166
|
expect(entity.getField('bigintField')).toEqual('10');
|
|
186
|
-
entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
187
|
-
.withAuthorizationResults()
|
|
167
|
+
entity = await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.updaterWithAuthorizationResults(entity)
|
|
188
168
|
.setField('bigintField', '-10')
|
|
189
169
|
.updateAsync());
|
|
190
170
|
expect(entity.getField('bigintField')).toEqual('-10');
|
|
@@ -193,27 +173,22 @@ describe('postgres entity integration', () => {
|
|
|
193
173
|
describe('conjunction field equality loading', () => {
|
|
194
174
|
it('supports single fieldValue and multiple fieldValues', async () => {
|
|
195
175
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
196
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
197
|
-
.withAuthorizationResults()
|
|
176
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
198
177
|
.setField('name', 'hello')
|
|
199
178
|
.setField('hasACat', false)
|
|
200
179
|
.setField('hasADog', true)
|
|
201
180
|
.createAsync());
|
|
202
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
203
|
-
.withAuthorizationResults()
|
|
181
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
204
182
|
.setField('name', 'world')
|
|
205
183
|
.setField('hasACat', false)
|
|
206
184
|
.setField('hasADog', true)
|
|
207
185
|
.createAsync());
|
|
208
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
209
|
-
.withAuthorizationResults()
|
|
186
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
210
187
|
.setField('name', 'wat')
|
|
211
188
|
.setField('hasACat', false)
|
|
212
189
|
.setField('hasADog', false)
|
|
213
190
|
.createAsync());
|
|
214
|
-
const results = await PostgresTestEntity_1.default.loader(vc1)
|
|
215
|
-
.enforcing()
|
|
216
|
-
.loadManyByFieldEqualityConjunctionAsync([
|
|
191
|
+
const results = await PostgresTestEntity_1.default.loader(vc1).loadManyByFieldEqualityConjunctionAsync([
|
|
217
192
|
{
|
|
218
193
|
fieldName: 'hasACat',
|
|
219
194
|
fieldValue: false,
|
|
@@ -224,30 +199,15 @@ describe('postgres entity integration', () => {
|
|
|
224
199
|
},
|
|
225
200
|
]);
|
|
226
201
|
expect(results).toHaveLength(2);
|
|
227
|
-
const results2 = await PostgresTestEntity_1.default.loader(vc1)
|
|
228
|
-
.enforcing()
|
|
229
|
-
.loadManyByFieldEqualityConjunctionAsync([
|
|
230
|
-
{ fieldName: 'hasADog', fieldValues: [true, false] },
|
|
231
|
-
]);
|
|
202
|
+
const results2 = await PostgresTestEntity_1.default.loader(vc1).loadManyByFieldEqualityConjunctionAsync([{ fieldName: 'hasADog', fieldValues: [true, false] }]);
|
|
232
203
|
expect(results2).toHaveLength(3);
|
|
233
204
|
});
|
|
234
205
|
it('supports query modifiers', async () => {
|
|
235
206
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
236
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creator(vc1)
|
|
241
|
-
.withAuthorizationResults()
|
|
242
|
-
.setField('name', 'b')
|
|
243
|
-
.createAsync());
|
|
244
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creator(vc1)
|
|
245
|
-
.withAuthorizationResults()
|
|
246
|
-
.setField('name', 'c')
|
|
247
|
-
.createAsync());
|
|
248
|
-
const results = await PostgresTestEntity_1.default.loader(vc1)
|
|
249
|
-
.enforcing()
|
|
250
|
-
.loadManyByFieldEqualityConjunctionAsync([], {
|
|
207
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1).setField('name', 'a').createAsync());
|
|
208
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1).setField('name', 'b').createAsync());
|
|
209
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1).setField('name', 'c').createAsync());
|
|
210
|
+
const results = await PostgresTestEntity_1.default.loader(vc1).loadManyByFieldEqualityConjunctionAsync([], {
|
|
251
211
|
limit: 2,
|
|
252
212
|
offset: 1,
|
|
253
213
|
orderBy: [
|
|
@@ -262,34 +222,28 @@ describe('postgres entity integration', () => {
|
|
|
262
222
|
});
|
|
263
223
|
it('supports null field values', async () => {
|
|
264
224
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
265
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
266
|
-
.withAuthorizationResults()
|
|
225
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
267
226
|
.setField('name', 'a')
|
|
268
227
|
.setField('hasADog', true)
|
|
269
228
|
.createAsync());
|
|
270
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
271
|
-
.withAuthorizationResults()
|
|
229
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
272
230
|
.setField('name', 'b')
|
|
273
231
|
.setField('hasADog', true)
|
|
274
232
|
.createAsync());
|
|
275
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
276
|
-
.withAuthorizationResults()
|
|
233
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
277
234
|
.setField('name', null)
|
|
278
235
|
.setField('hasADog', true)
|
|
279
236
|
.createAsync());
|
|
280
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
281
|
-
.withAuthorizationResults()
|
|
237
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
282
238
|
.setField('name', null)
|
|
283
239
|
.setField('hasADog', false)
|
|
284
240
|
.createAsync());
|
|
285
|
-
const results = await PostgresTestEntity_1.default.loader(vc1)
|
|
286
|
-
|
|
287
|
-
|
|
241
|
+
const results = await PostgresTestEntity_1.default.loader(vc1).loadManyByFieldEqualityConjunctionAsync([
|
|
242
|
+
{ fieldName: 'name', fieldValue: null },
|
|
243
|
+
]);
|
|
288
244
|
expect(results).toHaveLength(2);
|
|
289
245
|
expect(results[0].getField('name')).toBeNull();
|
|
290
|
-
const results2 = await PostgresTestEntity_1.default.loader(vc1)
|
|
291
|
-
.enforcing()
|
|
292
|
-
.loadManyByFieldEqualityConjunctionAsync([
|
|
246
|
+
const results2 = await PostgresTestEntity_1.default.loader(vc1).loadManyByFieldEqualityConjunctionAsync([
|
|
293
247
|
{ fieldName: 'name', fieldValues: ['a', null] },
|
|
294
248
|
{ fieldName: 'hasADog', fieldValue: true },
|
|
295
249
|
], {
|
|
@@ -307,49 +261,40 @@ describe('postgres entity integration', () => {
|
|
|
307
261
|
describe('raw where clause loading', () => {
|
|
308
262
|
it('loads by raw where clause', async () => {
|
|
309
263
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
310
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
311
|
-
.withAuthorizationResults()
|
|
264
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
312
265
|
.setField('name', 'hello')
|
|
313
266
|
.setField('hasACat', false)
|
|
314
267
|
.setField('hasADog', true)
|
|
315
268
|
.createAsync());
|
|
316
|
-
const results = await PostgresTestEntity_1.default.loader(vc1)
|
|
317
|
-
.enforcing()
|
|
318
|
-
.loadManyByRawWhereClauseAsync('name = ?', ['hello']);
|
|
269
|
+
const results = await PostgresTestEntity_1.default.loader(vc1).loadManyByRawWhereClauseAsync('name = ?', ['hello']);
|
|
319
270
|
expect(results).toHaveLength(1);
|
|
320
271
|
});
|
|
321
272
|
it('throws with invalid where clause', async () => {
|
|
322
273
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
323
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
324
|
-
.withAuthorizationResults()
|
|
274
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
325
275
|
.setField('name', 'hello')
|
|
326
276
|
.setField('hasACat', false)
|
|
327
277
|
.setField('hasADog', true)
|
|
328
278
|
.createAsync());
|
|
329
|
-
await expect(PostgresTestEntity_1.default.loader(vc1)
|
|
330
|
-
|
|
331
|
-
|
|
279
|
+
await expect(PostgresTestEntity_1.default.loader(vc1).loadManyByRawWhereClauseAsync('invalid_column = ?', [
|
|
280
|
+
'hello',
|
|
281
|
+
])).rejects.toThrow();
|
|
332
282
|
});
|
|
333
283
|
it('supports query modifiers', async () => {
|
|
334
284
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
335
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
336
|
-
.withAuthorizationResults()
|
|
285
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
337
286
|
.setField('name', 'a')
|
|
338
287
|
.setField('hasADog', true)
|
|
339
288
|
.createAsync());
|
|
340
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
341
|
-
.withAuthorizationResults()
|
|
289
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
342
290
|
.setField('name', 'b')
|
|
343
291
|
.setField('hasADog', true)
|
|
344
292
|
.createAsync());
|
|
345
|
-
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.
|
|
346
|
-
.withAuthorizationResults()
|
|
293
|
+
await (0, results_1.enforceAsyncResult)(PostgresTestEntity_1.default.creatorWithAuthorizationResults(vc1)
|
|
347
294
|
.setField('name', 'c')
|
|
348
295
|
.setField('hasADog', true)
|
|
349
296
|
.createAsync());
|
|
350
|
-
const results = await PostgresTestEntity_1.default.loader(vc1)
|
|
351
|
-
.enforcing()
|
|
352
|
-
.loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
|
297
|
+
const results = await PostgresTestEntity_1.default.loader(vc1).loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
|
353
298
|
limit: 2,
|
|
354
299
|
offset: 1,
|
|
355
300
|
orderBy: [
|
|
@@ -361,9 +306,7 @@ describe('postgres entity integration', () => {
|
|
|
361
306
|
});
|
|
362
307
|
expect(results).toHaveLength(2);
|
|
363
308
|
expect(results.map((e) => e.getField('name'))).toEqual(['b', 'c']);
|
|
364
|
-
const resultsMultipleOrderBy = await PostgresTestEntity_1.default.loader(vc1)
|
|
365
|
-
.enforcing()
|
|
366
|
-
.loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
|
309
|
+
const resultsMultipleOrderBy = await PostgresTestEntity_1.default.loader(vc1).loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
|
367
310
|
orderBy: [
|
|
368
311
|
{
|
|
369
312
|
fieldName: 'hasADog',
|
|
@@ -377,9 +320,7 @@ describe('postgres entity integration', () => {
|
|
|
377
320
|
});
|
|
378
321
|
expect(resultsMultipleOrderBy).toHaveLength(3);
|
|
379
322
|
expect(resultsMultipleOrderBy.map((e) => e.getField('name'))).toEqual(['c', 'b', 'a']);
|
|
380
|
-
const resultsOrderByRaw = await PostgresTestEntity_1.default.loader(vc1)
|
|
381
|
-
.enforcing()
|
|
382
|
-
.loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
|
323
|
+
const resultsOrderByRaw = await PostgresTestEntity_1.default.loader(vc1).loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
|
383
324
|
orderByRaw: 'has_a_dog ASC, name DESC',
|
|
384
325
|
});
|
|
385
326
|
expect(resultsOrderByRaw).toHaveLength(3);
|
|
@@ -390,106 +331,49 @@ describe('postgres entity integration', () => {
|
|
|
390
331
|
describe('create', () => {
|
|
391
332
|
it('rolls back transaction when trigger throws except afterCommit', async () => {
|
|
392
333
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
393
|
-
await expect(PostgresTriggerTestEntity_1.default.creator(vc1)
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
await expect(PostgresTriggerTestEntity_1.default.
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
await expect(PostgresTriggerTestEntity_1.default.
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
.createAsync()).rejects.toThrowError('name cannot have value afterCreate');
|
|
404
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
405
|
-
.enforcing()
|
|
406
|
-
.loadByFieldEqualingAsync('name', 'afterCreate')).resolves.toBeNull();
|
|
407
|
-
await expect(PostgresTriggerTestEntity_1.default.creator(vc1)
|
|
408
|
-
.enforcing()
|
|
409
|
-
.setField('name', 'beforeAll')
|
|
410
|
-
.createAsync()).rejects.toThrowError('name cannot have value beforeAll');
|
|
411
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
412
|
-
.enforcing()
|
|
413
|
-
.loadByFieldEqualingAsync('name', 'beforeAll')).resolves.toBeNull();
|
|
414
|
-
await expect(PostgresTriggerTestEntity_1.default.creator(vc1)
|
|
415
|
-
.enforcing()
|
|
416
|
-
.setField('name', 'afterAll')
|
|
417
|
-
.createAsync()).rejects.toThrowError('name cannot have value afterAll');
|
|
418
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
419
|
-
.enforcing()
|
|
420
|
-
.loadByFieldEqualingAsync('name', 'afterAll')).resolves.toBeNull();
|
|
421
|
-
await expect(PostgresTriggerTestEntity_1.default.creator(vc1)
|
|
422
|
-
.enforcing()
|
|
423
|
-
.setField('name', 'afterCommit')
|
|
424
|
-
.createAsync()).rejects.toThrowError('name cannot have value afterCommit');
|
|
425
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
426
|
-
.enforcing()
|
|
427
|
-
.loadByFieldEqualingAsync('name', 'afterCommit')).resolves.not.toBeNull();
|
|
334
|
+
await expect(PostgresTriggerTestEntity_1.default.creator(vc1).setField('name', 'beforeCreate').createAsync()).rejects.toThrowError('name cannot have value beforeCreate');
|
|
335
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'beforeCreate')).resolves.toBeNull();
|
|
336
|
+
await expect(PostgresTriggerTestEntity_1.default.creator(vc1).setField('name', 'afterCreate').createAsync()).rejects.toThrowError('name cannot have value afterCreate');
|
|
337
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'afterCreate')).resolves.toBeNull();
|
|
338
|
+
await expect(PostgresTriggerTestEntity_1.default.creator(vc1).setField('name', 'beforeAll').createAsync()).rejects.toThrowError('name cannot have value beforeAll');
|
|
339
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'beforeAll')).resolves.toBeNull();
|
|
340
|
+
await expect(PostgresTriggerTestEntity_1.default.creator(vc1).setField('name', 'afterAll').createAsync()).rejects.toThrowError('name cannot have value afterAll');
|
|
341
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'afterAll')).resolves.toBeNull();
|
|
342
|
+
await expect(PostgresTriggerTestEntity_1.default.creator(vc1).setField('name', 'afterCommit').createAsync()).rejects.toThrowError('name cannot have value afterCommit');
|
|
343
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'afterCommit')).resolves.not.toBeNull();
|
|
428
344
|
});
|
|
429
345
|
});
|
|
430
346
|
describe('update', () => {
|
|
431
347
|
it('rolls back transaction when trigger throws except afterCommit', async () => {
|
|
432
348
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
433
349
|
const entity = await PostgresTriggerTestEntity_1.default.creator(vc1)
|
|
434
|
-
.enforcing()
|
|
435
350
|
.setField('name', 'blah')
|
|
436
351
|
.createAsync();
|
|
437
|
-
await expect(PostgresTriggerTestEntity_1.default.updater(entity)
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
await expect(PostgresTriggerTestEntity_1.default.
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
await expect(PostgresTriggerTestEntity_1.default.
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
.updateAsync()).rejects.toThrowError('name cannot have value afterUpdate');
|
|
448
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
449
|
-
.enforcing()
|
|
450
|
-
.loadByFieldEqualingAsync('name', 'afterUpdate')).resolves.toBeNull();
|
|
451
|
-
await expect(PostgresTriggerTestEntity_1.default.updater(entity)
|
|
452
|
-
.enforcing()
|
|
453
|
-
.setField('name', 'beforeAll')
|
|
454
|
-
.updateAsync()).rejects.toThrowError('name cannot have value beforeAll');
|
|
455
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
456
|
-
.enforcing()
|
|
457
|
-
.loadByFieldEqualingAsync('name', 'beforeAll')).resolves.toBeNull();
|
|
458
|
-
await expect(PostgresTriggerTestEntity_1.default.updater(entity)
|
|
459
|
-
.enforcing()
|
|
460
|
-
.setField('name', 'afterAll')
|
|
461
|
-
.updateAsync()).rejects.toThrowError('name cannot have value afterAll');
|
|
462
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
463
|
-
.enforcing()
|
|
464
|
-
.loadByFieldEqualingAsync('name', 'afterAll')).resolves.toBeNull();
|
|
465
|
-
await expect(PostgresTriggerTestEntity_1.default.updater(entity)
|
|
466
|
-
.enforcing()
|
|
467
|
-
.setField('name', 'afterCommit')
|
|
468
|
-
.updateAsync()).rejects.toThrowError('name cannot have value afterCommit');
|
|
469
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
470
|
-
.enforcing()
|
|
471
|
-
.loadByFieldEqualingAsync('name', 'afterCommit')).resolves.not.toBeNull();
|
|
352
|
+
await expect(PostgresTriggerTestEntity_1.default.updater(entity).setField('name', 'beforeUpdate').updateAsync()).rejects.toThrowError('name cannot have value beforeUpdate');
|
|
353
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'beforeUpdate')).resolves.toBeNull();
|
|
354
|
+
await expect(PostgresTriggerTestEntity_1.default.updater(entity).setField('name', 'afterUpdate').updateAsync()).rejects.toThrowError('name cannot have value afterUpdate');
|
|
355
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'afterUpdate')).resolves.toBeNull();
|
|
356
|
+
await expect(PostgresTriggerTestEntity_1.default.updater(entity).setField('name', 'beforeAll').updateAsync()).rejects.toThrowError('name cannot have value beforeAll');
|
|
357
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'beforeAll')).resolves.toBeNull();
|
|
358
|
+
await expect(PostgresTriggerTestEntity_1.default.updater(entity).setField('name', 'afterAll').updateAsync()).rejects.toThrowError('name cannot have value afterAll');
|
|
359
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'afterAll')).resolves.toBeNull();
|
|
360
|
+
await expect(PostgresTriggerTestEntity_1.default.updater(entity).setField('name', 'afterCommit').updateAsync()).rejects.toThrowError('name cannot have value afterCommit');
|
|
361
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'afterCommit')).resolves.not.toBeNull();
|
|
472
362
|
});
|
|
473
363
|
});
|
|
474
364
|
describe('delete', () => {
|
|
475
365
|
it('rolls back transaction when trigger throws except afterCommit', async () => {
|
|
476
366
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
477
367
|
const entityBeforeDelete = await PostgresTriggerTestEntity_1.default.creator(vc1)
|
|
478
|
-
.enforcing()
|
|
479
368
|
.setField('name', 'beforeDelete')
|
|
480
369
|
.createAsync();
|
|
481
|
-
await expect(PostgresTriggerTestEntity_1.default.deleter(entityBeforeDelete).
|
|
482
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
483
|
-
.enforcing()
|
|
484
|
-
.loadByFieldEqualingAsync('name', 'beforeDelete')).resolves.not.toBeNull();
|
|
370
|
+
await expect(PostgresTriggerTestEntity_1.default.deleter(entityBeforeDelete).deleteAsync()).rejects.toThrowError('name cannot have value beforeDelete');
|
|
371
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'beforeDelete')).resolves.not.toBeNull();
|
|
485
372
|
const entityAfterDelete = await PostgresTriggerTestEntity_1.default.creator(vc1)
|
|
486
|
-
.enforcing()
|
|
487
373
|
.setField('name', 'afterDelete')
|
|
488
374
|
.createAsync();
|
|
489
|
-
await expect(PostgresTriggerTestEntity_1.default.deleter(entityAfterDelete).
|
|
490
|
-
await expect(PostgresTriggerTestEntity_1.default.loader(vc1)
|
|
491
|
-
.enforcing()
|
|
492
|
-
.loadByFieldEqualingAsync('name', 'afterDelete')).resolves.not.toBeNull();
|
|
375
|
+
await expect(PostgresTriggerTestEntity_1.default.deleter(entityAfterDelete).deleteAsync()).rejects.toThrowError('name cannot have value afterDelete');
|
|
376
|
+
await expect(PostgresTriggerTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'afterDelete')).resolves.not.toBeNull();
|
|
493
377
|
});
|
|
494
378
|
});
|
|
495
379
|
describe('validation transaction behavior', () => {
|
|
@@ -497,41 +381,31 @@ describe('postgres entity integration', () => {
|
|
|
497
381
|
it('rolls back transaction when trigger throws ', async () => {
|
|
498
382
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
499
383
|
await expect(PostgresValidatorTestEntity_1.default.creator(vc1)
|
|
500
|
-
.enforcing()
|
|
501
384
|
.setField('name', 'beforeCreateAndBeforeUpdate')
|
|
502
385
|
.createAsync()).rejects.toThrowError('name cannot have value beforeCreateAndBeforeUpdate');
|
|
503
|
-
await expect(PostgresValidatorTestEntity_1.default.loader(vc1)
|
|
504
|
-
.enforcing()
|
|
505
|
-
.loadByFieldEqualingAsync('name', 'beforeCreateAndBeforeUpdate')).resolves.toBeNull();
|
|
386
|
+
await expect(PostgresValidatorTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'beforeCreateAndBeforeUpdate')).resolves.toBeNull();
|
|
506
387
|
});
|
|
507
388
|
});
|
|
508
389
|
describe('update', () => {
|
|
509
390
|
it('rolls back transaction when trigger throws ', async () => {
|
|
510
391
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
511
392
|
const entity = await PostgresValidatorTestEntity_1.default.creator(vc1)
|
|
512
|
-
.enforcing()
|
|
513
393
|
.setField('name', 'blah')
|
|
514
394
|
.createAsync();
|
|
515
395
|
await expect(PostgresValidatorTestEntity_1.default.updater(entity)
|
|
516
|
-
.enforcing()
|
|
517
396
|
.setField('name', 'beforeCreateAndBeforeUpdate')
|
|
518
397
|
.updateAsync()).rejects.toThrowError('name cannot have value beforeCreateAndBeforeUpdate');
|
|
519
|
-
await expect(PostgresValidatorTestEntity_1.default.loader(vc1)
|
|
520
|
-
.enforcing()
|
|
521
|
-
.loadByFieldEqualingAsync('name', 'beforeCreateAndBeforeUpdate')).resolves.toBeNull();
|
|
398
|
+
await expect(PostgresValidatorTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'beforeCreateAndBeforeUpdate')).resolves.toBeNull();
|
|
522
399
|
});
|
|
523
400
|
});
|
|
524
401
|
describe('delete', () => {
|
|
525
402
|
it('validation should not run on a delete mutation', async () => {
|
|
526
403
|
const vc1 = new entity_1.ViewerContext((0, createKnexIntegrationTestEntityCompanionProvider_1.createKnexIntegrationTestEntityCompanionProvider)(knexInstance));
|
|
527
404
|
const entityToDelete = await PostgresValidatorTestEntity_1.default.creator(vc1)
|
|
528
|
-
.enforcing()
|
|
529
405
|
.setField('name', 'shouldBeDeleted')
|
|
530
406
|
.createAsync();
|
|
531
|
-
await PostgresValidatorTestEntity_1.default.deleter(entityToDelete).
|
|
532
|
-
await expect(PostgresValidatorTestEntity_1.default.loader(vc1)
|
|
533
|
-
.enforcing()
|
|
534
|
-
.loadByFieldEqualingAsync('name', 'shouldBeDeleted')).resolves.toBeNull();
|
|
407
|
+
await PostgresValidatorTestEntity_1.default.deleter(entityToDelete).deleteAsync();
|
|
408
|
+
await expect(PostgresValidatorTestEntity_1.default.loader(vc1).loadByFieldEqualingAsync('name', 'shouldBeDeleted')).resolves.toBeNull();
|
|
535
409
|
});
|
|
536
410
|
});
|
|
537
411
|
});
|