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