@expo/entity 0.38.0 → 0.40.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 +124 -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 +8 -12
- package/build/Entity.js +9 -34
- 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/EntityCompanionProvider.d.ts +2 -2
- package/build/EntityCompanionProvider.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/EntityDatabaseAdapter.js +2 -2
- package/build/EntityDatabaseAdapter.js.map +1 -1
- 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 +2 -2
- package/build/ReadonlyEntity.js +4 -6
- 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 +273 -0
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js.map +1 -0
- package/build/__tests__/{EntityLoader-constructor-test.js → AuthorizationResultBasedEntityLoader-constructor-test.js} +11 -11
- 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 +23 -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 -12
- 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__/EntityDatabaseAdapter-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +41 -23
- 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 +4 -3
- 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 +36 -24
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +1 -1
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +4 -2
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +7 -4
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/__tests__/entityUtils-test.js +8 -0
- package/build/__tests__/entityUtils-test.js.map +1 -1
- package/build/entityUtils.d.ts +7 -0
- package/build/entityUtils.js +20 -10
- package/build/entityUtils.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/EntityFieldTransformationUtils.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.d.ts +32 -4
- package/build/utils/EntityPrivacyUtils.js +68 -24
- package/build/utils/EntityPrivacyUtils.js.map +1 -1
- package/build/utils/__tests__/EntityPrivacyUtils-test.js +148 -23
- package/build/utils/__tests__/EntityPrivacyUtils-test.js.map +1 -1
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js +8 -5
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js.map +1 -1
- package/build/utils/collections/__tests__/maps-test.js +1 -1
- package/build/utils/collections/__tests__/maps-test.js.map +1 -1
- package/build/utils/collections/maps.js +2 -2
- package/build/utils/collections/maps.js.map +1 -1
- package/build/utils/mergeEntityMutationTriggerConfigurations.js +1 -2
- package/build/utils/mergeEntityMutationTriggerConfigurations.js.map +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.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/build/utils/testing/describeFieldTestCase.js +1 -1
- package/build/utils/testing/describeFieldTestCase.js.map +1 -1
- package/package.json +19 -3
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +492 -0
- package/src/AuthorizationResultBasedEntityLoader.ts +2 -2
- 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 +20 -65
- package/src/EntityAssociationLoader.ts +38 -495
- package/src/EntityCompanionProvider.ts +5 -2
- 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 +14 -13
- package/src/ViewerScopedEntityLoaderFactory.ts +9 -2
- package/src/ViewerScopedEntityMutatorFactory.ts +29 -4
- package/src/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.ts +354 -0
- package/src/__tests__/{EntityLoader-constructor-test.ts → AuthorizationResultBasedEntityLoader-constructor-test.ts} +17 -10
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +730 -0
- package/src/__tests__/EnforcingEntityAssociationLoader-test.ts +253 -0
- package/src/__tests__/Entity-test.ts +24 -5
- package/src/__tests__/EntityAssociationLoader-test.ts +16 -259
- package/src/__tests__/EntityCommonUseCases-test.ts +20 -8
- package/src/__tests__/EntityCompanion-test.ts +1 -1
- package/src/__tests__/EntityDatabaseAdapter-test.ts +6 -6
- package/src/__tests__/EntityEdges-test.ts +24 -16
- package/src/__tests__/EntityLoader-test.ts +25 -675
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +4 -3
- package/src/__tests__/EntityMutator-test.ts +116 -103
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +7 -7
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +36 -24
- package/src/__tests__/ReadonlyEntity-test.ts +1 -1
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +4 -2
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +7 -4
- package/src/__tests__/entityUtils-test.ts +12 -0
- package/src/entityUtils.ts +24 -9
- package/src/index.ts +19 -11
- package/src/internal/EntityFieldTransformationUtils.ts +2 -2
- package/src/internal/__tests__/EntityDataManager-test.ts +29 -29
- package/src/utils/EntityPrivacyUtils.ts +188 -107
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +169 -29
- package/src/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.ts +8 -5
- package/src/utils/collections/__tests__/maps-test.ts +1 -1
- package/src/utils/testing/PrivacyPolicyRuleTestUtils.ts +1 -1
- package/src/utils/testing/StubDatabaseAdapter.ts +1 -1
- 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
|
@@ -4,6 +4,7 @@ import EntityConfiguration from '../EntityConfiguration';
|
|
|
4
4
|
import { UUIDField } from '../EntityFields';
|
|
5
5
|
import { EntityMutationType, EntityTriggerMutationInfo } from '../EntityMutationInfo';
|
|
6
6
|
import { EntityNonTransactionalMutationTrigger } from '../EntityMutationTriggerConfiguration';
|
|
7
|
+
import EntityMutatorFactory from '../EntityMutatorFactory';
|
|
7
8
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
8
9
|
import ViewerContext from '../ViewerContext';
|
|
9
10
|
import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
|
|
@@ -87,17 +88,17 @@ class TestNonTransactionalMutationTrigger extends EntityNonTransactionalMutation
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
describe(
|
|
91
|
+
describe(EntityMutatorFactory, () => {
|
|
91
92
|
test('cache consistency with post-commit callbacks', async () => {
|
|
92
93
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
93
94
|
const viewerContext = new ViewerContext(companionProvider);
|
|
94
95
|
|
|
95
96
|
// put it in cache
|
|
96
|
-
const entity = await BlahEntity.creator(viewerContext).
|
|
97
|
+
const entity = await BlahEntity.creator(viewerContext).enforcing().createAsync();
|
|
97
98
|
const entityLoaded = await BlahEntity.loader(viewerContext)
|
|
98
99
|
.enforcing()
|
|
99
100
|
.loadByIDAsync(entity.getID());
|
|
100
101
|
|
|
101
|
-
await BlahEntity.
|
|
102
|
+
await BlahEntity.deleter(entityLoaded).enforcing().deleteAsync();
|
|
102
103
|
});
|
|
103
104
|
});
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
} from 'ts-mockito';
|
|
13
13
|
import { v4 as uuidv4 } from 'uuid';
|
|
14
14
|
|
|
15
|
+
import AuthorizationResultBasedEntityLoader from '../AuthorizationResultBasedEntityLoader';
|
|
15
16
|
import EntityCompanionProvider from '../EntityCompanionProvider';
|
|
16
17
|
import EntityConfiguration from '../EntityConfiguration';
|
|
17
18
|
import EntityDatabaseAdapter from '../EntityDatabaseAdapter';
|
|
18
|
-
import EntityLoader from '../EntityLoader';
|
|
19
19
|
import EntityLoaderFactory from '../EntityLoaderFactory';
|
|
20
20
|
import EntityLoaderUtils from '../EntityLoaderUtils';
|
|
21
21
|
import {
|
|
@@ -315,6 +315,7 @@ const createEntityMutatorFactory = (
|
|
|
315
315
|
const cacheAdapter = cacheAdapterProvider.getCacheAdapter(testEntityConfiguration);
|
|
316
316
|
const entityCache = new ReadThroughEntityCache<TestFields>(testEntityConfiguration, cacheAdapter);
|
|
317
317
|
|
|
318
|
+
const queryContextProvider = new StubQueryContextProvider();
|
|
318
319
|
const companionProvider = new EntityCompanionProvider(
|
|
319
320
|
metricsAdapter,
|
|
320
321
|
new Map([
|
|
@@ -322,7 +323,7 @@ const createEntityMutatorFactory = (
|
|
|
322
323
|
'postgres',
|
|
323
324
|
{
|
|
324
325
|
adapterProvider: customStubDatabaseAdapterProvider,
|
|
325
|
-
queryContextProvider
|
|
326
|
+
queryContextProvider,
|
|
326
327
|
},
|
|
327
328
|
],
|
|
328
329
|
]),
|
|
@@ -339,7 +340,7 @@ const createEntityMutatorFactory = (
|
|
|
339
340
|
const dataManager = new EntityDataManager(
|
|
340
341
|
databaseAdapter,
|
|
341
342
|
entityCache,
|
|
342
|
-
|
|
343
|
+
queryContextProvider,
|
|
343
344
|
metricsAdapter,
|
|
344
345
|
TestEntity.name,
|
|
345
346
|
);
|
|
@@ -373,7 +374,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
373
374
|
describe('forCreate', () => {
|
|
374
375
|
it('creates entities', async () => {
|
|
375
376
|
const viewerContext = mock<ViewerContext>();
|
|
376
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
377
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
377
378
|
|
|
378
379
|
const id1 = uuidv4();
|
|
379
380
|
const id2 = uuidv4();
|
|
@@ -395,16 +396,18 @@ describe(EntityMutatorFactory, () => {
|
|
|
395
396
|
nullableField: null,
|
|
396
397
|
},
|
|
397
398
|
]);
|
|
398
|
-
const newEntity = await
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
399
|
+
const newEntity = await enforceAsyncResult(
|
|
400
|
+
entityMutatorFactory
|
|
401
|
+
.forCreate(viewerContext, queryContext)
|
|
402
|
+
.setField('stringField', 'huh')
|
|
403
|
+
.createAsync(),
|
|
404
|
+
);
|
|
402
405
|
expect(newEntity).toBeTruthy();
|
|
403
406
|
});
|
|
404
407
|
|
|
405
408
|
it('checks privacy', async () => {
|
|
406
409
|
const viewerContext = mock<ViewerContext>();
|
|
407
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
410
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
408
411
|
|
|
409
412
|
const id1 = uuidv4();
|
|
410
413
|
const id2 = uuidv4();
|
|
@@ -429,10 +432,12 @@ describe(EntityMutatorFactory, () => {
|
|
|
429
432
|
|
|
430
433
|
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
431
434
|
|
|
432
|
-
await
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
435
|
+
await enforceAsyncResult(
|
|
436
|
+
entityMutatorFactory
|
|
437
|
+
.forCreate(viewerContext, queryContext)
|
|
438
|
+
.setField('stringField', 'huh')
|
|
439
|
+
.createAsync(),
|
|
440
|
+
);
|
|
436
441
|
|
|
437
442
|
verify(
|
|
438
443
|
spiedPrivacyPolicy.authorizeCreateAsync(
|
|
@@ -447,7 +452,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
447
452
|
|
|
448
453
|
it('executes triggers', async () => {
|
|
449
454
|
const viewerContext = mock<ViewerContext>();
|
|
450
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
455
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
451
456
|
|
|
452
457
|
const id1 = uuidv4();
|
|
453
458
|
const id2 = uuidv4();
|
|
@@ -472,10 +477,12 @@ describe(EntityMutatorFactory, () => {
|
|
|
472
477
|
|
|
473
478
|
const triggerSpies = setUpMutationTriggerSpies(mutationTriggers);
|
|
474
479
|
|
|
475
|
-
await
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
480
|
+
await enforceAsyncResult(
|
|
481
|
+
entityMutatorFactory
|
|
482
|
+
.forCreate(viewerContext, queryContext)
|
|
483
|
+
.setField('stringField', 'huh')
|
|
484
|
+
.createAsync(),
|
|
485
|
+
);
|
|
479
486
|
|
|
480
487
|
verifyTriggerCounts(
|
|
481
488
|
viewerContext,
|
|
@@ -494,7 +501,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
494
501
|
|
|
495
502
|
it('executes validators', async () => {
|
|
496
503
|
const viewerContext = mock<ViewerContext>();
|
|
497
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
504
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
498
505
|
|
|
499
506
|
const id1 = uuidv4();
|
|
500
507
|
const id2 = uuidv4();
|
|
@@ -519,10 +526,12 @@ describe(EntityMutatorFactory, () => {
|
|
|
519
526
|
|
|
520
527
|
const validatorSpies = setUpMutationValidatorSpies(mutationValidators);
|
|
521
528
|
|
|
522
|
-
await
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
529
|
+
await enforceAsyncResult(
|
|
530
|
+
entityMutatorFactory
|
|
531
|
+
.forCreate(viewerContext, queryContext)
|
|
532
|
+
.setField('stringField', 'huh')
|
|
533
|
+
.createAsync(),
|
|
534
|
+
);
|
|
526
535
|
|
|
527
536
|
verifyValidatorCounts(viewerContext, validatorSpies, 1, { type: EntityMutationType.CREATE });
|
|
528
537
|
});
|
|
@@ -543,7 +552,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
543
552
|
>
|
|
544
553
|
>(),
|
|
545
554
|
);
|
|
546
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
555
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
547
556
|
|
|
548
557
|
const id1 = uuidv4();
|
|
549
558
|
const id2 = uuidv4();
|
|
@@ -569,14 +578,15 @@ describe(EntityMutatorFactory, () => {
|
|
|
569
578
|
const existingEntity = await enforceAsyncResult(
|
|
570
579
|
entityLoaderFactory
|
|
571
580
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
572
|
-
.withAuthorizationResults()
|
|
573
581
|
.loadByIDAsync(id2),
|
|
574
582
|
);
|
|
575
583
|
|
|
576
|
-
const updatedEntity = await
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
584
|
+
const updatedEntity = await enforceAsyncResult(
|
|
585
|
+
entityMutatorFactory
|
|
586
|
+
.forUpdate(existingEntity, queryContext)
|
|
587
|
+
.setField('stringField', 'huh2')
|
|
588
|
+
.updateAsync(),
|
|
589
|
+
);
|
|
580
590
|
|
|
581
591
|
expect(updatedEntity).toBeTruthy();
|
|
582
592
|
expect(updatedEntity.getAllFields()).not.toMatchObject(existingEntity.getAllFields());
|
|
@@ -585,7 +595,6 @@ describe(EntityMutatorFactory, () => {
|
|
|
585
595
|
const reloadedEntity = await enforceAsyncResult(
|
|
586
596
|
entityLoaderFactory
|
|
587
597
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
588
|
-
.withAuthorizationResults()
|
|
589
598
|
.loadByIDAsync(id2),
|
|
590
599
|
);
|
|
591
600
|
expect(reloadedEntity.getAllFields()).toMatchObject(updatedEntity.getAllFields());
|
|
@@ -593,7 +602,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
593
602
|
|
|
594
603
|
it('checks privacy', async () => {
|
|
595
604
|
const viewerContext = mock<ViewerContext>();
|
|
596
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
605
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
597
606
|
|
|
598
607
|
const id1 = uuidv4();
|
|
599
608
|
const id2 = uuidv4();
|
|
@@ -622,14 +631,15 @@ describe(EntityMutatorFactory, () => {
|
|
|
622
631
|
const existingEntity = await enforceAsyncResult(
|
|
623
632
|
entityLoaderFactory
|
|
624
633
|
.forLoad(viewerContext, queryContext, { previousValue: null, cascadingDeleteCause: null })
|
|
625
|
-
.withAuthorizationResults()
|
|
626
634
|
.loadByIDAsync(id2),
|
|
627
635
|
);
|
|
628
636
|
|
|
629
|
-
await
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
637
|
+
await enforceAsyncResult(
|
|
638
|
+
entityMutatorFactory
|
|
639
|
+
.forUpdate(existingEntity, queryContext)
|
|
640
|
+
.setField('stringField', 'huh2')
|
|
641
|
+
.updateAsync(),
|
|
642
|
+
);
|
|
633
643
|
|
|
634
644
|
verify(
|
|
635
645
|
spiedPrivacyPolicy.authorizeUpdateAsync(
|
|
@@ -666,7 +676,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
666
676
|
>
|
|
667
677
|
>(),
|
|
668
678
|
);
|
|
669
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
679
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
670
680
|
|
|
671
681
|
const id1 = uuidv4();
|
|
672
682
|
const id2 = uuidv4();
|
|
@@ -695,14 +705,15 @@ describe(EntityMutatorFactory, () => {
|
|
|
695
705
|
const existingEntity = await enforceAsyncResult(
|
|
696
706
|
entityLoaderFactory
|
|
697
707
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
698
|
-
.withAuthorizationResults()
|
|
699
708
|
.loadByIDAsync(id2),
|
|
700
709
|
);
|
|
701
710
|
|
|
702
|
-
await
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
711
|
+
await enforceAsyncResult(
|
|
712
|
+
entityMutatorFactory
|
|
713
|
+
.forUpdate(existingEntity, queryContext)
|
|
714
|
+
.setField('stringField', 'huh2')
|
|
715
|
+
.updateAsync(),
|
|
716
|
+
);
|
|
706
717
|
|
|
707
718
|
verifyTriggerCounts(
|
|
708
719
|
viewerContext,
|
|
@@ -737,7 +748,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
737
748
|
>
|
|
738
749
|
>(),
|
|
739
750
|
);
|
|
740
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
751
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
741
752
|
|
|
742
753
|
const id1 = uuidv4();
|
|
743
754
|
const id2 = uuidv4();
|
|
@@ -766,14 +777,15 @@ describe(EntityMutatorFactory, () => {
|
|
|
766
777
|
const existingEntity = await enforceAsyncResult(
|
|
767
778
|
entityLoaderFactory
|
|
768
779
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
769
|
-
.withAuthorizationResults()
|
|
770
780
|
.loadByIDAsync(id2),
|
|
771
781
|
);
|
|
772
782
|
|
|
773
|
-
await
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
783
|
+
await enforceAsyncResult(
|
|
784
|
+
entityMutatorFactory
|
|
785
|
+
.forUpdate(existingEntity, queryContext)
|
|
786
|
+
.setField('stringField', 'huh2')
|
|
787
|
+
.updateAsync(),
|
|
788
|
+
);
|
|
777
789
|
|
|
778
790
|
verifyValidatorCounts(viewerContext, validatorSpies, 1, {
|
|
779
791
|
type: EntityMutationType.UPDATE,
|
|
@@ -796,7 +808,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
796
808
|
>
|
|
797
809
|
>(),
|
|
798
810
|
);
|
|
799
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
811
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
800
812
|
|
|
801
813
|
const id1 = uuidv4();
|
|
802
814
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
@@ -813,21 +825,21 @@ describe(EntityMutatorFactory, () => {
|
|
|
813
825
|
const existingEntity = await enforceAsyncResult(
|
|
814
826
|
entityLoaderFactory
|
|
815
827
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
816
|
-
.withAuthorizationResults()
|
|
817
828
|
.loadByIDAsync(id1),
|
|
818
829
|
);
|
|
819
830
|
|
|
820
831
|
await expect(
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
832
|
+
enforceAsyncResult(
|
|
833
|
+
entityMutatorFactory
|
|
834
|
+
.forUpdate(existingEntity, queryContext)
|
|
835
|
+
.setField('customIdField', uuidv4())
|
|
836
|
+
.updateAsync(),
|
|
837
|
+
),
|
|
825
838
|
).rejects.toThrow('id field updates not supported: (entityClass = TestEntity)');
|
|
826
839
|
|
|
827
840
|
const reloadedEntity = await enforceAsyncResult(
|
|
828
841
|
entityLoaderFactory
|
|
829
842
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
830
|
-
.withAuthorizationResults()
|
|
831
843
|
.loadByIDAsync(id1),
|
|
832
844
|
);
|
|
833
845
|
expect(reloadedEntity.getAllFields()).toMatchObject(existingEntity.getAllFields());
|
|
@@ -849,7 +861,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
849
861
|
>
|
|
850
862
|
>(),
|
|
851
863
|
);
|
|
852
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
864
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
853
865
|
|
|
854
866
|
const id1 = uuidv4();
|
|
855
867
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
@@ -866,18 +878,18 @@ describe(EntityMutatorFactory, () => {
|
|
|
866
878
|
const existingEntity = await enforceAsyncResult(
|
|
867
879
|
entityLoaderFactory
|
|
868
880
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
869
|
-
.withAuthorizationResults()
|
|
870
881
|
.loadByIDAsync(id1),
|
|
871
882
|
);
|
|
872
883
|
expect(existingEntity).toBeTruthy();
|
|
873
884
|
|
|
874
|
-
await
|
|
885
|
+
await enforceAsyncResult(
|
|
886
|
+
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
|
|
887
|
+
);
|
|
875
888
|
|
|
876
889
|
await expect(
|
|
877
890
|
enforceAsyncResult(
|
|
878
891
|
entityLoaderFactory
|
|
879
892
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
880
|
-
.withAuthorizationResults()
|
|
881
893
|
.loadByIDAsync(id1),
|
|
882
894
|
),
|
|
883
895
|
).rejects.toBeInstanceOf(Error);
|
|
@@ -897,7 +909,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
897
909
|
>
|
|
898
910
|
>(),
|
|
899
911
|
);
|
|
900
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
912
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
901
913
|
|
|
902
914
|
const id1 = uuidv4();
|
|
903
915
|
const { privacyPolicy, entityMutatorFactory, entityLoaderFactory } =
|
|
@@ -917,11 +929,12 @@ describe(EntityMutatorFactory, () => {
|
|
|
917
929
|
const existingEntity = await enforceAsyncResult(
|
|
918
930
|
entityLoaderFactory
|
|
919
931
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
920
|
-
.withAuthorizationResults()
|
|
921
932
|
.loadByIDAsync(id1),
|
|
922
933
|
);
|
|
923
934
|
|
|
924
|
-
await
|
|
935
|
+
await enforceAsyncResult(
|
|
936
|
+
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
|
|
937
|
+
);
|
|
925
938
|
|
|
926
939
|
verify(
|
|
927
940
|
spiedPrivacyPolicy.authorizeDeleteAsync(
|
|
@@ -948,7 +961,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
948
961
|
>
|
|
949
962
|
>(),
|
|
950
963
|
);
|
|
951
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
964
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
952
965
|
|
|
953
966
|
const id1 = uuidv4();
|
|
954
967
|
const { mutationTriggers, entityMutatorFactory, entityLoaderFactory } =
|
|
@@ -968,11 +981,12 @@ describe(EntityMutatorFactory, () => {
|
|
|
968
981
|
const existingEntity = await enforceAsyncResult(
|
|
969
982
|
entityLoaderFactory
|
|
970
983
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
971
|
-
.withAuthorizationResults()
|
|
972
984
|
.loadByIDAsync(id1),
|
|
973
985
|
);
|
|
974
986
|
|
|
975
|
-
await
|
|
987
|
+
await enforceAsyncResult(
|
|
988
|
+
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
|
|
989
|
+
);
|
|
976
990
|
|
|
977
991
|
verifyTriggerCounts(
|
|
978
992
|
viewerContext,
|
|
@@ -1003,7 +1017,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1003
1017
|
>
|
|
1004
1018
|
>(),
|
|
1005
1019
|
);
|
|
1006
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
1020
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
1007
1021
|
|
|
1008
1022
|
const id1 = uuidv4();
|
|
1009
1023
|
const { mutationValidators, entityMutatorFactory, entityLoaderFactory } =
|
|
@@ -1023,11 +1037,12 @@ describe(EntityMutatorFactory, () => {
|
|
|
1023
1037
|
const existingEntity = await enforceAsyncResult(
|
|
1024
1038
|
entityLoaderFactory
|
|
1025
1039
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
1026
|
-
.withAuthorizationResults()
|
|
1027
1040
|
.loadByIDAsync(id1),
|
|
1028
1041
|
);
|
|
1029
1042
|
|
|
1030
|
-
await
|
|
1043
|
+
await enforceAsyncResult(
|
|
1044
|
+
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
|
|
1045
|
+
);
|
|
1031
1046
|
|
|
1032
1047
|
verifyValidatorCounts(viewerContext, validatorSpies, 0, {
|
|
1033
1048
|
type: EntityMutationType.DELETE as any,
|
|
@@ -1049,7 +1064,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1049
1064
|
>
|
|
1050
1065
|
>(),
|
|
1051
1066
|
);
|
|
1052
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
1067
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
1053
1068
|
|
|
1054
1069
|
const id1 = uuidv4();
|
|
1055
1070
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
@@ -1066,7 +1081,6 @@ describe(EntityMutatorFactory, () => {
|
|
|
1066
1081
|
const entites1 = await enforceResultsAsync(
|
|
1067
1082
|
entityLoaderFactory
|
|
1068
1083
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
1069
|
-
.withAuthorizationResults()
|
|
1070
1084
|
.loadManyByFieldEqualingAsync('stringField', 'huh'),
|
|
1071
1085
|
);
|
|
1072
1086
|
expect(entites1).toHaveLength(1);
|
|
@@ -1081,7 +1095,6 @@ describe(EntityMutatorFactory, () => {
|
|
|
1081
1095
|
const entities2 = await enforceResultsAsync(
|
|
1082
1096
|
entityLoaderFactory
|
|
1083
1097
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
1084
|
-
.withAuthorizationResults()
|
|
1085
1098
|
.loadManyByFieldEqualingAsync('stringField', 'huh'),
|
|
1086
1099
|
);
|
|
1087
1100
|
expect(entities2).toHaveLength(2);
|
|
@@ -1089,7 +1102,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1089
1102
|
|
|
1090
1103
|
it('throws error when field not valid', async () => {
|
|
1091
1104
|
const viewerContext = mock<ViewerContext>();
|
|
1092
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
1105
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
1093
1106
|
const id1 = uuidv4();
|
|
1094
1107
|
const { entityMutatorFactory } = createEntityMutatorFactory([
|
|
1095
1108
|
{
|
|
@@ -1109,10 +1122,12 @@ describe(EntityMutatorFactory, () => {
|
|
|
1109
1122
|
.createAsync(),
|
|
1110
1123
|
).rejects.toThrowError('Entity field not valid: TestEntity (stringField = 10)');
|
|
1111
1124
|
|
|
1112
|
-
const createdEntity = await
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1125
|
+
const createdEntity = await enforceAsyncResult(
|
|
1126
|
+
entityMutatorFactory
|
|
1127
|
+
.forCreate(viewerContext, queryContext)
|
|
1128
|
+
.setField('stringField', 'hello')
|
|
1129
|
+
.createAsync(),
|
|
1130
|
+
);
|
|
1116
1131
|
|
|
1117
1132
|
await expect(
|
|
1118
1133
|
entityMutatorFactory
|
|
@@ -1125,7 +1140,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1125
1140
|
it('returns error result when not authorized to create', async () => {
|
|
1126
1141
|
const entityCompanionProvider = instance(mock(EntityCompanionProvider));
|
|
1127
1142
|
const viewerContext = instance(mock(ViewerContext));
|
|
1128
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
1143
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
1129
1144
|
const privacyPolicyMock = mock(SimpleTestEntityPrivacyPolicy);
|
|
1130
1145
|
const databaseAdapter = instance(mock<EntityDatabaseAdapter<SimpleTestFields>>());
|
|
1131
1146
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
@@ -1142,17 +1157,16 @@ describe(EntityMutatorFactory, () => {
|
|
|
1142
1157
|
},
|
|
1143
1158
|
});
|
|
1144
1159
|
|
|
1145
|
-
const entityLoaderMock =
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
>(EntityLoader);
|
|
1160
|
+
const entityLoaderMock = mock<
|
|
1161
|
+
AuthorizationResultBasedEntityLoader<
|
|
1162
|
+
SimpleTestFields,
|
|
1163
|
+
string,
|
|
1164
|
+
ViewerContext,
|
|
1165
|
+
SimpleTestEntity,
|
|
1166
|
+
SimpleTestEntityPrivacyPolicy,
|
|
1167
|
+
keyof SimpleTestFields
|
|
1168
|
+
>
|
|
1169
|
+
>(AuthorizationResultBasedEntityLoader);
|
|
1156
1170
|
const entityLoaderUtilsMock =
|
|
1157
1171
|
mock<
|
|
1158
1172
|
EntityLoaderUtils<
|
|
@@ -1165,7 +1179,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1165
1179
|
>
|
|
1166
1180
|
>(EntityLoaderUtils);
|
|
1167
1181
|
when(entityLoaderUtilsMock.constructEntity(anything())).thenReturn(fakeEntity);
|
|
1168
|
-
when(entityLoaderMock.utils
|
|
1182
|
+
when(entityLoaderMock.utils).thenReturn(instance(entityLoaderUtilsMock));
|
|
1169
1183
|
const entityLoader = instance(entityLoaderMock);
|
|
1170
1184
|
|
|
1171
1185
|
const entityLoaderFactoryMock =
|
|
@@ -1261,7 +1275,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1261
1275
|
const entityCompanionProvider = instance(entityCompanionProviderMock);
|
|
1262
1276
|
|
|
1263
1277
|
const viewerContext = instance(mock(ViewerContext));
|
|
1264
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
1278
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
1265
1279
|
const privacyPolicy = instance(mock(SimpleTestEntityPrivacyPolicy));
|
|
1266
1280
|
const databaseAdapterMock = mock<EntityDatabaseAdapter<SimpleTestFields>>();
|
|
1267
1281
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
@@ -1278,17 +1292,16 @@ describe(EntityMutatorFactory, () => {
|
|
|
1278
1292
|
},
|
|
1279
1293
|
});
|
|
1280
1294
|
|
|
1281
|
-
const entityLoaderMock =
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
>(EntityLoader);
|
|
1295
|
+
const entityLoaderMock = mock<
|
|
1296
|
+
AuthorizationResultBasedEntityLoader<
|
|
1297
|
+
SimpleTestFields,
|
|
1298
|
+
string,
|
|
1299
|
+
ViewerContext,
|
|
1300
|
+
SimpleTestEntity,
|
|
1301
|
+
SimpleTestEntityPrivacyPolicy,
|
|
1302
|
+
keyof SimpleTestFields
|
|
1303
|
+
>
|
|
1304
|
+
>(AuthorizationResultBasedEntityLoader);
|
|
1292
1305
|
const entityLoaderUtilsMock =
|
|
1293
1306
|
mock<
|
|
1294
1307
|
EntityLoaderUtils<
|
|
@@ -1301,7 +1314,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1301
1314
|
>
|
|
1302
1315
|
>(EntityLoaderUtils);
|
|
1303
1316
|
when(entityLoaderUtilsMock.constructEntity(anything())).thenReturn(fakeEntity);
|
|
1304
|
-
when(entityLoaderMock.utils
|
|
1317
|
+
when(entityLoaderMock.utils).thenReturn(instance(entityLoaderUtilsMock));
|
|
1305
1318
|
const entityLoader = instance(entityLoaderMock);
|
|
1306
1319
|
|
|
1307
1320
|
const entityLoaderFactoryMock =
|
|
@@ -1370,7 +1383,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1370
1383
|
|
|
1371
1384
|
it('records metrics appropriately', async () => {
|
|
1372
1385
|
const viewerContext = mock<ViewerContext>();
|
|
1373
|
-
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
1386
|
+
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
1374
1387
|
const { entityMutatorFactory, metricsAdapter } = createEntityMutatorFactory([]);
|
|
1375
1388
|
const spiedMetricsAdapter = spy(metricsAdapter);
|
|
1376
1389
|
|
|
@@ -32,7 +32,7 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
32
32
|
it('calls into secondary cache with correct params', async () => {
|
|
33
33
|
const vc1 = new ViewerContext(createUnitTestEntityCompanionProvider());
|
|
34
34
|
|
|
35
|
-
const createdEntity = await SimpleTestEntity.creator(vc1).
|
|
35
|
+
const createdEntity = await SimpleTestEntity.creator(vc1).enforcing().createAsync();
|
|
36
36
|
const loadParams = { id: createdEntity.getID() };
|
|
37
37
|
|
|
38
38
|
const secondaryEntityCacheMock =
|
|
@@ -44,7 +44,7 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
44
44
|
|
|
45
45
|
const secondaryCacheLoader = new TestSecondaryRedisCacheLoader(
|
|
46
46
|
secondaryEntityCache,
|
|
47
|
-
SimpleTestEntity.loader(vc1),
|
|
47
|
+
SimpleTestEntity.loader(vc1).withAuthorizationResults(),
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
await secondaryCacheLoader.loadManyAsync([loadParams]);
|
|
@@ -57,7 +57,7 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
57
57
|
it('constructs and authorizes entities', async () => {
|
|
58
58
|
const vc1 = new ViewerContext(createUnitTestEntityCompanionProvider());
|
|
59
59
|
|
|
60
|
-
const createdEntity = await SimpleTestEntity.creator(vc1).
|
|
60
|
+
const createdEntity = await SimpleTestEntity.creator(vc1).enforcing().createAsync();
|
|
61
61
|
const loadParams = { id: createdEntity.getID() };
|
|
62
62
|
|
|
63
63
|
const secondaryEntityCacheMock =
|
|
@@ -67,8 +67,8 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
67
67
|
).thenResolve(new Map([[loadParams, createdEntity.getAllFields()]]));
|
|
68
68
|
const secondaryEntityCache = instance(secondaryEntityCacheMock);
|
|
69
69
|
|
|
70
|
-
const loader = SimpleTestEntity.loader(vc1);
|
|
71
|
-
const spiedPrivacyPolicy = spy(loader['privacyPolicy']);
|
|
70
|
+
const loader = SimpleTestEntity.loader(vc1).withAuthorizationResults();
|
|
71
|
+
const spiedPrivacyPolicy = spy(loader.utils['privacyPolicy']);
|
|
72
72
|
const secondaryCacheLoader = new TestSecondaryRedisCacheLoader(secondaryEntityCache, loader);
|
|
73
73
|
|
|
74
74
|
const result = await secondaryCacheLoader.loadManyAsync([loadParams]);
|
|
@@ -90,13 +90,13 @@ describe(EntitySecondaryCacheLoader, () => {
|
|
|
90
90
|
it('calls invalidate on the secondary cache', async () => {
|
|
91
91
|
const vc1 = new ViewerContext(createUnitTestEntityCompanionProvider());
|
|
92
92
|
|
|
93
|
-
const createdEntity = await SimpleTestEntity.creator(vc1).
|
|
93
|
+
const createdEntity = await SimpleTestEntity.creator(vc1).enforcing().createAsync();
|
|
94
94
|
const loadParams = { id: createdEntity.getID() };
|
|
95
95
|
|
|
96
96
|
const secondaryEntityCacheMock =
|
|
97
97
|
mock<ISecondaryEntityCache<SimpleTestFields, TestLoadParams>>();
|
|
98
98
|
const secondaryEntityCache = instance(secondaryEntityCacheMock);
|
|
99
|
-
const loader = SimpleTestEntity.loader(vc1);
|
|
99
|
+
const loader = SimpleTestEntity.loader(vc1).withAuthorizationResults();
|
|
100
100
|
const secondaryCacheLoader = new TestSecondaryRedisCacheLoader(secondaryEntityCache, loader);
|
|
101
101
|
await secondaryCacheLoader.invalidateManyAsync([loadParams]);
|
|
102
102
|
|