@expo/entity 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/AuthorizationResultBasedEntityAssociationLoader.js +2 -4
- package/build/AuthorizationResultBasedEntityAssociationLoader.js.map +1 -1
- package/build/Entity.d.ts +28 -6
- package/build/Entity.js +41 -3
- package/build/Entity.js.map +1 -1
- package/build/ReadonlyEntity.d.ts +24 -5
- package/build/ReadonlyEntity.js +31 -3
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js +37 -68
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/Entity-test.js +49 -9
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +4 -4
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +9 -17
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +32 -64
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +3 -3
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +4 -8
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +6 -6
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +35 -81
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +39 -6
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +4 -10
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +7 -22
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/utils/__tests__/EntityPrivacyUtils-test.js +13 -47
- package/build/utils/__tests__/EntityPrivacyUtils-test.js.map +1 -1
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js +2 -5
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js.map +1 -1
- package/package.json +2 -2
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +2 -4
- package/src/Entity.ts +163 -7
- package/src/ReadonlyEntity.ts +119 -6
- package/src/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.ts +37 -68
- package/src/__tests__/Entity-test.ts +62 -9
- package/src/__tests__/EntityAssociationLoader-test.ts +4 -6
- package/src/__tests__/EntityCommonUseCases-test.ts +14 -17
- package/src/__tests__/EntityEdges-test.ts +36 -64
- package/src/__tests__/EntityLoader-test.ts +3 -5
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +6 -8
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +6 -6
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +53 -81
- package/src/__tests__/ReadonlyEntity-test.ts +46 -6
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +13 -15
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +16 -22
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +19 -47
- package/src/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.ts +2 -5
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { instance, mock } from 'ts-mockito';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import AuthorizationResultBasedEntityAssociationLoader from '../AuthorizationResultBasedEntityAssociationLoader';
|
|
4
|
+
import AuthorizationResultBasedEntityLoader from '../AuthorizationResultBasedEntityLoader';
|
|
5
|
+
import EnforcingEntityAssociationLoader from '../EnforcingEntityAssociationLoader';
|
|
6
|
+
import EnforcingEntityLoader from '../EnforcingEntityLoader';
|
|
7
|
+
import EntityLoaderUtils from '../EntityLoaderUtils';
|
|
5
8
|
import ReadonlyEntity from '../ReadonlyEntity';
|
|
6
9
|
import ViewerContext from '../ViewerContext';
|
|
7
10
|
import SimpleTestEntity from '../testfixtures/SimpleTestEntity';
|
|
@@ -157,7 +160,7 @@ describe(ReadonlyEntity, () => {
|
|
|
157
160
|
});
|
|
158
161
|
|
|
159
162
|
describe('associationLoader', () => {
|
|
160
|
-
it('returns a new
|
|
163
|
+
it('returns a new EnforcingEntityAssociationLoader', () => {
|
|
161
164
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
162
165
|
const viewerContext = new ViewerContext(companionProvider);
|
|
163
166
|
const data = {
|
|
@@ -169,15 +172,52 @@ describe(ReadonlyEntity, () => {
|
|
|
169
172
|
databaseFields: data,
|
|
170
173
|
selectedFields: data,
|
|
171
174
|
});
|
|
172
|
-
expect(testEntity.associationLoader()).toBeInstanceOf(
|
|
175
|
+
expect(testEntity.associationLoader()).toBeInstanceOf(EnforcingEntityAssociationLoader);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('associationLoaderWithAuthorizationResults', () => {
|
|
180
|
+
it('returns a new AuthorizationResultBasedEntityAssociationLoader', () => {
|
|
181
|
+
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
182
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
183
|
+
const data = {
|
|
184
|
+
id: 'what',
|
|
185
|
+
};
|
|
186
|
+
const testEntity = new SimpleTestEntity({
|
|
187
|
+
viewerContext,
|
|
188
|
+
id: 'what',
|
|
189
|
+
databaseFields: data,
|
|
190
|
+
selectedFields: data,
|
|
191
|
+
});
|
|
192
|
+
expect(testEntity.associationLoaderWithAuthorizationResults()).toBeInstanceOf(
|
|
193
|
+
AuthorizationResultBasedEntityAssociationLoader,
|
|
194
|
+
);
|
|
173
195
|
});
|
|
174
196
|
});
|
|
175
197
|
|
|
176
198
|
describe('loader', () => {
|
|
177
|
-
it('creates a new
|
|
199
|
+
it('creates a new EnforcingEntityLoader', async () => {
|
|
200
|
+
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
201
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
202
|
+
expect(SimpleTestEntity.loader(viewerContext)).toBeInstanceOf(EnforcingEntityLoader);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('loaderWithAuthorizationResults', () => {
|
|
207
|
+
it('creates a new AuthorizationResultBasedEntityLoader', async () => {
|
|
208
|
+
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
209
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
210
|
+
expect(SimpleTestEntity.loaderWithAuthorizationResults(viewerContext)).toBeInstanceOf(
|
|
211
|
+
AuthorizationResultBasedEntityLoader,
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('loaderUtils', () => {
|
|
217
|
+
it('creates a new EntityLoaderUtils', async () => {
|
|
178
218
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
179
219
|
const viewerContext = new ViewerContext(companionProvider);
|
|
180
|
-
expect(SimpleTestEntity.
|
|
220
|
+
expect(SimpleTestEntity.loaderUtils(viewerContext)).toBeInstanceOf(EntityLoaderUtils);
|
|
181
221
|
});
|
|
182
222
|
});
|
|
183
223
|
});
|
|
@@ -14,13 +14,11 @@ describe('Two entities backed by the same table', () => {
|
|
|
14
14
|
const viewerContext = new ViewerContext(companionProvider);
|
|
15
15
|
|
|
16
16
|
const one = await OneTestEntity.creator(viewerContext)
|
|
17
|
-
.enforcing()
|
|
18
17
|
.setField('entity_type', EntityType.ONE)
|
|
19
18
|
.setField('common_other_field', 'wat')
|
|
20
19
|
.createAsync();
|
|
21
20
|
|
|
22
21
|
const two = await TwoTestEntity.creator(viewerContext)
|
|
23
|
-
.enforcing()
|
|
24
22
|
.setField('entity_type', EntityType.TWO)
|
|
25
23
|
.setField('other_field', 'blah')
|
|
26
24
|
.setField('common_other_field', 'wat')
|
|
@@ -30,16 +28,16 @@ describe('Two entities backed by the same table', () => {
|
|
|
30
28
|
expect(two).toBeInstanceOf(TwoTestEntity);
|
|
31
29
|
|
|
32
30
|
await expect(
|
|
33
|
-
TwoTestEntity.loader(viewerContext).
|
|
31
|
+
TwoTestEntity.loader(viewerContext).loadByIDAsync(one.getID()),
|
|
34
32
|
).rejects.toThrowError('TwoTestEntity must be instantiated with two data');
|
|
35
33
|
|
|
36
34
|
await expect(
|
|
37
|
-
OneTestEntity.loader(viewerContext).
|
|
35
|
+
OneTestEntity.loader(viewerContext).loadByIDAsync(two.getID()),
|
|
38
36
|
).rejects.toThrowError('OneTestEntity must be instantiated with one data');
|
|
39
37
|
|
|
40
|
-
const manyResults = await OneTestEntity.
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const manyResults = await OneTestEntity.loaderWithAuthorizationResults(
|
|
39
|
+
viewerContext,
|
|
40
|
+
).loadManyByFieldEqualingAsync('common_other_field', 'wat');
|
|
43
41
|
const successfulManyResults = successfulResults(manyResults);
|
|
44
42
|
const failedManyResults = failedResults(manyResults);
|
|
45
43
|
|
|
@@ -51,14 +49,14 @@ describe('Two entities backed by the same table', () => {
|
|
|
51
49
|
'OneTestEntity must be instantiated with one data',
|
|
52
50
|
);
|
|
53
51
|
|
|
54
|
-
const fieldEqualityConjunctionResults = await OneTestEntity.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
const fieldEqualityConjunctionResults = await OneTestEntity.loaderWithAuthorizationResults(
|
|
53
|
+
viewerContext,
|
|
54
|
+
).loadManyByFieldEqualityConjunctionAsync([
|
|
55
|
+
{
|
|
56
|
+
fieldName: 'common_other_field',
|
|
57
|
+
fieldValue: 'wat',
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
62
60
|
const successfulfieldEqualityConjunctionResultsResults = successfulResults(
|
|
63
61
|
fieldEqualityConjunctionResults,
|
|
64
62
|
);
|
|
@@ -13,18 +13,14 @@ describe('Two entities backed by the same table', () => {
|
|
|
13
13
|
const viewerContext = new ViewerContext(companionProvider);
|
|
14
14
|
|
|
15
15
|
const entity1 = await OneTestEntity.creator(viewerContext)
|
|
16
|
-
.enforcing()
|
|
17
16
|
.setField('fake_field', 'hello')
|
|
18
17
|
.createAsync();
|
|
19
18
|
expect(entity1).toBeInstanceOf(OneTestEntity);
|
|
20
19
|
|
|
21
|
-
const entity2 = await TwoTestEntity.loader(viewerContext)
|
|
22
|
-
.enforcing()
|
|
23
|
-
.loadByIDAsync(entity1.getID());
|
|
20
|
+
const entity2 = await TwoTestEntity.loader(viewerContext).loadByIDAsync(entity1.getID());
|
|
24
21
|
expect(entity2).toBeInstanceOf(TwoTestEntity);
|
|
25
22
|
|
|
26
23
|
const updated2 = await TwoTestEntity.updater(entity2)
|
|
27
|
-
.enforcing()
|
|
28
24
|
.setField('fake_field', 'world')
|
|
29
25
|
.setField('other_field', 'wat')
|
|
30
26
|
.updateAsync();
|
|
@@ -34,9 +30,7 @@ describe('Two entities backed by the same table', () => {
|
|
|
34
30
|
fake_field: 'world',
|
|
35
31
|
});
|
|
36
32
|
|
|
37
|
-
const loaded1 = await OneTestEntity.loader(viewerContext)
|
|
38
|
-
.enforcing()
|
|
39
|
-
.loadByIDAsync(entity1.getID());
|
|
33
|
+
const loaded1 = await OneTestEntity.loader(viewerContext).loadByIDAsync(entity1.getID());
|
|
40
34
|
expect(loaded1.getAllFields()).toMatchObject({
|
|
41
35
|
id: updated2.getID(),
|
|
42
36
|
fake_field: 'world',
|
|
@@ -48,37 +42,37 @@ describe('Two entities backed by the same table', () => {
|
|
|
48
42
|
const viewerContext = new ViewerContext(companionProvider);
|
|
49
43
|
|
|
50
44
|
const entity = await TwoTestEntity.creator(viewerContext)
|
|
51
|
-
.enforcing()
|
|
52
45
|
.setField('fake_field', 'hello')
|
|
53
46
|
.setField('other_field', 'huh')
|
|
54
47
|
.createAsync();
|
|
55
48
|
|
|
56
|
-
const loadedEntity = await TwoTestEntity.loader(viewerContext)
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const loadedEntity = await TwoTestEntity.loader(viewerContext).loadByFieldEqualingAsync(
|
|
50
|
+
'other_field',
|
|
51
|
+
'huh',
|
|
52
|
+
);
|
|
59
53
|
expect(loadedEntity?.getAllFields()).toMatchObject({
|
|
60
54
|
id: entity.getID(),
|
|
61
55
|
fake_field: 'hello',
|
|
62
56
|
other_field: 'huh',
|
|
63
57
|
});
|
|
64
58
|
|
|
65
|
-
const loaded1 = await OneTestEntity.loader(viewerContext)
|
|
66
|
-
|
|
67
|
-
.loadByIDAsync(entity.getID());
|
|
68
|
-
await OneTestEntity.updater(loaded1).enforcing().setField('fake_field', 'world').updateAsync();
|
|
59
|
+
const loaded1 = await OneTestEntity.loader(viewerContext).loadByIDAsync(entity.getID());
|
|
60
|
+
await OneTestEntity.updater(loaded1).setField('fake_field', 'world').updateAsync();
|
|
69
61
|
|
|
70
|
-
const loaded2 = await TwoTestEntity.loader(viewerContext)
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
const loaded2 = await TwoTestEntity.loader(viewerContext).loadByFieldEqualingAsync(
|
|
63
|
+
'other_field',
|
|
64
|
+
'huh',
|
|
65
|
+
);
|
|
73
66
|
expect(loaded2?.getAllFields()).toMatchObject({
|
|
74
67
|
id: entity.getID(),
|
|
75
68
|
fake_field: 'world',
|
|
76
69
|
other_field: 'huh',
|
|
77
70
|
});
|
|
78
71
|
|
|
79
|
-
const loaded22 = await TwoTestEntity.loader(viewerContext)
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
const loaded22 = await TwoTestEntity.loader(viewerContext).loadByFieldEqualingAsync(
|
|
73
|
+
'fake_field',
|
|
74
|
+
'world',
|
|
75
|
+
);
|
|
82
76
|
expect(loaded22?.getAllFields()).toMatchObject({
|
|
83
77
|
id: entity.getID(),
|
|
84
78
|
fake_field: 'world',
|
|
@@ -50,9 +50,7 @@ describe(canViewerUpdateAsync, () => {
|
|
|
50
50
|
it('appropriately executes update privacy policy', async () => {
|
|
51
51
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
52
52
|
const viewerContext = new ViewerContext(companionProvider);
|
|
53
|
-
const testEntity = await SimpleTestDenyDeleteEntity.creator(viewerContext)
|
|
54
|
-
.enforcing()
|
|
55
|
-
.createAsync();
|
|
53
|
+
const testEntity = await SimpleTestDenyDeleteEntity.creator(viewerContext).createAsync();
|
|
56
54
|
const canViewerUpdate = await canViewerUpdateAsync(SimpleTestDenyDeleteEntity, testEntity);
|
|
57
55
|
expect(canViewerUpdate).toBe(true);
|
|
58
56
|
const canViewerUpdateResult = await getCanViewerUpdateResultAsync(
|
|
@@ -65,9 +63,7 @@ describe(canViewerUpdateAsync, () => {
|
|
|
65
63
|
it('denies when policy denies', async () => {
|
|
66
64
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
67
65
|
const viewerContext = new ViewerContext(companionProvider);
|
|
68
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext)
|
|
69
|
-
.enforcing()
|
|
70
|
-
.createAsync();
|
|
66
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext).createAsync();
|
|
71
67
|
const canViewerUpdate = await canViewerUpdateAsync(SimpleTestDenyUpdateEntity, testEntity);
|
|
72
68
|
expect(canViewerUpdate).toBe(false);
|
|
73
69
|
const canViewerUpdateResult = await getCanViewerUpdateResultAsync(
|
|
@@ -83,9 +79,7 @@ describe(canViewerUpdateAsync, () => {
|
|
|
83
79
|
it('rethrows non-authorization errors', async () => {
|
|
84
80
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
85
81
|
const viewerContext = new ViewerContext(companionProvider);
|
|
86
|
-
const testEntity = await SimpleTestThrowOtherErrorEntity.creator(viewerContext)
|
|
87
|
-
.enforcing()
|
|
88
|
-
.createAsync();
|
|
82
|
+
const testEntity = await SimpleTestThrowOtherErrorEntity.creator(viewerContext).createAsync();
|
|
89
83
|
await expect(canViewerUpdateAsync(SimpleTestThrowOtherErrorEntity, testEntity)).rejects.toThrow(
|
|
90
84
|
'update error',
|
|
91
85
|
);
|
|
@@ -99,9 +93,7 @@ describe(canViewerDeleteAsync, () => {
|
|
|
99
93
|
it('appropriately executes update privacy policy', async () => {
|
|
100
94
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
101
95
|
const viewerContext = new ViewerContext(companionProvider);
|
|
102
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext)
|
|
103
|
-
.enforcing()
|
|
104
|
-
.createAsync();
|
|
96
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext).createAsync();
|
|
105
97
|
const canViewerDelete = await canViewerDeleteAsync(SimpleTestDenyUpdateEntity, testEntity);
|
|
106
98
|
expect(canViewerDelete).toBe(true);
|
|
107
99
|
const canViewerDeleteResult = await getCanViewerDeleteResultAsync(
|
|
@@ -114,9 +106,7 @@ describe(canViewerDeleteAsync, () => {
|
|
|
114
106
|
it('denies when policy denies', async () => {
|
|
115
107
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
116
108
|
const viewerContext = new ViewerContext(companionProvider);
|
|
117
|
-
const testEntity = await SimpleTestDenyDeleteEntity.creator(viewerContext)
|
|
118
|
-
.enforcing()
|
|
119
|
-
.createAsync();
|
|
109
|
+
const testEntity = await SimpleTestDenyDeleteEntity.creator(viewerContext).createAsync();
|
|
120
110
|
const canViewerDelete = await canViewerDeleteAsync(SimpleTestDenyDeleteEntity, testEntity);
|
|
121
111
|
expect(canViewerDelete).toBe(false);
|
|
122
112
|
const canViewerDeleteResult = await getCanViewerDeleteResultAsync(
|
|
@@ -132,12 +122,9 @@ describe(canViewerDeleteAsync, () => {
|
|
|
132
122
|
it('denies when recursive policy denies for CASCADE_DELETE', async () => {
|
|
133
123
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
134
124
|
const viewerContext = new ViewerContext(companionProvider);
|
|
135
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext)
|
|
136
|
-
.enforcing()
|
|
137
|
-
.createAsync();
|
|
125
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext).createAsync();
|
|
138
126
|
// add another entity referencing testEntity that would cascade deletion to itself when testEntity is deleted
|
|
139
127
|
const leafEntity = await LeafDenyDeleteEntity.creator(viewerContext)
|
|
140
|
-
.enforcing()
|
|
141
128
|
.setField('simple_test_deny_update_cascade_delete_id', testEntity.getID())
|
|
142
129
|
.createAsync();
|
|
143
130
|
const canViewerDelete = await canViewerDeleteAsync(SimpleTestDenyUpdateEntity, testEntity);
|
|
@@ -155,12 +142,9 @@ describe(canViewerDeleteAsync, () => {
|
|
|
155
142
|
it('denies when recursive policy denies for SET_NULL', async () => {
|
|
156
143
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
157
144
|
const viewerContext = new ViewerContext(companionProvider);
|
|
158
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext)
|
|
159
|
-
.enforcing()
|
|
160
|
-
.createAsync();
|
|
145
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext).createAsync();
|
|
161
146
|
// add another entity referencing testEntity that would set null to its column when testEntity is deleted
|
|
162
147
|
const leafEntity = await LeafDenyUpdateEntity.creator(viewerContext)
|
|
163
|
-
.enforcing()
|
|
164
148
|
.setField('simple_test_deny_update_set_null_id', testEntity.getID())
|
|
165
149
|
.createAsync();
|
|
166
150
|
const canViewerDelete = await canViewerDeleteAsync(SimpleTestDenyUpdateEntity, testEntity);
|
|
@@ -178,17 +162,13 @@ describe(canViewerDeleteAsync, () => {
|
|
|
178
162
|
it('allows when recursive policy allows for CASCADE_DELETE and SET_NULL', async () => {
|
|
179
163
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
180
164
|
const viewerContext = new ViewerContext(companionProvider);
|
|
181
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext)
|
|
182
|
-
.enforcing()
|
|
183
|
-
.createAsync();
|
|
165
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext).createAsync();
|
|
184
166
|
// add another entity referencing testEntity that would cascade deletion to itself when testEntity is deleted
|
|
185
167
|
await LeafDenyUpdateEntity.creator(viewerContext)
|
|
186
|
-
.enforcing()
|
|
187
168
|
.setField('simple_test_deny_update_cascade_delete_id', testEntity.getID())
|
|
188
169
|
.createAsync();
|
|
189
170
|
// add another entity referencing testEntity that would set null to its column when testEntity is deleted
|
|
190
171
|
await LeafDenyDeleteEntity.creator(viewerContext)
|
|
191
|
-
.enforcing()
|
|
192
172
|
.setField('simple_test_deny_update_set_null_id', testEntity.getID())
|
|
193
173
|
.createAsync();
|
|
194
174
|
|
|
@@ -204,9 +184,7 @@ describe(canViewerDeleteAsync, () => {
|
|
|
204
184
|
it('rethrows non-authorization errors', async () => {
|
|
205
185
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
206
186
|
const viewerContext = new ViewerContext(companionProvider);
|
|
207
|
-
const testEntity = await SimpleTestThrowOtherErrorEntity.creator(viewerContext)
|
|
208
|
-
.enforcing()
|
|
209
|
-
.createAsync();
|
|
187
|
+
const testEntity = await SimpleTestThrowOtherErrorEntity.creator(viewerContext).createAsync();
|
|
210
188
|
await expect(
|
|
211
189
|
canViewerDeleteAsync(SimpleTestThrowOtherErrorEntity, testEntity),
|
|
212
190
|
).rejects.toThrowError('delete error');
|
|
@@ -218,11 +196,8 @@ describe(canViewerDeleteAsync, () => {
|
|
|
218
196
|
it('returns false when edge cannot be read', async () => {
|
|
219
197
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
220
198
|
const viewerContext = new ViewerContext(companionProvider);
|
|
221
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext)
|
|
222
|
-
.enforcing()
|
|
223
|
-
.createAsync();
|
|
199
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext).createAsync();
|
|
224
200
|
const leafEntity = await LeafDenyReadEntity.creator(viewerContext)
|
|
225
|
-
.enforcing()
|
|
226
201
|
.setField('simple_test_id', testEntity.getID())
|
|
227
202
|
.createAsync();
|
|
228
203
|
const canViewerDelete = await canViewerDeleteAsync(SimpleTestDenyUpdateEntity, testEntity);
|
|
@@ -240,11 +215,8 @@ describe(canViewerDeleteAsync, () => {
|
|
|
240
215
|
it('rethrows non-authorization edge read errors', async () => {
|
|
241
216
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
242
217
|
const viewerContext = new ViewerContext(companionProvider);
|
|
243
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext)
|
|
244
|
-
.enforcing()
|
|
245
|
-
.createAsync();
|
|
218
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(viewerContext).createAsync();
|
|
246
219
|
await SimpleTestThrowOtherErrorEntity.creator(viewerContext)
|
|
247
|
-
.enforcing()
|
|
248
220
|
.setField('simple_test_id', testEntity.getID())
|
|
249
221
|
.createAsync();
|
|
250
222
|
await expect(canViewerDeleteAsync(SimpleTestDenyUpdateEntity, testEntity)).rejects.toThrowError(
|
|
@@ -261,11 +233,11 @@ describe(canViewerDeleteAsync, () => {
|
|
|
261
233
|
const canViewerDelete = await viewerContext.runInTransactionForDatabaseAdaptorFlavorAsync(
|
|
262
234
|
'postgres',
|
|
263
235
|
async (queryContext) => {
|
|
264
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(
|
|
265
|
-
|
|
266
|
-
|
|
236
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(
|
|
237
|
+
viewerContext,
|
|
238
|
+
queryContext,
|
|
239
|
+
).createAsync();
|
|
267
240
|
await LeafDenyReadEntity.creator(viewerContext, queryContext)
|
|
268
|
-
.enforcing()
|
|
269
241
|
.setField('simple_test_id', testEntity.getID())
|
|
270
242
|
.createAsync();
|
|
271
243
|
// this would fail if transactions weren't supported or correctly passed through
|
|
@@ -277,11 +249,11 @@ describe(canViewerDeleteAsync, () => {
|
|
|
277
249
|
const canViewerDeleteResult = await viewerContext.runInTransactionForDatabaseAdaptorFlavorAsync(
|
|
278
250
|
'postgres',
|
|
279
251
|
async (queryContext) => {
|
|
280
|
-
const testEntity = await SimpleTestDenyUpdateEntity.creator(
|
|
281
|
-
|
|
282
|
-
|
|
252
|
+
const testEntity = await SimpleTestDenyUpdateEntity.creator(
|
|
253
|
+
viewerContext,
|
|
254
|
+
queryContext,
|
|
255
|
+
).createAsync();
|
|
283
256
|
await LeafDenyReadEntity.creator(viewerContext, queryContext)
|
|
284
|
-
.enforcing()
|
|
285
257
|
.setField('simple_test_id', testEntity.getID())
|
|
286
258
|
.createAsync();
|
|
287
259
|
// this would fail if transactions weren't supported or correctly passed through
|
package/src/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.ts
CHANGED
|
@@ -21,20 +21,18 @@ describe(canViewerDeleteAsync, () => {
|
|
|
21
21
|
const viewerContext = new ViewerContext(companionProvider);
|
|
22
22
|
|
|
23
23
|
// create root
|
|
24
|
-
const testEntity = await TestEntity.creator(viewerContext).
|
|
24
|
+
const testEntity = await TestEntity.creator(viewerContext).createAsync();
|
|
25
25
|
|
|
26
26
|
// create a bunch of leaves referencing root with
|
|
27
27
|
// edgeDeletionPermissionInferenceBehavior = EntityEdgeDeletionPermissionInferenceBehavior.ONE_IMPLIES_ALL
|
|
28
28
|
for (let i = 0; i < 10; i++) {
|
|
29
29
|
await TestLeafEntity.creator(viewerContext)
|
|
30
|
-
.enforcing()
|
|
31
30
|
.setField('test_entity_id', testEntity.getID())
|
|
32
31
|
.createAsync();
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
for (let i = 0; i < 10; i++) {
|
|
36
35
|
await TestLeafLookupByFieldEntity.creator(viewerContext)
|
|
37
|
-
.enforcing()
|
|
38
36
|
.setField('test_entity_id', testEntity.getID())
|
|
39
37
|
.createAsync();
|
|
40
38
|
}
|
|
@@ -65,12 +63,11 @@ describe(canViewerDeleteAsync, () => {
|
|
|
65
63
|
const viewerContext = new ViewerContext(companionProvider);
|
|
66
64
|
|
|
67
65
|
// create root
|
|
68
|
-
const testEntity = await TestEntity.creator(viewerContext).
|
|
66
|
+
const testEntity = await TestEntity.creator(viewerContext).createAsync();
|
|
69
67
|
|
|
70
68
|
// create a bunch of leaves with no edgeDeletionPermissionInferenceBehavior
|
|
71
69
|
for (let i = 0; i < 10; i++) {
|
|
72
70
|
await TestLeafNoInferenceEntity.creator(viewerContext)
|
|
73
|
-
.enforcing()
|
|
74
71
|
.setField('test_entity_id', testEntity.getID())
|
|
75
72
|
.createAsync();
|
|
76
73
|
}
|