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