@expo/entity 0.39.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.d.ts +99 -0
- package/build/AuthorizationResultBasedEntityAssociationLoader.js +122 -0
- package/build/AuthorizationResultBasedEntityAssociationLoader.js.map +1 -0
- package/build/AuthorizationResultBasedEntityLoader.d.ts +1 -1
- package/build/AuthorizationResultBasedEntityLoader.js.map +1 -1
- package/build/{EntityMutator.d.ts → AuthorizationResultBasedEntityMutator.d.ts} +5 -17
- package/build/{EntityMutator.js → AuthorizationResultBasedEntityMutator.js} +22 -48
- package/build/AuthorizationResultBasedEntityMutator.js.map +1 -0
- package/build/EnforcingEntityAssociationLoader.d.ts +79 -0
- package/build/EnforcingEntityAssociationLoader.js +62 -0
- package/build/EnforcingEntityAssociationLoader.js.map +1 -0
- package/build/EnforcingEntityCreator.d.ts +24 -0
- package/build/EnforcingEntityCreator.js +32 -0
- package/build/EnforcingEntityCreator.js.map +1 -0
- package/build/EnforcingEntityDeleter.d.ts +17 -0
- package/build/EnforcingEntityDeleter.js +22 -0
- package/build/EnforcingEntityDeleter.js.map +1 -0
- package/build/EnforcingEntityUpdater.d.ts +24 -0
- package/build/EnforcingEntityUpdater.js +32 -0
- package/build/EnforcingEntityUpdater.js.map +1 -0
- package/build/Entity.d.ts +26 -8
- package/build/Entity.js +38 -25
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +12 -91
- package/build/EntityAssociationLoader.js +20 -126
- package/build/EntityAssociationLoader.js.map +1 -1
- package/build/EntityCreator.d.ts +27 -0
- package/build/EntityCreator.js +39 -0
- package/build/EntityCreator.js.map +1 -0
- package/build/EntityDeleter.d.ts +27 -0
- package/build/EntityDeleter.js +40 -0
- package/build/EntityDeleter.js.map +1 -0
- package/build/EntityLoader.d.ts +4 -14
- package/build/EntityLoader.js +7 -20
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityLoaderFactory.d.ts +2 -2
- package/build/EntityLoaderFactory.js +4 -2
- package/build/EntityLoaderFactory.js.map +1 -1
- package/build/EntityMutatorFactory.d.ts +4 -4
- package/build/EntityMutatorFactory.js +4 -4
- package/build/EntityMutatorFactory.js.map +1 -1
- package/build/EntitySecondaryCacheLoader.d.ts +3 -3
- package/build/EntitySecondaryCacheLoader.js +1 -3
- package/build/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/EntityUpdater.d.ts +27 -0
- package/build/EntityUpdater.js +40 -0
- package/build/EntityUpdater.js.map +1 -0
- package/build/ReadonlyEntity.d.ts +24 -5
- package/build/ReadonlyEntity.js +33 -7
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerScopedEntityLoaderFactory.d.ts +2 -2
- package/build/ViewerScopedEntityLoaderFactory.js.map +1 -1
- package/build/ViewerScopedEntityMutatorFactory.d.ts +4 -4
- package/build/ViewerScopedEntityMutatorFactory.js.map +1 -1
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.d.ts +1 -0
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js +242 -0
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js.map +1 -0
- package/build/__tests__/{EntityLoader-constructor-test.js → AuthorizationResultBasedEntityLoader-constructor-test.js} +10 -10
- package/build/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.js.map +1 -0
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.d.ts +1 -0
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.js +401 -0
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.js.map +1 -0
- package/build/__tests__/EnforcingEntityAssociationLoader-test.d.ts +1 -0
- package/build/__tests__/EnforcingEntityAssociationLoader-test.js +115 -0
- package/build/__tests__/EnforcingEntityAssociationLoader-test.js.map +1 -0
- package/build/__tests__/Entity-test.js +63 -5
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +14 -184
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +34 -20
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityCompanion-test.js +17 -7
- package/build/__tests__/EntityCompanion-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +57 -71
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +22 -386
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +6 -9
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
- package/build/__tests__/EntityMutator-test.js +67 -70
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +17 -7
- package/build/__tests__/EntityPrivacyPolicy-test.js.map +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +7 -7
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +47 -81
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +40 -7
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +6 -10
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +10 -22
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/errors/EntityCacheAdapterError.js +17 -7
- package/build/errors/EntityCacheAdapterError.js.map +1 -1
- package/build/errors/EntityDatabaseAdapterError.js +17 -7
- package/build/errors/EntityDatabaseAdapterError.js.map +1 -1
- package/build/errors/EntityInvalidFieldValueError.js +17 -7
- package/build/errors/EntityInvalidFieldValueError.js.map +1 -1
- package/build/errors/EntityNotAuthorizedError.js +17 -7
- package/build/errors/EntityNotAuthorizedError.js.map +1 -1
- package/build/errors/EntityNotFoundError.js +17 -7
- package/build/errors/EntityNotFoundError.js.map +1 -1
- package/build/index.d.ts +19 -11
- package/build/index.js +24 -7
- package/build/index.js.map +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js +42 -32
- package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.js +17 -7
- package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +1 -1
- package/build/rules/AlwaysAllowPrivacyPolicyRule.js +17 -7
- package/build/rules/AlwaysAllowPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysDenyPrivacyPolicyRule.js +17 -7
- package/build/rules/AlwaysDenyPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysSkipPrivacyPolicyRule.js +17 -7
- package/build/rules/AlwaysSkipPrivacyPolicyRule.js.map +1 -1
- package/build/utils/EntityPrivacyUtils.js +4 -8
- package/build/utils/EntityPrivacyUtils.js.map +1 -1
- package/build/utils/__tests__/EntityPrivacyUtils-test.js +38 -28
- package/build/utils/__tests__/EntityPrivacyUtils-test.js.map +1 -1
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js +5 -5
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js.map +1 -1
- package/build/utils/testing/StubDatabaseAdapter.js +17 -7
- package/build/utils/testing/StubDatabaseAdapter.js.map +1 -1
- package/build/utils/testing/StubQueryContextProvider.d.ts +1 -3
- package/build/utils/testing/StubQueryContextProvider.js +1 -3
- package/build/utils/testing/StubQueryContextProvider.js.map +1 -1
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js +2 -1
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js.map +1 -1
- package/package.json +19 -3
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +490 -0
- package/src/AuthorizationResultBasedEntityLoader.ts +1 -1
- package/src/{EntityMutator.ts → AuthorizationResultBasedEntityMutator.ts} +62 -58
- package/src/EnforcingEntityAssociationLoader.ts +390 -0
- package/src/EnforcingEntityCreator.ts +55 -0
- package/src/EnforcingEntityDeleter.ts +44 -0
- package/src/EnforcingEntityUpdater.ts +55 -0
- package/src/Entity.ts +140 -29
- package/src/EntityAssociationLoader.ts +38 -495
- package/src/EntityCreator.ts +73 -0
- package/src/EntityDeleter.ts +73 -0
- package/src/EntityLoader.ts +10 -49
- package/src/EntityLoaderFactory.ts +20 -3
- package/src/EntityMutatorFactory.ts +32 -7
- package/src/EntitySecondaryCacheLoader.ts +5 -7
- package/src/EntityUpdater.ts +73 -0
- package/src/ReadonlyEntity.ts +121 -7
- package/src/ViewerScopedEntityLoaderFactory.ts +9 -2
- package/src/ViewerScopedEntityMutatorFactory.ts +29 -4
- package/src/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.ts +323 -0
- package/src/__tests__/{EntityLoader-constructor-test.ts → AuthorizationResultBasedEntityLoader-constructor-test.ts} +16 -9
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +730 -0
- package/src/__tests__/EnforcingEntityAssociationLoader-test.ts +253 -0
- package/src/__tests__/Entity-test.ts +77 -5
- package/src/__tests__/EntityAssociationLoader-test.ts +15 -260
- package/src/__tests__/EntityCommonUseCases-test.ts +24 -15
- package/src/__tests__/EntityEdges-test.ts +44 -64
- package/src/__tests__/EntityLoader-test.ts +29 -681
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +8 -9
- package/src/__tests__/EntityMutator-test.ts +116 -103
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +7 -7
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +65 -81
- package/src/__tests__/ReadonlyEntity-test.ts +47 -7
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +15 -15
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +19 -22
- package/src/index.ts +19 -11
- package/src/internal/__tests__/EntityDataManager-test.ts +25 -25
- package/src/utils/EntityPrivacyUtils.ts +10 -13
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +21 -23
- package/src/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.ts +5 -5
- package/src/utils/testing/StubQueryContextProvider.ts +1 -3
- package/src/utils/testing/createUnitTestEntityCompanionProvider.ts +3 -1
- package/build/EntityMutator.js.map +0 -1
- package/build/__tests__/EntityLoader-constructor-test.js.map +0 -1
- /package/build/__tests__/{EntityLoader-constructor-test.d.ts → AuthorizationResultBasedEntityLoader-constructor-test.d.ts} +0 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { result } from '@expo/results';
|
|
2
|
+
import { mock, instance, when, anything } from 'ts-mockito';
|
|
3
|
+
|
|
4
|
+
import AuthorizationResultBasedEntityAssociationLoader from '../AuthorizationResultBasedEntityAssociationLoader';
|
|
5
|
+
import EnforcingEntityAssociationLoader from '../EnforcingEntityAssociationLoader';
|
|
6
|
+
|
|
7
|
+
describe(EnforcingEntityAssociationLoader, () => {
|
|
8
|
+
describe('loadAssociatedEntityAsync', () => {
|
|
9
|
+
it('throws when result is unsuccessful', async () => {
|
|
10
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
11
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
12
|
+
const rejection = new Error();
|
|
13
|
+
when(
|
|
14
|
+
nonEnforcingEntityAssociationLoaderMock.loadAssociatedEntityAsync(anything(), anything()),
|
|
15
|
+
).thenResolve(result(rejection));
|
|
16
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
17
|
+
const enforcingEntityAssociationLoader = new EnforcingEntityAssociationLoader(
|
|
18
|
+
nonEnforcingEntityAssociationLoader,
|
|
19
|
+
);
|
|
20
|
+
await expect(
|
|
21
|
+
enforcingEntityAssociationLoader.loadAssociatedEntityAsync(anything(), anything()),
|
|
22
|
+
).rejects.toThrow(rejection);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('returns value when result is successful', async () => {
|
|
26
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
27
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
28
|
+
const resolved = {} as any;
|
|
29
|
+
when(
|
|
30
|
+
nonEnforcingEntityAssociationLoaderMock.loadAssociatedEntityAsync(anything(), anything()),
|
|
31
|
+
).thenResolve(result(resolved));
|
|
32
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
33
|
+
const enforcingEntityLoader = new EnforcingEntityAssociationLoader(
|
|
34
|
+
nonEnforcingEntityAssociationLoader,
|
|
35
|
+
);
|
|
36
|
+
await expect(
|
|
37
|
+
enforcingEntityLoader.loadAssociatedEntityAsync(anything(), anything()),
|
|
38
|
+
).resolves.toEqual(resolved);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('loadManyAssociatedEntitiesAsync', () => {
|
|
43
|
+
it('throws when result is unsuccessful', async () => {
|
|
44
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
45
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
46
|
+
const rejection = new Error();
|
|
47
|
+
when(
|
|
48
|
+
nonEnforcingEntityAssociationLoaderMock.loadManyAssociatedEntitiesAsync(
|
|
49
|
+
anything(),
|
|
50
|
+
anything() as never,
|
|
51
|
+
),
|
|
52
|
+
).thenResolve([result(rejection)]);
|
|
53
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
54
|
+
const enforcingEntityAssociationLoader = new EnforcingEntityAssociationLoader(
|
|
55
|
+
nonEnforcingEntityAssociationLoader,
|
|
56
|
+
);
|
|
57
|
+
await expect(
|
|
58
|
+
enforcingEntityAssociationLoader.loadManyAssociatedEntitiesAsync(
|
|
59
|
+
anything(),
|
|
60
|
+
anything() as never,
|
|
61
|
+
),
|
|
62
|
+
).rejects.toThrow(rejection);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('returns value when result is successful', async () => {
|
|
66
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
67
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
68
|
+
const resolved = [] as any;
|
|
69
|
+
when(
|
|
70
|
+
nonEnforcingEntityAssociationLoaderMock.loadManyAssociatedEntitiesAsync(
|
|
71
|
+
anything(),
|
|
72
|
+
anything() as never,
|
|
73
|
+
),
|
|
74
|
+
).thenResolve([result(resolved)]);
|
|
75
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
76
|
+
const enforcingEntityLoader = new EnforcingEntityAssociationLoader(
|
|
77
|
+
nonEnforcingEntityAssociationLoader,
|
|
78
|
+
);
|
|
79
|
+
await expect(
|
|
80
|
+
enforcingEntityLoader.loadManyAssociatedEntitiesAsync(anything(), anything() as never),
|
|
81
|
+
).resolves.toEqual([resolved]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('loadAssociatedEntityByFieldEqualingAsync', () => {
|
|
86
|
+
it('throws when result is unsuccessful', async () => {
|
|
87
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
88
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
89
|
+
const rejection = new Error();
|
|
90
|
+
when(
|
|
91
|
+
nonEnforcingEntityAssociationLoaderMock.loadAssociatedEntityByFieldEqualingAsync(
|
|
92
|
+
anything(),
|
|
93
|
+
anything(),
|
|
94
|
+
anything() as never,
|
|
95
|
+
),
|
|
96
|
+
).thenResolve(result(rejection));
|
|
97
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
98
|
+
const enforcingEntityAssociationLoader = new EnforcingEntityAssociationLoader(
|
|
99
|
+
nonEnforcingEntityAssociationLoader,
|
|
100
|
+
);
|
|
101
|
+
await expect(
|
|
102
|
+
enforcingEntityAssociationLoader.loadAssociatedEntityByFieldEqualingAsync(
|
|
103
|
+
anything(),
|
|
104
|
+
anything(),
|
|
105
|
+
anything() as never,
|
|
106
|
+
),
|
|
107
|
+
).rejects.toThrow(rejection);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('returns value when result is successful', async () => {
|
|
111
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
112
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
113
|
+
const resolved = {} as any;
|
|
114
|
+
when(
|
|
115
|
+
nonEnforcingEntityAssociationLoaderMock.loadAssociatedEntityByFieldEqualingAsync(
|
|
116
|
+
anything(),
|
|
117
|
+
anything(),
|
|
118
|
+
anything() as never,
|
|
119
|
+
),
|
|
120
|
+
).thenResolve(result(resolved));
|
|
121
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
122
|
+
const enforcingEntityLoader = new EnforcingEntityAssociationLoader(
|
|
123
|
+
nonEnforcingEntityAssociationLoader,
|
|
124
|
+
);
|
|
125
|
+
await expect(
|
|
126
|
+
enforcingEntityLoader.loadAssociatedEntityByFieldEqualingAsync(
|
|
127
|
+
anything(),
|
|
128
|
+
anything(),
|
|
129
|
+
anything() as never,
|
|
130
|
+
),
|
|
131
|
+
).resolves.toEqual(resolved);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('returns null when result is successful but null', async () => {
|
|
135
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
136
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
137
|
+
const resolved = null;
|
|
138
|
+
when(
|
|
139
|
+
nonEnforcingEntityAssociationLoaderMock.loadAssociatedEntityByFieldEqualingAsync(
|
|
140
|
+
anything(),
|
|
141
|
+
anything(),
|
|
142
|
+
anything() as never,
|
|
143
|
+
),
|
|
144
|
+
).thenResolve(resolved);
|
|
145
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
146
|
+
const enforcingEntityLoader = new EnforcingEntityAssociationLoader(
|
|
147
|
+
nonEnforcingEntityAssociationLoader,
|
|
148
|
+
);
|
|
149
|
+
await expect(
|
|
150
|
+
enforcingEntityLoader.loadAssociatedEntityByFieldEqualingAsync(
|
|
151
|
+
anything(),
|
|
152
|
+
anything(),
|
|
153
|
+
anything() as never,
|
|
154
|
+
),
|
|
155
|
+
).resolves.toEqual(resolved);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('loadManyAssociatedEntitiesByFieldEqualingAsync', () => {
|
|
160
|
+
it('throws when result is unsuccessful', async () => {
|
|
161
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
162
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
163
|
+
const rejection = new Error();
|
|
164
|
+
when(
|
|
165
|
+
nonEnforcingEntityAssociationLoaderMock.loadManyAssociatedEntitiesByFieldEqualingAsync(
|
|
166
|
+
anything(),
|
|
167
|
+
anything(),
|
|
168
|
+
anything() as never,
|
|
169
|
+
),
|
|
170
|
+
).thenResolve([result(rejection)]);
|
|
171
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
172
|
+
const enforcingEntityAssociationLoader = new EnforcingEntityAssociationLoader(
|
|
173
|
+
nonEnforcingEntityAssociationLoader,
|
|
174
|
+
);
|
|
175
|
+
await expect(
|
|
176
|
+
enforcingEntityAssociationLoader.loadManyAssociatedEntitiesByFieldEqualingAsync(
|
|
177
|
+
anything(),
|
|
178
|
+
anything(),
|
|
179
|
+
anything() as never,
|
|
180
|
+
),
|
|
181
|
+
).rejects.toThrow(rejection);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('returns value when result is successful', async () => {
|
|
185
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
186
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
187
|
+
const resolved = [] as any;
|
|
188
|
+
when(
|
|
189
|
+
nonEnforcingEntityAssociationLoaderMock.loadManyAssociatedEntitiesByFieldEqualingAsync(
|
|
190
|
+
anything(),
|
|
191
|
+
anything(),
|
|
192
|
+
anything() as never,
|
|
193
|
+
),
|
|
194
|
+
).thenResolve([result(resolved)]);
|
|
195
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
196
|
+
const enforcingEntityLoader = new EnforcingEntityAssociationLoader(
|
|
197
|
+
nonEnforcingEntityAssociationLoader,
|
|
198
|
+
);
|
|
199
|
+
await expect(
|
|
200
|
+
enforcingEntityLoader.loadManyAssociatedEntitiesByFieldEqualingAsync(
|
|
201
|
+
anything(),
|
|
202
|
+
anything(),
|
|
203
|
+
anything() as never,
|
|
204
|
+
),
|
|
205
|
+
).resolves.toEqual([resolved]);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('loadAssociatedEntityThroughAsync', () => {
|
|
210
|
+
it('throws when result is unsuccessful', async () => {
|
|
211
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
212
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
213
|
+
const rejection = new Error();
|
|
214
|
+
when(
|
|
215
|
+
nonEnforcingEntityAssociationLoaderMock.loadAssociatedEntityThroughAsync(anything()),
|
|
216
|
+
).thenResolve(result(rejection));
|
|
217
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
218
|
+
const enforcingEntityAssociationLoader = new EnforcingEntityAssociationLoader(
|
|
219
|
+
nonEnforcingEntityAssociationLoader,
|
|
220
|
+
);
|
|
221
|
+
await expect(
|
|
222
|
+
enforcingEntityAssociationLoader.loadAssociatedEntityThroughAsync(anything()),
|
|
223
|
+
).rejects.toThrow(rejection);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('returns value when result is successful', async () => {
|
|
227
|
+
const nonEnforcingEntityAssociationLoaderMock =
|
|
228
|
+
mock<AuthorizationResultBasedEntityAssociationLoader<any, any, any, any, any>>();
|
|
229
|
+
const resolved = {} as any;
|
|
230
|
+
when(
|
|
231
|
+
nonEnforcingEntityAssociationLoaderMock.loadAssociatedEntityThroughAsync(anything()),
|
|
232
|
+
).thenResolve(result(resolved));
|
|
233
|
+
const nonEnforcingEntityAssociationLoader = instance(nonEnforcingEntityAssociationLoaderMock);
|
|
234
|
+
const enforcingEntityLoader = new EnforcingEntityAssociationLoader(
|
|
235
|
+
nonEnforcingEntityAssociationLoader,
|
|
236
|
+
);
|
|
237
|
+
await expect(
|
|
238
|
+
enforcingEntityLoader.loadAssociatedEntityThroughAsync(anything()),
|
|
239
|
+
).resolves.toEqual(resolved);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('has the same method names as AuthorizationResultBasedEntityAssociationLoader', () => {
|
|
244
|
+
const enforcingLoaderProperties = Object.getOwnPropertyNames(
|
|
245
|
+
EnforcingEntityAssociationLoader.prototype,
|
|
246
|
+
);
|
|
247
|
+
const nonEnforcingLoaderProperties = Object.getOwnPropertyNames(
|
|
248
|
+
AuthorizationResultBasedEntityAssociationLoader.prototype,
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
expect(enforcingLoaderProperties).toEqual(nonEnforcingLoaderProperties);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -1,20 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthorizationResultBasedCreateMutator,
|
|
3
|
+
AuthorizationResultBasedDeleteMutator,
|
|
4
|
+
AuthorizationResultBasedUpdateMutator,
|
|
5
|
+
} from '../AuthorizationResultBasedEntityMutator';
|
|
6
|
+
import EnforcingEntityCreator from '../EnforcingEntityCreator';
|
|
7
|
+
import EnforcingEntityDeleter from '../EnforcingEntityDeleter';
|
|
8
|
+
import EnforcingEntityUpdater from '../EnforcingEntityUpdater';
|
|
1
9
|
import Entity from '../Entity';
|
|
2
|
-
import { CreateMutator, UpdateMutator } from '../EntityMutator';
|
|
3
10
|
import ViewerContext from '../ViewerContext';
|
|
4
11
|
import SimpleTestEntity from '../testfixtures/SimpleTestEntity';
|
|
5
12
|
import { createUnitTestEntityCompanionProvider } from '../utils/testing/createUnitTestEntityCompanionProvider';
|
|
6
13
|
|
|
7
14
|
describe(Entity, () => {
|
|
8
15
|
describe('creator', () => {
|
|
9
|
-
it('creates a new
|
|
16
|
+
it('creates a new EnforcingEntityCreator', () => {
|
|
10
17
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
11
18
|
const viewerContext = new ViewerContext(companionProvider);
|
|
12
|
-
expect(SimpleTestEntity.creator(viewerContext)).toBeInstanceOf(
|
|
19
|
+
expect(SimpleTestEntity.creator(viewerContext)).toBeInstanceOf(EnforcingEntityCreator);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('creatorWithAuthorizationResults', () => {
|
|
24
|
+
it('creates a new AuthorizationResultBasedCreateMutator', () => {
|
|
25
|
+
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
26
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
27
|
+
expect(SimpleTestEntity.creatorWithAuthorizationResults(viewerContext)).toBeInstanceOf(
|
|
28
|
+
AuthorizationResultBasedCreateMutator,
|
|
29
|
+
);
|
|
13
30
|
});
|
|
14
31
|
});
|
|
15
32
|
|
|
16
33
|
describe('updater', () => {
|
|
17
|
-
it('creates a new
|
|
34
|
+
it('creates a new EnforcingEntityUpdater', () => {
|
|
35
|
+
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
36
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
37
|
+
const data = {
|
|
38
|
+
id: 'what',
|
|
39
|
+
};
|
|
40
|
+
const testEntity = new SimpleTestEntity({
|
|
41
|
+
viewerContext,
|
|
42
|
+
id: 'what',
|
|
43
|
+
databaseFields: data,
|
|
44
|
+
selectedFields: data,
|
|
45
|
+
});
|
|
46
|
+
expect(SimpleTestEntity.updater(testEntity)).toBeInstanceOf(EnforcingEntityUpdater);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('updaterWithAuthorizationResults', () => {
|
|
51
|
+
it('creates a new AuthorizationResultBasedUpdateMutator', () => {
|
|
52
|
+
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
53
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
54
|
+
const data = {
|
|
55
|
+
id: 'what',
|
|
56
|
+
};
|
|
57
|
+
const testEntity = new SimpleTestEntity({
|
|
58
|
+
viewerContext,
|
|
59
|
+
id: 'what',
|
|
60
|
+
databaseFields: data,
|
|
61
|
+
selectedFields: data,
|
|
62
|
+
});
|
|
63
|
+
expect(SimpleTestEntity.updaterWithAuthorizationResults(testEntity)).toBeInstanceOf(
|
|
64
|
+
AuthorizationResultBasedUpdateMutator,
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('deleter', () => {
|
|
70
|
+
it('creates a new EnforcingEntityDeleter', () => {
|
|
71
|
+
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
72
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
73
|
+
const data = {
|
|
74
|
+
id: 'what',
|
|
75
|
+
};
|
|
76
|
+
const testEntity = new SimpleTestEntity({
|
|
77
|
+
viewerContext,
|
|
78
|
+
id: 'what',
|
|
79
|
+
databaseFields: data,
|
|
80
|
+
selectedFields: data,
|
|
81
|
+
});
|
|
82
|
+
expect(SimpleTestEntity.deleter(testEntity)).toBeInstanceOf(EnforcingEntityDeleter);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('deleterWithAuthorizationResults', () => {
|
|
87
|
+
it('creates a new AuthorizationResultBasedDeleteMutator', () => {
|
|
18
88
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
19
89
|
const viewerContext = new ViewerContext(companionProvider);
|
|
20
90
|
const data = {
|
|
@@ -26,7 +96,9 @@ describe(Entity, () => {
|
|
|
26
96
|
databaseFields: data,
|
|
27
97
|
selectedFields: data,
|
|
28
98
|
});
|
|
29
|
-
expect(SimpleTestEntity.
|
|
99
|
+
expect(SimpleTestEntity.deleterWithAuthorizationResults(testEntity)).toBeInstanceOf(
|
|
100
|
+
AuthorizationResultBasedDeleteMutator,
|
|
101
|
+
);
|
|
30
102
|
});
|
|
31
103
|
});
|
|
32
104
|
});
|
|
@@ -1,273 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import AuthorizationResultBasedEntityAssociationLoader from '../AuthorizationResultBasedEntityAssociationLoader';
|
|
2
|
+
import EnforcingEntityAssociationLoader from '../EnforcingEntityAssociationLoader';
|
|
4
3
|
import EntityAssociationLoader from '../EntityAssociationLoader';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import TestEntity2 from '../testfixtures/TestEntity2';
|
|
8
|
-
import TestViewerContext from '../testfixtures/TestViewerContext';
|
|
4
|
+
import ViewerContext from '../ViewerContext';
|
|
5
|
+
import SimpleTestEntity from '../testfixtures/SimpleTestEntity';
|
|
9
6
|
import { createUnitTestEntityCompanionProvider } from '../utils/testing/createUnitTestEntityCompanionProvider';
|
|
10
7
|
|
|
11
8
|
describe(EntityAssociationLoader, () => {
|
|
12
|
-
describe('
|
|
13
|
-
it('
|
|
14
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
15
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
16
|
-
const testOtherEntity = await enforceAsyncResult(
|
|
17
|
-
TestEntity.creator(viewerContext).createAsync(),
|
|
18
|
-
);
|
|
19
|
-
const testEntity = await enforceAsyncResult(
|
|
20
|
-
TestEntity.creator(viewerContext)
|
|
21
|
-
.setField('stringField', testOtherEntity.getID())
|
|
22
|
-
.createAsync(),
|
|
23
|
-
);
|
|
24
|
-
const loadedOther = await enforceAsyncResult(
|
|
25
|
-
testEntity.associationLoader().loadAssociatedEntityAsync('stringField', TestEntity),
|
|
26
|
-
);
|
|
27
|
-
expect(loadedOther.getID()).toEqual(testOtherEntity.getID());
|
|
28
|
-
|
|
29
|
-
const loadedOther2 = await enforceAsyncResult(
|
|
30
|
-
testEntity.associationLoader().loadAssociatedEntityAsync('nullableField', TestEntity),
|
|
31
|
-
);
|
|
32
|
-
expect(loadedOther2).toBeNull();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('loadManyAssociatedEntitiesAsync', () => {
|
|
37
|
-
it('loads many associated entities referencing this entity', async () => {
|
|
38
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
39
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
40
|
-
const testEntity = await enforceAsyncResult(TestEntity.creator(viewerContext).createAsync());
|
|
41
|
-
const testOtherEntity1 = await enforceAsyncResult(
|
|
42
|
-
TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync(),
|
|
43
|
-
);
|
|
44
|
-
const testOtherEntity2 = await enforceAsyncResult(
|
|
45
|
-
TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync(),
|
|
46
|
-
);
|
|
47
|
-
const loaded = await enforceResultsAsync(
|
|
48
|
-
testEntity.associationLoader().loadManyAssociatedEntitiesAsync(TestEntity, 'stringField'),
|
|
49
|
-
);
|
|
50
|
-
expect(loaded).toHaveLength(2);
|
|
51
|
-
expect(loaded.find((e) => e.getID() === testOtherEntity1.getID())).not.toBeUndefined();
|
|
52
|
-
expect(loaded.find((e) => e.getID() === testOtherEntity2.getID())).not.toBeUndefined();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('loadAssociatedEntityByFieldEqualingAsync', () => {
|
|
57
|
-
it('loads associated entity by field equaling', async () => {
|
|
58
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
59
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
60
|
-
const testOtherEntity = await enforceAsyncResult(
|
|
61
|
-
TestEntity.creator(viewerContext).createAsync(),
|
|
62
|
-
);
|
|
63
|
-
const testEntity = await enforceAsyncResult(
|
|
64
|
-
TestEntity.creator(viewerContext)
|
|
65
|
-
.setField('stringField', testOtherEntity.getID())
|
|
66
|
-
.createAsync(),
|
|
67
|
-
);
|
|
68
|
-
const loadedOtherResult = await testEntity
|
|
69
|
-
.associationLoader()
|
|
70
|
-
.loadAssociatedEntityByFieldEqualingAsync('stringField', TestEntity, 'customIdField');
|
|
71
|
-
expect(loadedOtherResult?.enforceValue().getID()).toEqual(testOtherEntity.getID());
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('returns null when loading associated entities by field equaling a non existent association', async () => {
|
|
75
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
76
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
77
|
-
const testEntity = await enforceAsyncResult(
|
|
78
|
-
TestEntity.creator(viewerContext).setField('stringField', uuidv4()).createAsync(),
|
|
79
|
-
);
|
|
80
|
-
const loadedOtherResult = await testEntity
|
|
81
|
-
.associationLoader()
|
|
82
|
-
.loadAssociatedEntityByFieldEqualingAsync('stringField', TestEntity, 'customIdField');
|
|
83
|
-
expect(loadedOtherResult).toBeNull();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('returns null when load-by field is null', async () => {
|
|
87
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
88
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
89
|
-
const testEntity = await enforceAsyncResult(
|
|
90
|
-
TestEntity.creator(viewerContext).setField('stringField', 'blah').createAsync(),
|
|
91
|
-
);
|
|
92
|
-
const loadedOtherResult = await testEntity
|
|
93
|
-
.associationLoader()
|
|
94
|
-
.loadAssociatedEntityByFieldEqualingAsync('nullableField', TestEntity, 'customIdField');
|
|
95
|
-
expect(loadedOtherResult).toBeNull();
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('loadManyAssociatedEntitiesByFieldEqualingAsync', () => {
|
|
100
|
-
it('loads many associated entities by field equaling', async () => {
|
|
101
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
102
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
103
|
-
const testEntity = await enforceAsyncResult(TestEntity.creator(viewerContext).createAsync());
|
|
104
|
-
const testOtherEntity1 = await enforceAsyncResult(
|
|
105
|
-
TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync(),
|
|
106
|
-
);
|
|
107
|
-
const testOtherEntity2 = await enforceAsyncResult(
|
|
108
|
-
TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync(),
|
|
109
|
-
);
|
|
110
|
-
const loaded = await enforceResultsAsync(
|
|
111
|
-
testEntity
|
|
112
|
-
.associationLoader()
|
|
113
|
-
.loadManyAssociatedEntitiesByFieldEqualingAsync(
|
|
114
|
-
'customIdField',
|
|
115
|
-
TestEntity,
|
|
116
|
-
'stringField',
|
|
117
|
-
),
|
|
118
|
-
);
|
|
119
|
-
expect(loaded).toHaveLength(2);
|
|
120
|
-
expect(loaded.find((e) => e.getID() === testOtherEntity1.getID())).not.toBeUndefined();
|
|
121
|
-
expect(loaded.find((e) => e.getID() === testOtherEntity2.getID())).not.toBeUndefined();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('returns empty results when field being queried by is null', async () => {
|
|
9
|
+
describe('enforcing', () => {
|
|
10
|
+
it('creates a new EnforcingEntityLoader', async () => {
|
|
125
11
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
126
|
-
const viewerContext = new
|
|
127
|
-
const testEntity = await
|
|
128
|
-
|
|
129
|
-
testEntity
|
|
130
|
-
.associationLoader()
|
|
131
|
-
.loadManyAssociatedEntitiesByFieldEqualingAsync(
|
|
132
|
-
'nullableField',
|
|
133
|
-
TestEntity,
|
|
134
|
-
'stringField',
|
|
135
|
-
),
|
|
136
|
-
);
|
|
137
|
-
expect(loaded).toHaveLength(0);
|
|
12
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
13
|
+
const testEntity = await SimpleTestEntity.creator(viewerContext).createAsync();
|
|
14
|
+
expect(testEntity.associationLoader()).toBeInstanceOf(EnforcingEntityAssociationLoader);
|
|
138
15
|
});
|
|
139
16
|
});
|
|
140
17
|
|
|
141
|
-
describe('
|
|
142
|
-
it('
|
|
143
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
144
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
145
|
-
const testEntity4 = await enforceAsyncResult(TestEntity.creator(viewerContext).createAsync());
|
|
146
|
-
const testEntity3 = await enforceAsyncResult(
|
|
147
|
-
TestEntity2.creator(viewerContext)
|
|
148
|
-
.setField('foreignKey', testEntity4.getID())
|
|
149
|
-
.createAsync(),
|
|
150
|
-
);
|
|
151
|
-
const testEntity2 = await enforceAsyncResult(
|
|
152
|
-
TestEntity.creator(viewerContext)
|
|
153
|
-
.setField('testIndexedField', testEntity3.getID())
|
|
154
|
-
.createAsync(),
|
|
155
|
-
);
|
|
156
|
-
const testEntity = await enforceAsyncResult(
|
|
157
|
-
TestEntity2.creator(viewerContext)
|
|
158
|
-
.setField('foreignKey', testEntity2.getID())
|
|
159
|
-
.createAsync(),
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
|
|
163
|
-
{
|
|
164
|
-
associatedEntityClass: TestEntity,
|
|
165
|
-
fieldIdentifyingAssociatedEntity: 'foreignKey',
|
|
166
|
-
},
|
|
167
|
-
]);
|
|
168
|
-
expect(loaded2Result?.enforceValue().getID()).toEqual(testEntity2.getID());
|
|
169
|
-
|
|
170
|
-
const loaded3Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
|
|
171
|
-
{
|
|
172
|
-
associatedEntityClass: TestEntity,
|
|
173
|
-
fieldIdentifyingAssociatedEntity: 'foreignKey',
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
associatedEntityClass: TestEntity2,
|
|
177
|
-
fieldIdentifyingAssociatedEntity: 'testIndexedField',
|
|
178
|
-
},
|
|
179
|
-
]);
|
|
180
|
-
expect(loaded3Result?.enforceValue().getID()).toEqual(testEntity3.getID());
|
|
181
|
-
|
|
182
|
-
const loaded4Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
|
|
183
|
-
{
|
|
184
|
-
associatedEntityClass: TestEntity,
|
|
185
|
-
fieldIdentifyingAssociatedEntity: 'foreignKey',
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
associatedEntityClass: TestEntity2,
|
|
189
|
-
fieldIdentifyingAssociatedEntity: 'testIndexedField',
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
associatedEntityClass: TestEntity,
|
|
193
|
-
fieldIdentifyingAssociatedEntity: 'foreignKey',
|
|
194
|
-
},
|
|
195
|
-
]);
|
|
196
|
-
expect(loaded4Result?.enforceValue().getID()).toEqual(testEntity4.getID());
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('fails when chain loading associated entity fails', async () => {
|
|
200
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
201
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
202
|
-
|
|
203
|
-
const testEntity = await enforceAsyncResult(
|
|
204
|
-
TestEntity2.creator(viewerContext).setField('foreignKey', uuidv4()).createAsync(),
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
const loadResult = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
|
|
208
|
-
{
|
|
209
|
-
associatedEntityClass: TestEntity,
|
|
210
|
-
fieldIdentifyingAssociatedEntity: 'foreignKey',
|
|
211
|
-
},
|
|
212
|
-
]);
|
|
213
|
-
expect(loadResult?.ok).toBe(false);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('supports chain loading by field equality', async () => {
|
|
18
|
+
describe('withAuthorizationResults', () => {
|
|
19
|
+
it('creates a new AuthorizationResultBasedEntityAssociationLoader', async () => {
|
|
217
20
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
218
|
-
const viewerContext = new
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
TestEntity.creator(viewerContext).setField('stringField', fieldValue).createAsync(),
|
|
21
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
22
|
+
const testEntity = await SimpleTestEntity.creator(viewerContext).createAsync();
|
|
23
|
+
expect(testEntity.associationLoaderWithAuthorizationResults()).toBeInstanceOf(
|
|
24
|
+
AuthorizationResultBasedEntityAssociationLoader,
|
|
223
25
|
);
|
|
224
|
-
const testEntity = await enforceAsyncResult(
|
|
225
|
-
TestEntity2.creator(viewerContext).setField('foreignKey', fieldValue).createAsync(),
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
|
|
229
|
-
{
|
|
230
|
-
associatedEntityClass: TestEntity,
|
|
231
|
-
fieldIdentifyingAssociatedEntity: 'foreignKey',
|
|
232
|
-
associatedEntityLookupByField: 'stringField',
|
|
233
|
-
},
|
|
234
|
-
]);
|
|
235
|
-
expect(loaded2Result?.enforceValue().getID()).toEqual(testEntity2.getID());
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('returns null when chain loading by field equality returns null', async () => {
|
|
239
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
240
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
241
|
-
|
|
242
|
-
const testEntity = await enforceAsyncResult(
|
|
243
|
-
TestEntity2.creator(viewerContext).setField('foreignKey', uuidv4()).createAsync(),
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
|
|
247
|
-
{
|
|
248
|
-
associatedEntityClass: TestEntity,
|
|
249
|
-
fieldIdentifyingAssociatedEntity: 'foreignKey',
|
|
250
|
-
associatedEntityLookupByField: 'stringField',
|
|
251
|
-
},
|
|
252
|
-
]);
|
|
253
|
-
expect(loaded2Result).toBeNull();
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('returns null when chain loading by field is null', async () => {
|
|
257
|
-
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
258
|
-
const viewerContext = new TestViewerContext(companionProvider);
|
|
259
|
-
|
|
260
|
-
const testEntity = await enforceAsyncResult(
|
|
261
|
-
TestEntity.creator(viewerContext).setField('nullableField', null).createAsync(),
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
const loadedResult = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
|
|
265
|
-
{
|
|
266
|
-
associatedEntityClass: TestEntity,
|
|
267
|
-
fieldIdentifyingAssociatedEntity: 'nullableField',
|
|
268
|
-
},
|
|
269
|
-
]);
|
|
270
|
-
expect(loadedResult).toBeNull();
|
|
271
26
|
});
|
|
272
27
|
});
|
|
273
28
|
});
|