@expo/entity 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/EnforcingEntityLoader.d.ts +5 -0
- package/build/EnforcingEntityLoader.js +8 -0
- package/build/EnforcingEntityLoader.js.map +1 -1
- package/build/Entity.d.ts +6 -6
- package/build/Entity.js +6 -29
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +8 -8
- package/build/EntityAssociationLoader.js +4 -20
- package/build/EntityAssociationLoader.js.map +1 -1
- package/build/EntityFields.js +3 -2
- package/build/EntityFields.js.map +1 -1
- package/build/EntityLoader.d.ts +6 -0
- package/build/EntityLoader.js +11 -0
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityMutationTriggerConfiguration.d.ts +5 -7
- package/build/EntityMutationTriggerConfiguration.js +3 -4
- package/build/EntityMutationTriggerConfiguration.js.map +1 -1
- package/build/EntityQueryContextProvider.d.ts +1 -1
- package/build/EntityQueryContextProvider.js +1 -1
- package/build/EntityQueryContextProvider.js.map +1 -1
- package/build/IEntityCacheAdapterProvider.d.ts +1 -1
- package/build/ReadonlyEntity.d.ts +1 -1
- package/build/ReadonlyEntity.js +1 -4
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerContext.d.ts +2 -2
- package/build/ViewerContext.js +3 -3
- package/build/ViewerContext.js.map +1 -1
- package/build/__tests__/EnforcingEntityLoader-test.js +27 -0
- package/build/__tests__/EnforcingEntityLoader-test.js.map +1 -1
- package/build/__tests__/Entity-test.js +13 -13
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +69 -37
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +19 -11
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +72 -40
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityFields-test.js +7 -1
- package/build/__tests__/EntityFields-test.js.map +1 -1
- package/build/__tests__/EntityLoader-constructor-test.js +1 -1
- package/build/__tests__/EntityLoader-constructor-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +22 -20
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +6 -6
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
- package/build/__tests__/EntityMutator-test.js +20 -20
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +10 -10
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +79 -47
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +13 -13
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/ViewerContext-test.js +2 -2
- package/build/__tests__/ViewerContext-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +12 -8
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +15 -13
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/internal/EntityDataManager.js +1 -1
- package/build/internal/EntityDataManager.js.map +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js +11 -11
- package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
- package/build/testfixtures/SimpleTestEntity.d.ts +8 -8
- package/build/testfixtures/SimpleTestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity.d.ts +12 -12
- package/build/testfixtures/TestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity2.d.ts +8 -8
- package/build/testfixtures/TestEntity2.js.map +1 -1
- package/build/testfixtures/TestViewerContext.d.ts +3 -0
- package/build/testfixtures/TestViewerContext.js +6 -0
- package/build/testfixtures/TestViewerContext.js.map +1 -1
- package/package.json +2 -2
- package/src/EnforcingEntityLoader.ts +9 -0
- package/src/Entity.ts +6 -29
- package/src/EntityAssociationLoader.ts +9 -25
- package/src/EntityFields.ts +5 -3
- package/src/EntityLoader.ts +17 -0
- package/src/EntityMutationTriggerConfiguration.ts +5 -7
- package/src/EntityQueryContextProvider.ts +1 -1
- package/src/IEntityCacheAdapterProvider.ts +1 -1
- package/src/ReadonlyEntity.ts +1 -4
- package/src/ViewerContext.ts +5 -5
- package/src/__tests__/EnforcingEntityLoader-test.ts +43 -0
- package/src/__tests__/Entity-test.ts +43 -27
- package/src/__tests__/EntityAssociationLoader-test.ts +168 -86
- package/src/__tests__/EntityCommonUseCases-test.ts +36 -18
- package/src/__tests__/EntityEdges-test.ts +102 -40
- package/src/__tests__/EntityFields-test.ts +7 -1
- package/src/__tests__/EntityLoader-constructor-test.ts +1 -1
- package/src/__tests__/EntityLoader-test.ts +24 -20
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +19 -16
- package/src/__tests__/EntityMutator-test.ts +67 -61
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +20 -11
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +115 -47
- package/src/__tests__/ReadonlyEntity-test.ts +15 -13
- package/src/__tests__/ViewerContext-test.ts +3 -2
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +33 -22
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +30 -22
- package/src/internal/EntityDataManager.ts +1 -1
- package/src/internal/__tests__/EntityDataManager-test.ts +11 -11
- package/src/testfixtures/SimpleTestEntity.ts +8 -8
- package/src/testfixtures/TestEntity.ts +15 -12
- package/src/testfixtures/TestEntity2.ts +8 -8
- package/src/testfixtures/TestViewerContext.ts +12 -1
|
@@ -31,7 +31,6 @@ import EntityMutatorFactory from '../EntityMutatorFactory';
|
|
|
31
31
|
import { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
|
|
32
32
|
import { EntityTransactionalQueryContext, EntityQueryContext } from '../EntityQueryContext';
|
|
33
33
|
import IEntityDatabaseAdapterProvider from '../IEntityDatabaseAdapterProvider';
|
|
34
|
-
import ViewerContext from '../ViewerContext';
|
|
35
34
|
import { enforceResultsAsync } from '../entityUtils';
|
|
36
35
|
import EntityDataManager from '../internal/EntityDataManager';
|
|
37
36
|
import ReadThroughEntityCache from '../internal/ReadThroughEntityCache';
|
|
@@ -47,6 +46,7 @@ import TestEntity, {
|
|
|
47
46
|
TestEntityPrivacyPolicy,
|
|
48
47
|
testEntityConfiguration,
|
|
49
48
|
} from '../testfixtures/TestEntity';
|
|
49
|
+
import TestViewerContext from '../testfixtures/TestViewerContext';
|
|
50
50
|
import { NoCacheStubCacheAdapterProvider } from '../utils/testing/StubCacheAdapter';
|
|
51
51
|
import StubDatabaseAdapter from '../utils/testing/StubDatabaseAdapter';
|
|
52
52
|
import StubQueryContextProvider from '../utils/testing/StubQueryContextProvider';
|
|
@@ -54,18 +54,18 @@ import StubQueryContextProvider from '../utils/testing/StubQueryContextProvider'
|
|
|
54
54
|
class TestMutationTrigger extends EntityMutationTrigger<
|
|
55
55
|
TestFields,
|
|
56
56
|
string,
|
|
57
|
-
|
|
57
|
+
TestViewerContext,
|
|
58
58
|
TestEntity,
|
|
59
59
|
keyof TestFields
|
|
60
60
|
> {
|
|
61
61
|
async executeAsync(
|
|
62
|
-
_viewerContext:
|
|
62
|
+
_viewerContext: TestViewerContext,
|
|
63
63
|
_queryContext: EntityQueryContext,
|
|
64
64
|
_entity: TestEntity,
|
|
65
65
|
_mutationInfo: EntityTriggerMutationInfo<
|
|
66
66
|
TestFields,
|
|
67
67
|
string,
|
|
68
|
-
|
|
68
|
+
TestViewerContext,
|
|
69
69
|
TestEntity,
|
|
70
70
|
keyof TestFields
|
|
71
71
|
>
|
|
@@ -75,31 +75,37 @@ class TestMutationTrigger extends EntityMutationTrigger<
|
|
|
75
75
|
class TestNonTransactionalMutationTrigger extends EntityNonTransactionalMutationTrigger<
|
|
76
76
|
TestFields,
|
|
77
77
|
string,
|
|
78
|
-
|
|
78
|
+
TestViewerContext,
|
|
79
79
|
TestEntity,
|
|
80
80
|
keyof TestFields
|
|
81
81
|
> {
|
|
82
|
-
async executeAsync(_viewerContext:
|
|
82
|
+
async executeAsync(_viewerContext: TestViewerContext, _entity: TestEntity): Promise<void> {}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
const setUpMutationValidatorSpies = (
|
|
86
86
|
mutationValidators: EntityMutationValidator<
|
|
87
87
|
TestFields,
|
|
88
88
|
string,
|
|
89
|
-
|
|
89
|
+
TestViewerContext,
|
|
90
90
|
TestEntity,
|
|
91
91
|
keyof TestFields
|
|
92
92
|
>[]
|
|
93
|
-
): EntityMutationValidator<
|
|
93
|
+
): EntityMutationValidator<
|
|
94
|
+
TestFields,
|
|
95
|
+
string,
|
|
96
|
+
TestViewerContext,
|
|
97
|
+
TestEntity,
|
|
98
|
+
keyof TestFields
|
|
99
|
+
>[] => {
|
|
94
100
|
return mutationValidators.map((validator) => spy(validator));
|
|
95
101
|
};
|
|
96
102
|
|
|
97
103
|
const verifyValidatorCounts = (
|
|
98
|
-
viewerContext:
|
|
104
|
+
viewerContext: TestViewerContext,
|
|
99
105
|
mutationValidatorSpies: EntityMutationValidator<
|
|
100
106
|
TestFields,
|
|
101
107
|
string,
|
|
102
|
-
|
|
108
|
+
TestViewerContext,
|
|
103
109
|
TestEntity,
|
|
104
110
|
keyof TestFields
|
|
105
111
|
>[],
|
|
@@ -107,7 +113,7 @@ const verifyValidatorCounts = (
|
|
|
107
113
|
mutationInfo: EntityValidatorMutationInfo<
|
|
108
114
|
TestFields,
|
|
109
115
|
string,
|
|
110
|
-
|
|
116
|
+
TestViewerContext,
|
|
111
117
|
TestEntity,
|
|
112
118
|
keyof TestFields
|
|
113
119
|
>
|
|
@@ -128,14 +134,14 @@ const setUpMutationTriggerSpies = (
|
|
|
128
134
|
mutationTriggers: EntityMutationTriggerConfiguration<
|
|
129
135
|
TestFields,
|
|
130
136
|
string,
|
|
131
|
-
|
|
137
|
+
TestViewerContext,
|
|
132
138
|
TestEntity,
|
|
133
139
|
keyof TestFields
|
|
134
140
|
>
|
|
135
141
|
): EntityMutationTriggerConfiguration<
|
|
136
142
|
TestFields,
|
|
137
143
|
string,
|
|
138
|
-
|
|
144
|
+
TestViewerContext,
|
|
139
145
|
TestEntity,
|
|
140
146
|
keyof TestFields
|
|
141
147
|
> => {
|
|
@@ -153,11 +159,11 @@ const setUpMutationTriggerSpies = (
|
|
|
153
159
|
};
|
|
154
160
|
|
|
155
161
|
const verifyTriggerCounts = (
|
|
156
|
-
viewerContext:
|
|
162
|
+
viewerContext: TestViewerContext,
|
|
157
163
|
mutationTriggerSpies: EntityMutationTriggerConfiguration<
|
|
158
164
|
TestFields,
|
|
159
165
|
string,
|
|
160
|
-
|
|
166
|
+
TestViewerContext,
|
|
161
167
|
TestEntity,
|
|
162
168
|
keyof TestFields
|
|
163
169
|
>,
|
|
@@ -166,7 +172,7 @@ const verifyTriggerCounts = (
|
|
|
166
172
|
EntityMutationTriggerConfiguration<
|
|
167
173
|
TestFields,
|
|
168
174
|
string,
|
|
169
|
-
|
|
175
|
+
TestViewerContext,
|
|
170
176
|
TestEntity,
|
|
171
177
|
keyof TestFields
|
|
172
178
|
>,
|
|
@@ -182,7 +188,7 @@ const verifyTriggerCounts = (
|
|
|
182
188
|
mutationInfo: EntityTriggerMutationInfo<
|
|
183
189
|
TestFields,
|
|
184
190
|
string,
|
|
185
|
-
|
|
191
|
+
TestViewerContext,
|
|
186
192
|
TestEntity,
|
|
187
193
|
keyof TestFields
|
|
188
194
|
>
|
|
@@ -243,7 +249,7 @@ const createEntityMutatorFactory = (
|
|
|
243
249
|
entityLoaderFactory: EntityLoaderFactory<
|
|
244
250
|
TestFields,
|
|
245
251
|
string,
|
|
246
|
-
|
|
252
|
+
TestViewerContext,
|
|
247
253
|
TestEntity,
|
|
248
254
|
TestEntityPrivacyPolicy,
|
|
249
255
|
keyof TestFields
|
|
@@ -251,7 +257,7 @@ const createEntityMutatorFactory = (
|
|
|
251
257
|
entityMutatorFactory: EntityMutatorFactory<
|
|
252
258
|
TestFields,
|
|
253
259
|
string,
|
|
254
|
-
|
|
260
|
+
TestViewerContext,
|
|
255
261
|
TestEntity,
|
|
256
262
|
TestEntityPrivacyPolicy
|
|
257
263
|
>;
|
|
@@ -259,14 +265,14 @@ const createEntityMutatorFactory = (
|
|
|
259
265
|
mutationValidators: EntityMutationValidator<
|
|
260
266
|
TestFields,
|
|
261
267
|
string,
|
|
262
|
-
|
|
268
|
+
TestViewerContext,
|
|
263
269
|
TestEntity,
|
|
264
270
|
keyof TestFields
|
|
265
271
|
>[];
|
|
266
272
|
mutationTriggers: EntityMutationTriggerConfiguration<
|
|
267
273
|
TestFields,
|
|
268
274
|
string,
|
|
269
|
-
|
|
275
|
+
TestViewerContext,
|
|
270
276
|
TestEntity,
|
|
271
277
|
keyof TestFields
|
|
272
278
|
>;
|
|
@@ -274,14 +280,14 @@ const createEntityMutatorFactory = (
|
|
|
274
280
|
const mutationValidators: EntityMutationValidator<
|
|
275
281
|
TestFields,
|
|
276
282
|
string,
|
|
277
|
-
|
|
283
|
+
TestViewerContext,
|
|
278
284
|
TestEntity,
|
|
279
285
|
keyof TestFields
|
|
280
286
|
>[] = [new TestMutationTrigger()];
|
|
281
287
|
const mutationTriggers: EntityMutationTriggerConfiguration<
|
|
282
288
|
TestFields,
|
|
283
289
|
string,
|
|
284
|
-
|
|
290
|
+
TestViewerContext,
|
|
285
291
|
TestEntity,
|
|
286
292
|
keyof TestFields
|
|
287
293
|
> = {
|
|
@@ -372,8 +378,8 @@ const createEntityMutatorFactory = (
|
|
|
372
378
|
describe(EntityMutatorFactory, () => {
|
|
373
379
|
describe('forCreate', () => {
|
|
374
380
|
it('creates entities', async () => {
|
|
375
|
-
const viewerContext = mock<
|
|
376
|
-
const queryContext = StubQueryContextProvider.
|
|
381
|
+
const viewerContext = mock<TestViewerContext>();
|
|
382
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
377
383
|
|
|
378
384
|
const id1 = uuidv4();
|
|
379
385
|
const id2 = uuidv4();
|
|
@@ -403,8 +409,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
403
409
|
});
|
|
404
410
|
|
|
405
411
|
it('checks privacy', async () => {
|
|
406
|
-
const viewerContext = mock<
|
|
407
|
-
const queryContext = StubQueryContextProvider.
|
|
412
|
+
const viewerContext = mock<TestViewerContext>();
|
|
413
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
408
414
|
|
|
409
415
|
const id1 = uuidv4();
|
|
410
416
|
const id2 = uuidv4();
|
|
@@ -446,8 +452,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
446
452
|
});
|
|
447
453
|
|
|
448
454
|
it('executes triggers', async () => {
|
|
449
|
-
const viewerContext = mock<
|
|
450
|
-
const queryContext = StubQueryContextProvider.
|
|
455
|
+
const viewerContext = mock<TestViewerContext>();
|
|
456
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
451
457
|
|
|
452
458
|
const id1 = uuidv4();
|
|
453
459
|
const id2 = uuidv4();
|
|
@@ -493,8 +499,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
493
499
|
});
|
|
494
500
|
|
|
495
501
|
it('executes validators', async () => {
|
|
496
|
-
const viewerContext = mock<
|
|
497
|
-
const queryContext = StubQueryContextProvider.
|
|
502
|
+
const viewerContext = mock<TestViewerContext>();
|
|
503
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
498
504
|
|
|
499
505
|
const id1 = uuidv4();
|
|
500
506
|
const id2 = uuidv4();
|
|
@@ -530,9 +536,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
530
536
|
|
|
531
537
|
describe('forUpdate', () => {
|
|
532
538
|
it('updates entities', async () => {
|
|
533
|
-
const viewerContext = mock<
|
|
539
|
+
const viewerContext = mock<TestViewerContext>();
|
|
534
540
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
535
|
-
const queryContext = StubQueryContextProvider.
|
|
541
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
536
542
|
|
|
537
543
|
const id1 = uuidv4();
|
|
538
544
|
const id2 = uuidv4();
|
|
@@ -579,9 +585,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
579
585
|
});
|
|
580
586
|
|
|
581
587
|
it('checks privacy', async () => {
|
|
582
|
-
const viewerContext = mock<
|
|
588
|
+
const viewerContext = mock<TestViewerContext>();
|
|
583
589
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
584
|
-
const queryContext = StubQueryContextProvider.
|
|
590
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
585
591
|
|
|
586
592
|
const id1 = uuidv4();
|
|
587
593
|
const id2 = uuidv4();
|
|
@@ -630,9 +636,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
630
636
|
});
|
|
631
637
|
|
|
632
638
|
it('executes triggers', async () => {
|
|
633
|
-
const viewerContext = mock<
|
|
639
|
+
const viewerContext = mock<TestViewerContext>();
|
|
634
640
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
635
|
-
const queryContext = StubQueryContextProvider.
|
|
641
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
636
642
|
|
|
637
643
|
const id1 = uuidv4();
|
|
638
644
|
const id2 = uuidv4();
|
|
@@ -688,9 +694,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
688
694
|
);
|
|
689
695
|
});
|
|
690
696
|
it('executes validators', async () => {
|
|
691
|
-
const viewerContext = mock<
|
|
697
|
+
const viewerContext = mock<TestViewerContext>();
|
|
692
698
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
693
|
-
const queryContext = StubQueryContextProvider.
|
|
699
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
694
700
|
|
|
695
701
|
const id1 = uuidv4();
|
|
696
702
|
const id2 = uuidv4();
|
|
@@ -737,9 +743,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
737
743
|
|
|
738
744
|
describe('forDelete', () => {
|
|
739
745
|
it('deletes entities', async () => {
|
|
740
|
-
const viewerContext = mock<
|
|
746
|
+
const viewerContext = mock<TestViewerContext>();
|
|
741
747
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
742
|
-
const queryContext = StubQueryContextProvider.
|
|
748
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
743
749
|
|
|
744
750
|
const id1 = uuidv4();
|
|
745
751
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
@@ -772,9 +778,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
772
778
|
});
|
|
773
779
|
|
|
774
780
|
it('checks privacy', async () => {
|
|
775
|
-
const viewerContext = mock<
|
|
781
|
+
const viewerContext = mock<TestViewerContext>();
|
|
776
782
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
777
|
-
const queryContext = StubQueryContextProvider.
|
|
783
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
778
784
|
|
|
779
785
|
const id1 = uuidv4();
|
|
780
786
|
const { privacyPolicy, entityMutatorFactory, entityLoaderFactory } =
|
|
@@ -811,9 +817,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
811
817
|
});
|
|
812
818
|
|
|
813
819
|
it('executes triggers', async () => {
|
|
814
|
-
const viewerContext = mock<
|
|
820
|
+
const viewerContext = mock<TestViewerContext>();
|
|
815
821
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
816
|
-
const queryContext = StubQueryContextProvider.
|
|
822
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
817
823
|
|
|
818
824
|
const id1 = uuidv4();
|
|
819
825
|
const { mutationTriggers, entityMutatorFactory, entityLoaderFactory } =
|
|
@@ -854,9 +860,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
854
860
|
});
|
|
855
861
|
|
|
856
862
|
it('does not execute validators', async () => {
|
|
857
|
-
const viewerContext = mock<
|
|
863
|
+
const viewerContext = mock<TestViewerContext>();
|
|
858
864
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
859
|
-
const queryContext = StubQueryContextProvider.
|
|
865
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
860
866
|
|
|
861
867
|
const id1 = uuidv4();
|
|
862
868
|
const { mutationValidators, entityMutatorFactory, entityLoaderFactory } =
|
|
@@ -888,9 +894,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
888
894
|
});
|
|
889
895
|
|
|
890
896
|
it('invalidates cache for fields upon create', async () => {
|
|
891
|
-
const viewerContext = mock<
|
|
897
|
+
const viewerContext = mock<TestViewerContext>();
|
|
892
898
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
893
|
-
const queryContext = StubQueryContextProvider.
|
|
899
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
894
900
|
|
|
895
901
|
const id1 = uuidv4();
|
|
896
902
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
@@ -927,8 +933,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
927
933
|
});
|
|
928
934
|
|
|
929
935
|
it('throws error when field not valid', async () => {
|
|
930
|
-
const viewerContext = mock<
|
|
931
|
-
const queryContext = StubQueryContextProvider.
|
|
936
|
+
const viewerContext = mock<TestViewerContext>();
|
|
937
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
932
938
|
const id1 = uuidv4();
|
|
933
939
|
const { entityMutatorFactory } = createEntityMutatorFactory([
|
|
934
940
|
{
|
|
@@ -963,8 +969,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
963
969
|
|
|
964
970
|
it('returns error result when not authorized to create', async () => {
|
|
965
971
|
const entityCompanionProvider = instance(mock(EntityCompanionProvider));
|
|
966
|
-
const viewerContext = instance(mock(
|
|
967
|
-
const queryContext = StubQueryContextProvider.
|
|
972
|
+
const viewerContext = instance(mock(TestViewerContext));
|
|
973
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
968
974
|
const privacyPolicyMock = mock(SimpleTestEntityPrivacyPolicy);
|
|
969
975
|
const databaseAdapter = instance(mock<EntityDatabaseAdapter<SimpleTestFields>>());
|
|
970
976
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
@@ -986,7 +992,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
986
992
|
EntityLoader<
|
|
987
993
|
SimpleTestFields,
|
|
988
994
|
string,
|
|
989
|
-
|
|
995
|
+
TestViewerContext,
|
|
990
996
|
SimpleTestEntity,
|
|
991
997
|
SimpleTestEntityPrivacyPolicy,
|
|
992
998
|
keyof SimpleTestFields
|
|
@@ -1000,7 +1006,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1000
1006
|
EntityLoaderFactory<
|
|
1001
1007
|
SimpleTestFields,
|
|
1002
1008
|
string,
|
|
1003
|
-
|
|
1009
|
+
TestViewerContext,
|
|
1004
1010
|
SimpleTestEntity,
|
|
1005
1011
|
SimpleTestEntityPrivacyPolicy,
|
|
1006
1012
|
keyof SimpleTestFields
|
|
@@ -1087,8 +1093,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
1087
1093
|
|
|
1088
1094
|
const entityCompanionProvider = instance(entityCompanionProviderMock);
|
|
1089
1095
|
|
|
1090
|
-
const viewerContext = instance(mock(
|
|
1091
|
-
const queryContext = StubQueryContextProvider.
|
|
1096
|
+
const viewerContext = instance(mock(TestViewerContext));
|
|
1097
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
1092
1098
|
const privacyPolicy = instance(mock(SimpleTestEntityPrivacyPolicy));
|
|
1093
1099
|
const databaseAdapterMock = mock<EntityDatabaseAdapter<SimpleTestFields>>();
|
|
1094
1100
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
@@ -1110,7 +1116,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1110
1116
|
EntityLoader<
|
|
1111
1117
|
SimpleTestFields,
|
|
1112
1118
|
string,
|
|
1113
|
-
|
|
1119
|
+
TestViewerContext,
|
|
1114
1120
|
SimpleTestEntity,
|
|
1115
1121
|
SimpleTestEntityPrivacyPolicy,
|
|
1116
1122
|
keyof SimpleTestFields
|
|
@@ -1124,7 +1130,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1124
1130
|
EntityLoaderFactory<
|
|
1125
1131
|
SimpleTestFields,
|
|
1126
1132
|
string,
|
|
1127
|
-
|
|
1133
|
+
TestViewerContext,
|
|
1128
1134
|
SimpleTestEntity,
|
|
1129
1135
|
SimpleTestEntityPrivacyPolicy,
|
|
1130
1136
|
keyof SimpleTestFields
|
|
@@ -1184,8 +1190,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
1184
1190
|
});
|
|
1185
1191
|
|
|
1186
1192
|
it('records metrics appropriately', async () => {
|
|
1187
|
-
const viewerContext = mock<
|
|
1188
|
-
const queryContext = StubQueryContextProvider.
|
|
1193
|
+
const viewerContext = mock<TestViewerContext>();
|
|
1194
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
1189
1195
|
const { entityMutatorFactory, metricsAdapter } = createEntityMutatorFactory([]);
|
|
1190
1196
|
const spiedMetricsAdapter = spy(metricsAdapter);
|
|
1191
1197
|
|
|
@@ -2,11 +2,11 @@ import { anyOfClass, anything, deepEqual, instance, mock, spy, verify, when } fr
|
|
|
2
2
|
|
|
3
3
|
import { EntityNonTransactionalQueryContext } from '../EntityQueryContext';
|
|
4
4
|
import EntitySecondaryCacheLoader, { ISecondaryEntityCache } from '../EntitySecondaryCacheLoader';
|
|
5
|
-
import ViewerContext from '../ViewerContext';
|
|
6
5
|
import SimpleTestEntity, {
|
|
7
6
|
SimpleTestEntityPrivacyPolicy,
|
|
8
7
|
SimpleTestFields,
|
|
9
8
|
} from '../testfixtures/SimpleTestEntity';
|
|
9
|
+
import TestViewerContext from '../testfixtures/TestViewerContext';
|
|
10
10
|
import { createUnitTestEntityCompanionProvider } from '../utils/testing/createUnitTestEntityCompanionProvider';
|
|
11
11
|
|
|
12
12
|
type TestLoadParams = { id: string };
|
|
@@ -15,7 +15,7 @@ class TestSecondaryRedisCacheLoader extends EntitySecondaryCacheLoader<
|
|
|
15
15
|
TestLoadParams,
|
|
16
16
|
SimpleTestFields,
|
|
17
17
|
string,
|
|
18
|
-
|
|
18
|
+
TestViewerContext,
|
|
19
19
|
SimpleTestEntity,
|
|
20
20
|
SimpleTestEntityPrivacyPolicy
|
|
21
21
|
> {
|
|
@@ -30,9 +30,12 @@ class TestSecondaryRedisCacheLoader extends EntitySecondaryCacheLoader<
|
|
|
30
30
|
describe(EntitySecondaryCacheLoader, () => {
|
|
31
31
|
describe('loadManyAsync', () => {
|
|
32
32
|
it('calls into secondary cache with correct params', async () => {
|
|
33
|
-
const vc1 = new
|
|
33
|
+
const vc1 = new TestViewerContext(createUnitTestEntityCompanionProvider());
|
|
34
34
|
|
|
35
|
-
const createdEntity = await SimpleTestEntity.creator(
|
|
35
|
+
const createdEntity = await SimpleTestEntity.creator(
|
|
36
|
+
vc1,
|
|
37
|
+
vc1.getQueryContext()
|
|
38
|
+
).enforceCreateAsync();
|
|
36
39
|
const loadParams = { id: createdEntity.getID() };
|
|
37
40
|
|
|
38
41
|
const secondaryEntityCacheMock =
|
|
@@ -44,7 +47,7 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
44
47
|
|
|
45
48
|
const secondaryCacheLoader = new TestSecondaryRedisCacheLoader(
|
|
46
49
|
secondaryEntityCache,
|
|
47
|
-
SimpleTestEntity.loader(vc1)
|
|
50
|
+
SimpleTestEntity.loader(vc1, vc1.getQueryContext())
|
|
48
51
|
);
|
|
49
52
|
|
|
50
53
|
await secondaryCacheLoader.loadManyAsync([loadParams]);
|
|
@@ -55,9 +58,12 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
55
58
|
});
|
|
56
59
|
|
|
57
60
|
it('constructs and authorizes entities', async () => {
|
|
58
|
-
const vc1 = new
|
|
61
|
+
const vc1 = new TestViewerContext(createUnitTestEntityCompanionProvider());
|
|
59
62
|
|
|
60
|
-
const createdEntity = await SimpleTestEntity.creator(
|
|
63
|
+
const createdEntity = await SimpleTestEntity.creator(
|
|
64
|
+
vc1,
|
|
65
|
+
vc1.getQueryContext()
|
|
66
|
+
).enforceCreateAsync();
|
|
61
67
|
const loadParams = { id: createdEntity.getID() };
|
|
62
68
|
|
|
63
69
|
const secondaryEntityCacheMock =
|
|
@@ -67,7 +73,7 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
67
73
|
).thenResolve(new Map([[loadParams, createdEntity.getAllFields()]]));
|
|
68
74
|
const secondaryEntityCache = instance(secondaryEntityCacheMock);
|
|
69
75
|
|
|
70
|
-
const loader = SimpleTestEntity.loader(vc1);
|
|
76
|
+
const loader = SimpleTestEntity.loader(vc1, vc1.getQueryContext());
|
|
71
77
|
const spiedPrivacyPolicy = spy(loader['privacyPolicy']);
|
|
72
78
|
const secondaryCacheLoader = new TestSecondaryRedisCacheLoader(secondaryEntityCache, loader);
|
|
73
79
|
|
|
@@ -88,15 +94,18 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
88
94
|
|
|
89
95
|
describe('invalidateManyAsync', () => {
|
|
90
96
|
it('calls invalidate on the secondary cache', async () => {
|
|
91
|
-
const vc1 = new
|
|
97
|
+
const vc1 = new TestViewerContext(createUnitTestEntityCompanionProvider());
|
|
92
98
|
|
|
93
|
-
const createdEntity = await SimpleTestEntity.creator(
|
|
99
|
+
const createdEntity = await SimpleTestEntity.creator(
|
|
100
|
+
vc1,
|
|
101
|
+
vc1.getQueryContext()
|
|
102
|
+
).enforceCreateAsync();
|
|
94
103
|
const loadParams = { id: createdEntity.getID() };
|
|
95
104
|
|
|
96
105
|
const secondaryEntityCacheMock =
|
|
97
106
|
mock<ISecondaryEntityCache<SimpleTestFields, TestLoadParams>>();
|
|
98
107
|
const secondaryEntityCache = instance(secondaryEntityCacheMock);
|
|
99
|
-
const loader = SimpleTestEntity.loader(vc1);
|
|
108
|
+
const loader = SimpleTestEntity.loader(vc1, vc1.getQueryContext());
|
|
100
109
|
const secondaryCacheLoader = new TestSecondaryRedisCacheLoader(secondaryEntityCache, loader);
|
|
101
110
|
await secondaryCacheLoader.invalidateManyAsync([loadParams]);
|
|
102
111
|
|