@expo/entity-database-adapter-knex 0.32.0 → 0.34.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 +110 -80
- package/build/__integration-tests__/PostgresEntityIntegration-test.js.map +1 -1
- package/build/__integration-tests__/PostgresEntityQueryContextProvider-test.js +15 -5
- package/build/__integration-tests__/PostgresEntityQueryContextProvider-test.js.map +1 -1
- package/build/__integration-tests__/PostgresInvalidSetup-test.js +28 -9
- package/build/__integration-tests__/PostgresInvalidSetup-test.js.map +1 -1
- package/build/__integration-tests__/errors-test.js +15 -13
- package/build/__integration-tests__/errors-test.js.map +1 -1
- package/package.json +3 -3
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +364 -80
- package/src/__integration-tests__/PostgresEntityQueryContextProvider-test.ts +30 -5
- package/src/__integration-tests__/PostgresInvalidSetup-test.ts +57 -11
- package/src/__integration-tests__/errors-test.ts +56 -15
|
@@ -34,10 +34,20 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
34
34
|
it('supports nested transactions', async () => {
|
|
35
35
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
36
36
|
|
|
37
|
-
await PostgresUniqueTestEntity.creator(
|
|
37
|
+
await PostgresUniqueTestEntity.creator(
|
|
38
|
+
vc1,
|
|
39
|
+
vc1.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
40
|
+
)
|
|
41
|
+
.setField('name', 'unique')
|
|
42
|
+
.enforceCreateAsync();
|
|
38
43
|
|
|
39
44
|
const id = (
|
|
40
|
-
await PostgresUniqueTestEntity.creator(
|
|
45
|
+
await PostgresUniqueTestEntity.creator(
|
|
46
|
+
vc1,
|
|
47
|
+
vc1.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
48
|
+
)
|
|
49
|
+
.setField('name', 'wat')
|
|
50
|
+
.enforceCreateAsync()
|
|
41
51
|
).getID();
|
|
42
52
|
|
|
43
53
|
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', async (queryContext) => {
|
|
@@ -69,7 +79,12 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
69
79
|
.enforceUpdateAsync();
|
|
70
80
|
});
|
|
71
81
|
|
|
72
|
-
const entityLoaded = await PostgresUniqueTestEntity.loader(
|
|
82
|
+
const entityLoaded = await PostgresUniqueTestEntity.loader(
|
|
83
|
+
vc1,
|
|
84
|
+
vc1.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
85
|
+
)
|
|
86
|
+
.enforcing()
|
|
87
|
+
.loadByIDAsync(id);
|
|
73
88
|
expect(entityLoaded.getField('name')).toEqual('wat3');
|
|
74
89
|
});
|
|
75
90
|
|
|
@@ -77,7 +92,12 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
77
92
|
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
78
93
|
|
|
79
94
|
const id = (
|
|
80
|
-
await PostgresUniqueTestEntity.creator(
|
|
95
|
+
await PostgresUniqueTestEntity.creator(
|
|
96
|
+
vc1,
|
|
97
|
+
vc1.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
98
|
+
)
|
|
99
|
+
.setField('name', 'wat')
|
|
100
|
+
.enforceCreateAsync()
|
|
81
101
|
).getID();
|
|
82
102
|
|
|
83
103
|
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', async (queryContext) => {
|
|
@@ -95,7 +115,12 @@ describe(PostgresEntityQueryContextProvider, () => {
|
|
|
95
115
|
});
|
|
96
116
|
});
|
|
97
117
|
|
|
98
|
-
const entityLoaded = await PostgresUniqueTestEntity.loader(
|
|
118
|
+
const entityLoaded = await PostgresUniqueTestEntity.loader(
|
|
119
|
+
vc1,
|
|
120
|
+
vc1.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
121
|
+
)
|
|
122
|
+
.enforcing()
|
|
123
|
+
.loadByIDAsync(id);
|
|
99
124
|
expect(entityLoaded.getField('name')).toEqual('wat3');
|
|
100
125
|
});
|
|
101
126
|
});
|
|
@@ -35,40 +35,86 @@ 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(
|
|
38
|
+
InvalidTestEntity.creator(
|
|
39
|
+
vc,
|
|
40
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
41
|
+
)
|
|
42
|
+
.setField('id', 1)
|
|
43
|
+
.setField('name', 'hello')
|
|
44
|
+
.createAsync()
|
|
39
45
|
);
|
|
40
46
|
await enforceAsyncResult(
|
|
41
|
-
InvalidTestEntity.creator(
|
|
47
|
+
InvalidTestEntity.creator(
|
|
48
|
+
vc,
|
|
49
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
50
|
+
)
|
|
51
|
+
.setField('id', 1)
|
|
52
|
+
.setField('name', 'world')
|
|
53
|
+
.createAsync()
|
|
42
54
|
);
|
|
43
55
|
|
|
44
|
-
await expect(
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
await expect(
|
|
57
|
+
InvalidTestEntity.deleteAsync(
|
|
58
|
+
entity1,
|
|
59
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
60
|
+
)
|
|
61
|
+
).rejects.toThrowError('Excessive deletions from database adapter delete');
|
|
47
62
|
});
|
|
48
63
|
|
|
49
64
|
it('throws after update of multiple rows', async () => {
|
|
50
65
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
51
66
|
const entity1 = await enforceAsyncResult(
|
|
52
|
-
InvalidTestEntity.creator(
|
|
67
|
+
InvalidTestEntity.creator(
|
|
68
|
+
vc,
|
|
69
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
70
|
+
)
|
|
71
|
+
.setField('id', 1)
|
|
72
|
+
.setField('name', 'hello')
|
|
73
|
+
.createAsync()
|
|
53
74
|
);
|
|
54
75
|
await enforceAsyncResult(
|
|
55
|
-
InvalidTestEntity.creator(
|
|
76
|
+
InvalidTestEntity.creator(
|
|
77
|
+
vc,
|
|
78
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
79
|
+
)
|
|
80
|
+
.setField('id', 1)
|
|
81
|
+
.setField('name', 'world')
|
|
82
|
+
.createAsync()
|
|
56
83
|
);
|
|
57
84
|
|
|
58
85
|
await expect(
|
|
59
|
-
InvalidTestEntity.updater(
|
|
86
|
+
InvalidTestEntity.updater(
|
|
87
|
+
entity1,
|
|
88
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
89
|
+
)
|
|
90
|
+
.setField('name', 'blah')
|
|
91
|
+
.enforceUpdateAsync()
|
|
60
92
|
).rejects.toThrowError('Excessive results from database adapter update');
|
|
61
93
|
});
|
|
62
94
|
|
|
63
95
|
it('throws after update of no rows', async () => {
|
|
64
96
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
65
97
|
const entity1 = await enforceAsyncResult(
|
|
66
|
-
InvalidTestEntity.creator(
|
|
98
|
+
InvalidTestEntity.creator(
|
|
99
|
+
vc,
|
|
100
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
101
|
+
)
|
|
102
|
+
.setField('id', 1)
|
|
103
|
+
.setField('name', 'hello')
|
|
104
|
+
.createAsync()
|
|
105
|
+
);
|
|
106
|
+
await InvalidTestEntity.deleteAsync(
|
|
107
|
+
entity1,
|
|
108
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
67
109
|
);
|
|
68
|
-
await InvalidTestEntity.deleteAsync(entity1);
|
|
69
110
|
|
|
70
111
|
await expect(
|
|
71
|
-
InvalidTestEntity.updater(
|
|
112
|
+
InvalidTestEntity.updater(
|
|
113
|
+
entity1,
|
|
114
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
115
|
+
)
|
|
116
|
+
.setField('name', 'blah')
|
|
117
|
+
.enforceUpdateAsync()
|
|
72
118
|
).rejects.toThrowError('Empty results from database adapter update');
|
|
73
119
|
});
|
|
74
120
|
});
|
|
@@ -41,7 +41,10 @@ describe('postgres errors', () => {
|
|
|
41
41
|
|
|
42
42
|
it('throws EntityDatabaseAdapterTransientError on Knex timeout', async () => {
|
|
43
43
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
44
|
-
await ErrorsTestEntity.creator(
|
|
44
|
+
await ErrorsTestEntity.creator(
|
|
45
|
+
vc,
|
|
46
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
47
|
+
)
|
|
45
48
|
.setField('id', 1)
|
|
46
49
|
.setField('fieldNonNull', 'hello')
|
|
47
50
|
.enforceCreateAsync();
|
|
@@ -60,16 +63,24 @@ describe('postgres errors', () => {
|
|
|
60
63
|
const vc2 = new ViewerContext(
|
|
61
64
|
createKnexIntegrationTestEntityCompanionProvider(shortTimeoutKnexInstance)
|
|
62
65
|
);
|
|
63
|
-
await expect(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
await expect(
|
|
67
|
+
ErrorsTestEntity.loader(
|
|
68
|
+
vc2,
|
|
69
|
+
vc2.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
70
|
+
)
|
|
71
|
+
.enforcing()
|
|
72
|
+
.loadByIDAsync(1)
|
|
73
|
+
).rejects.toThrow(EntityDatabaseAdapterTransientError);
|
|
66
74
|
await shortTimeoutKnexInstance.destroy();
|
|
67
75
|
});
|
|
68
76
|
|
|
69
77
|
it('throws EntityDatabaseAdapterNotNullConstraintError when not null is violated', async () => {
|
|
70
78
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
71
79
|
await expect(
|
|
72
|
-
ErrorsTestEntity.creator(
|
|
80
|
+
ErrorsTestEntity.creator(
|
|
81
|
+
vc,
|
|
82
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
83
|
+
)
|
|
73
84
|
.setField('id', 1)
|
|
74
85
|
.setField('fieldNonNull', null as any)
|
|
75
86
|
.enforceCreateAsync()
|
|
@@ -79,7 +90,10 @@ describe('postgres errors', () => {
|
|
|
79
90
|
it('throws EntityDatabaseAdapterForeignKeyConstraintError when foreign key is violated', async () => {
|
|
80
91
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
81
92
|
await expect(
|
|
82
|
-
ErrorsTestEntity.creator(
|
|
93
|
+
ErrorsTestEntity.creator(
|
|
94
|
+
vc,
|
|
95
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
96
|
+
)
|
|
83
97
|
.setField('id', 1)
|
|
84
98
|
.setField('fieldNonNull', 'hello')
|
|
85
99
|
.setField('fieldForeignKey', 2)
|
|
@@ -90,13 +104,19 @@ describe('postgres errors', () => {
|
|
|
90
104
|
it('throws EntityDatabaseAdapterUniqueConstraintError when primary key unique constraint is violated', async () => {
|
|
91
105
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
92
106
|
|
|
93
|
-
await ErrorsTestEntity.creator(
|
|
107
|
+
await ErrorsTestEntity.creator(
|
|
108
|
+
vc,
|
|
109
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
110
|
+
)
|
|
94
111
|
.setField('id', 1)
|
|
95
112
|
.setField('fieldNonNull', 'hello')
|
|
96
113
|
.enforceCreateAsync();
|
|
97
114
|
|
|
98
115
|
await expect(
|
|
99
|
-
ErrorsTestEntity.creator(
|
|
116
|
+
ErrorsTestEntity.creator(
|
|
117
|
+
vc,
|
|
118
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
119
|
+
)
|
|
100
120
|
.setField('id', 1)
|
|
101
121
|
.setField('fieldNonNull', 'hello')
|
|
102
122
|
.enforceCreateAsync()
|
|
@@ -105,14 +125,20 @@ describe('postgres errors', () => {
|
|
|
105
125
|
|
|
106
126
|
it('throws EntityDatabaseAdapterUniqueConstraintError when unique constraint is violated', async () => {
|
|
107
127
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
108
|
-
await ErrorsTestEntity.creator(
|
|
128
|
+
await ErrorsTestEntity.creator(
|
|
129
|
+
vc,
|
|
130
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
131
|
+
)
|
|
109
132
|
.setField('id', 2)
|
|
110
133
|
.setField('fieldNonNull', 'hello')
|
|
111
134
|
.setField('fieldUnique', 'hello')
|
|
112
135
|
.enforceCreateAsync();
|
|
113
136
|
|
|
114
137
|
await expect(
|
|
115
|
-
ErrorsTestEntity.creator(
|
|
138
|
+
ErrorsTestEntity.creator(
|
|
139
|
+
vc,
|
|
140
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
141
|
+
)
|
|
116
142
|
.setField('id', 1)
|
|
117
143
|
.setField('fieldNonNull', 'hello')
|
|
118
144
|
.setField('fieldUnique', 'hello')
|
|
@@ -123,7 +149,10 @@ describe('postgres errors', () => {
|
|
|
123
149
|
it('throws EntityDatabaseAdapterCheckConstraintError when check constraint is violated', async () => {
|
|
124
150
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
125
151
|
await expect(
|
|
126
|
-
ErrorsTestEntity.creator(
|
|
152
|
+
ErrorsTestEntity.creator(
|
|
153
|
+
vc,
|
|
154
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
155
|
+
)
|
|
127
156
|
.setField('id', 1)
|
|
128
157
|
.setField('fieldNonNull', 'hello')
|
|
129
158
|
.setField('checkLessThan5', 2)
|
|
@@ -131,7 +160,10 @@ describe('postgres errors', () => {
|
|
|
131
160
|
).resolves.toBeTruthy();
|
|
132
161
|
|
|
133
162
|
await expect(
|
|
134
|
-
ErrorsTestEntity.creator(
|
|
163
|
+
ErrorsTestEntity.creator(
|
|
164
|
+
vc,
|
|
165
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
166
|
+
)
|
|
135
167
|
.setField('id', 2)
|
|
136
168
|
.setField('fieldNonNull', 'hello')
|
|
137
169
|
.setField('checkLessThan5', 10)
|
|
@@ -142,7 +174,10 @@ describe('postgres errors', () => {
|
|
|
142
174
|
it('throws EntityDatabaseAdapterExclusionConstraintError when exclusion constraint is violated', async () => {
|
|
143
175
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
144
176
|
await expect(
|
|
145
|
-
ErrorsTestEntity.creator(
|
|
177
|
+
ErrorsTestEntity.creator(
|
|
178
|
+
vc,
|
|
179
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
180
|
+
)
|
|
146
181
|
.setField('id', 1)
|
|
147
182
|
.setField('fieldNonNull', 'hello')
|
|
148
183
|
.setField('fieldExclusion', 'what')
|
|
@@ -150,7 +185,10 @@ describe('postgres errors', () => {
|
|
|
150
185
|
).resolves.toBeTruthy();
|
|
151
186
|
|
|
152
187
|
await expect(
|
|
153
|
-
ErrorsTestEntity.creator(
|
|
188
|
+
ErrorsTestEntity.creator(
|
|
189
|
+
vc,
|
|
190
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
191
|
+
)
|
|
154
192
|
.setField('id', 2)
|
|
155
193
|
.setField('fieldNonNull', 'hello')
|
|
156
194
|
.setField('fieldExclusion', 'what')
|
|
@@ -161,7 +199,10 @@ describe('postgres errors', () => {
|
|
|
161
199
|
it('throws EntityDatabaseAdapterUnknownError otherwise', async () => {
|
|
162
200
|
const vc = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
163
201
|
await expect(
|
|
164
|
-
ErrorsTestEntity.creator(
|
|
202
|
+
ErrorsTestEntity.creator(
|
|
203
|
+
vc,
|
|
204
|
+
vc.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres')
|
|
205
|
+
)
|
|
165
206
|
.setField('id', 1)
|
|
166
207
|
.setField('fieldNonNull', 'hello')
|
|
167
208
|
.setField('nonExistentColumn', 'what')
|