@expo/entity 0.16.0 → 0.20.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.js +2 -2
- package/build/EnforcingEntityLoader.js.map +1 -1
- package/build/Entity.js +8 -2
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.js +3 -3
- package/build/EntityAssociationLoader.js.map +1 -1
- package/build/EntityCompanion.d.ts +5 -0
- package/build/EntityCompanion.js +8 -1
- package/build/EntityCompanion.js.map +1 -1
- package/build/EntityCompanionProvider.d.ts +1 -1
- package/build/EntityCompanionProvider.js +5 -5
- package/build/EntityCompanionProvider.js.map +1 -1
- package/build/EntityConfiguration.d.ts +1 -1
- package/build/EntityConfiguration.js +3 -3
- package/build/EntityConfiguration.js.map +1 -1
- package/build/EntityDatabaseAdapter.d.ts +4 -4
- package/build/EntityDatabaseAdapter.js +13 -13
- package/build/EntityDatabaseAdapter.js.map +1 -1
- package/build/EntityFieldDefinition.d.ts +77 -0
- package/build/EntityFieldDefinition.js +53 -0
- package/build/EntityFieldDefinition.js.map +1 -0
- package/build/EntityFields.d.ts +5 -78
- package/build/EntityFields.js +19 -61
- package/build/EntityFields.js.map +1 -1
- package/build/EntityLoader.d.ts +3 -1
- package/build/EntityLoader.js +19 -15
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityLoaderFactory.d.ts +3 -1
- package/build/EntityLoaderFactory.js +3 -2
- package/build/EntityLoaderFactory.js.map +1 -1
- package/build/EntityMutationInfo.d.ts +26 -0
- package/build/EntityMutationInfo.js +10 -0
- package/build/EntityMutationInfo.js.map +1 -0
- package/build/EntityMutationTriggerConfiguration.d.ts +4 -4
- package/build/EntityMutationValidator.d.ts +3 -3
- package/build/EntityMutationValidator.js.map +1 -1
- package/build/EntityMutator.d.ts +5 -16
- package/build/EntityMutator.js +62 -58
- package/build/EntityMutator.js.map +1 -1
- package/build/EntityPrivacyPolicy.d.ts +5 -4
- package/build/EntityPrivacyPolicy.js +60 -12
- package/build/EntityPrivacyPolicy.js.map +1 -1
- package/build/EntityQueryContext.d.ts +13 -0
- package/build/EntityQueryContext.js +18 -0
- package/build/EntityQueryContext.js.map +1 -1
- package/build/EntitySecondaryCacheLoader.js +2 -2
- package/build/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/ReadonlyEntity.js +3 -4
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerScopedEntityCompanion.d.ts +5 -0
- package/build/ViewerScopedEntityCompanion.js +6 -0
- package/build/ViewerScopedEntityCompanion.js.map +1 -1
- package/build/__tests__/EnforcingEntityLoader-test.js +82 -82
- package/build/__tests__/EnforcingEntityLoader-test.js.map +1 -1
- package/build/__tests__/Entity-test.js +6 -6
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +40 -40
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +11 -11
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityCompanion-test.js +3 -3
- package/build/__tests__/EntityCompanion-test.js.map +1 -1
- package/build/__tests__/EntityCompanionProvider-test.js +1 -1
- package/build/__tests__/EntityCompanionProvider-test.js.map +1 -1
- package/build/__tests__/EntityDatabaseAdapter-test.js +12 -12
- package/build/__tests__/EntityDatabaseAdapter-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +103 -6
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityFields-test.js +18 -26
- package/build/__tests__/EntityFields-test.js.map +1 -1
- package/build/__tests__/EntityLoader-constructor-test.d.ts +22 -0
- package/build/__tests__/EntityLoader-constructor-test.js +111 -0
- package/build/__tests__/EntityLoader-constructor-test.js.map +1 -0
- package/build/__tests__/EntityLoader-test.js +81 -73
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.d.ts +1 -0
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +81 -0
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -0
- package/build/__tests__/EntityMutator-test.js +138 -136
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +143 -67
- package/build/__tests__/EntityPrivacyPolicy-test.js.map +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +15 -15
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +13 -12
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +12 -12
- 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__/ViewerScopedEntityCompanion-test.js +2 -2
- package/build/__tests__/ViewerScopedEntityCompanion-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js +2 -2
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.js +5 -5
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js +5 -5
- package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +5 -5
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +2 -2
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/__tests__/entityUtils-test.js +21 -21
- package/build/__tests__/entityUtils-test.js.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.js +5 -1
- package/build/index.js.map +1 -1
- package/build/internal/EntityDataManager.js +8 -7
- package/build/internal/EntityDataManager.js.map +1 -1
- package/build/internal/EntityFieldTransformationUtils.js +2 -2
- package/build/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/internal/ReadThroughEntityCache.js +4 -4
- package/build/internal/ReadThroughEntityCache.js.map +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js +21 -21
- package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js +8 -8
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js.map +1 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.js +48 -48
- package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +1 -1
- package/build/metrics/EntityMetricsUtils.js +1 -1
- package/build/metrics/EntityMetricsUtils.js.map +1 -1
- package/build/metrics/IEntityMetricsAdapter.d.ts +16 -0
- package/build/metrics/IEntityMetricsAdapter.js +6 -1
- package/build/metrics/IEntityMetricsAdapter.js.map +1 -1
- package/build/metrics/NoOpEntityMetricsAdapter.d.ts +2 -1
- package/build/metrics/NoOpEntityMetricsAdapter.js +1 -0
- package/build/metrics/NoOpEntityMetricsAdapter.js.map +1 -1
- package/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.js +4 -4
- package/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.js.map +1 -1
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.js +4 -4
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.js.map +1 -1
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.js +4 -4
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.js.map +1 -1
- package/build/testfixtures/DateIDTestEntity.js.map +1 -1
- package/build/testfixtures/SimpleTestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity.d.ts +6 -6
- package/build/testfixtures/TestEntity.js +4 -4
- package/build/testfixtures/TestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity2.d.ts +5 -5
- package/build/testfixtures/TestEntity2.js.map +1 -1
- package/build/testfixtures/TestEntityNumberKey.js +1 -1
- package/build/testfixtures/TestEntityNumberKey.js.map +1 -1
- package/build/utils/collections/__tests__/maps-test.js +13 -13
- package/build/utils/collections/__tests__/maps-test.js.map +1 -1
- package/build/utils/collections/maps.js +1 -1
- package/build/utils/collections/maps.js.map +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.d.ts +6 -6
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js.map +1 -1
- package/build/utils/testing/StubCacheAdapter.js +1 -1
- package/build/utils/testing/StubCacheAdapter.js.map +1 -1
- package/build/utils/testing/StubDatabaseAdapter.js +7 -7
- package/build/utils/testing/StubDatabaseAdapter.js.map +1 -1
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js +26 -26
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js.map +1 -1
- package/build/utils/testing/describeFieldTestCase.d.ts +2 -0
- package/build/utils/testing/describeFieldTestCase.js +18 -0
- package/build/utils/testing/describeFieldTestCase.js.map +1 -0
- package/package.json +2 -1
- package/src/Entity.ts +10 -2
- package/src/EntityAssociationLoader.ts +1 -1
- package/src/EntityCompanion.ts +10 -2
- package/src/EntityCompanionProvider.ts +5 -9
- package/src/EntityConfiguration.ts +1 -1
- package/src/EntityDatabaseAdapter.ts +10 -8
- package/src/EntityFieldDefinition.ts +124 -0
- package/src/EntityFields.ts +11 -126
- package/src/EntityLoader.ts +12 -4
- package/src/EntityLoaderFactory.ts +5 -2
- package/src/EntityMutationInfo.ts +47 -0
- package/src/EntityMutationTriggerConfiguration.ts +5 -5
- package/src/EntityMutationValidator.ts +10 -4
- package/src/EntityMutator.ts +98 -76
- package/src/EntityPrivacyPolicy.ts +77 -19
- package/src/EntityQueryContext.ts +20 -0
- package/src/ReadonlyEntity.ts +3 -2
- package/src/ViewerScopedEntityCompanion.ts +8 -0
- package/src/__tests__/Entity-test.ts +8 -8
- package/src/__tests__/EntityCommonUseCases-test.ts +4 -4
- package/src/__tests__/EntityEdges-test.ts +169 -14
- package/src/__tests__/EntityFields-test.ts +6 -23
- package/src/__tests__/EntityLoader-constructor-test.ts +177 -0
- package/src/__tests__/EntityLoader-test.ts +48 -20
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +105 -0
- package/src/__tests__/EntityMutator-test.ts +153 -146
- package/src/__tests__/EntityPrivacyPolicy-test.ts +215 -78
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +7 -9
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +6 -5
- package/src/__tests__/ReadonlyEntity-test.ts +1 -1
- package/src/__tests__/ViewerContext-test.ts +7 -6
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +11 -10
- package/src/__tests__/ViewerScopedEntityMutatorFactory-test.ts +4 -3
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +6 -6
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +4 -4
- package/src/index.ts +3 -0
- package/src/internal/EntityDataManager.ts +2 -1
- package/src/internal/__tests__/EntityDataManager-test.ts +6 -6
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +15 -13
- package/src/metrics/EntityMetricsUtils.ts +56 -50
- package/src/metrics/IEntityMetricsAdapter.ts +23 -0
- package/src/metrics/NoOpEntityMetricsAdapter.ts +2 -0
- package/src/testfixtures/DateIDTestEntity.ts +4 -4
- package/src/testfixtures/SimpleTestEntity.ts +4 -4
- package/src/testfixtures/TestEntity.ts +8 -8
- package/src/testfixtures/TestEntity2.ts +4 -4
- package/src/testfixtures/TestEntityNumberKey.ts +6 -6
- package/src/utils/testing/StubDatabaseAdapter.ts +4 -4
- package/src/utils/testing/__tests__/StubDatabaseAdapter-test.ts +18 -18
- package/src/utils/testing/describeFieldTestCase.ts +21 -0
- package/CHANGELOG.md +0 -241
|
@@ -26,8 +26,8 @@ const results_1 = require("@expo/results");
|
|
|
26
26
|
const ts_mockito_1 = require("ts-mockito");
|
|
27
27
|
const uuid_1 = require("uuid");
|
|
28
28
|
const EntityLoaderFactory_1 = __importDefault(require("../EntityLoaderFactory"));
|
|
29
|
+
const EntityMutationInfo_1 = require("../EntityMutationInfo");
|
|
29
30
|
const EntityMutationTriggerConfiguration_1 = require("../EntityMutationTriggerConfiguration");
|
|
30
|
-
const EntityMutator_1 = require("../EntityMutator");
|
|
31
31
|
const EntityMutatorFactory_1 = __importDefault(require("../EntityMutatorFactory"));
|
|
32
32
|
const EntityQueryContext_1 = require("../EntityQueryContext");
|
|
33
33
|
const ViewerContext_1 = __importDefault(require("../ViewerContext"));
|
|
@@ -48,38 +48,38 @@ class TestNonTransactionalMutationTrigger extends EntityMutationTriggerConfigura
|
|
|
48
48
|
async executeAsync(_viewerContext, _entity) { }
|
|
49
49
|
}
|
|
50
50
|
const setUpMutationValidatorSpies = (mutationValidators) => {
|
|
51
|
-
return mutationValidators.map((validator) => ts_mockito_1.spy(validator));
|
|
51
|
+
return mutationValidators.map((validator) => (0, ts_mockito_1.spy)(validator));
|
|
52
52
|
};
|
|
53
53
|
const verifyValidatorCounts = (viewerContext, mutationValidatorSpies, expectedCalls, mutationInfo) => {
|
|
54
54
|
for (const validator of mutationValidatorSpies) {
|
|
55
|
-
ts_mockito_1.verify(validator.executeAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default), ts_mockito_1.deepEqual(mutationInfo))).times(expectedCalls);
|
|
55
|
+
(0, ts_mockito_1.verify)(validator.executeAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.deepEqual)(mutationInfo))).times(expectedCalls);
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
const setUpMutationTriggerSpies = (mutationTriggers) => {
|
|
59
59
|
return {
|
|
60
|
-
beforeCreate: [ts_mockito_1.spy(mutationTriggers.beforeCreate[0])],
|
|
61
|
-
afterCreate: [ts_mockito_1.spy(mutationTriggers.afterCreate[0])],
|
|
62
|
-
beforeUpdate: [ts_mockito_1.spy(mutationTriggers.beforeUpdate[0])],
|
|
63
|
-
afterUpdate: [ts_mockito_1.spy(mutationTriggers.afterUpdate[0])],
|
|
64
|
-
beforeDelete: [ts_mockito_1.spy(mutationTriggers.beforeDelete[0])],
|
|
65
|
-
afterDelete: [ts_mockito_1.spy(mutationTriggers.afterDelete[0])],
|
|
66
|
-
beforeAll: [ts_mockito_1.spy(mutationTriggers.beforeAll[0])],
|
|
67
|
-
afterAll: [ts_mockito_1.spy(mutationTriggers.afterAll[0])],
|
|
68
|
-
afterCommit: [ts_mockito_1.spy(mutationTriggers.afterCommit[0])],
|
|
60
|
+
beforeCreate: [(0, ts_mockito_1.spy)(mutationTriggers.beforeCreate[0])],
|
|
61
|
+
afterCreate: [(0, ts_mockito_1.spy)(mutationTriggers.afterCreate[0])],
|
|
62
|
+
beforeUpdate: [(0, ts_mockito_1.spy)(mutationTriggers.beforeUpdate[0])],
|
|
63
|
+
afterUpdate: [(0, ts_mockito_1.spy)(mutationTriggers.afterUpdate[0])],
|
|
64
|
+
beforeDelete: [(0, ts_mockito_1.spy)(mutationTriggers.beforeDelete[0])],
|
|
65
|
+
afterDelete: [(0, ts_mockito_1.spy)(mutationTriggers.afterDelete[0])],
|
|
66
|
+
beforeAll: [(0, ts_mockito_1.spy)(mutationTriggers.beforeAll[0])],
|
|
67
|
+
afterAll: [(0, ts_mockito_1.spy)(mutationTriggers.afterAll[0])],
|
|
68
|
+
afterCommit: [(0, ts_mockito_1.spy)(mutationTriggers.afterCommit[0])],
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
const verifyTriggerCounts = (viewerContext, mutationTriggerSpies, executed, mutationInfo) => {
|
|
72
72
|
Object.keys(executed).forEach((s) => {
|
|
73
73
|
if (executed[s]) {
|
|
74
|
-
ts_mockito_1.verify(mutationTriggerSpies[s][0].executeAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default), ts_mockito_1.deepEqual(mutationInfo))).once();
|
|
74
|
+
(0, ts_mockito_1.verify)(mutationTriggerSpies[s][0].executeAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.deepEqual)(mutationInfo))).once();
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
|
-
ts_mockito_1.verify(mutationTriggerSpies[s][0].executeAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default), ts_mockito_1.deepEqual(mutationInfo))).never();
|
|
77
|
+
(0, ts_mockito_1.verify)(mutationTriggerSpies[s][0].executeAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.deepEqual)(mutationInfo))).never();
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
ts_mockito_1.verify(mutationTriggerSpies.beforeAll[0].executeAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default), ts_mockito_1.deepEqual(mutationInfo))).once();
|
|
81
|
-
ts_mockito_1.verify(mutationTriggerSpies.afterAll[0].executeAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default), ts_mockito_1.deepEqual(mutationInfo))).once();
|
|
82
|
-
ts_mockito_1.verify(mutationTriggerSpies.afterCommit[0].executeAsync(viewerContext, ts_mockito_1.anyOfClass(TestEntity_1.default), ts_mockito_1.deepEqual(mutationInfo))).once();
|
|
80
|
+
(0, ts_mockito_1.verify)(mutationTriggerSpies.beforeAll[0].executeAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.deepEqual)(mutationInfo))).once();
|
|
81
|
+
(0, ts_mockito_1.verify)(mutationTriggerSpies.afterAll[0].executeAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.deepEqual)(mutationInfo))).once();
|
|
82
|
+
(0, ts_mockito_1.verify)(mutationTriggerSpies.afterCommit[0].executeAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.deepEqual)(mutationInfo))).once();
|
|
83
83
|
};
|
|
84
84
|
const createEntityMutatorFactory = (existingObjects) => {
|
|
85
85
|
const mutationValidators = [new TestMutationTrigger()];
|
|
@@ -101,7 +101,7 @@ const createEntityMutatorFactory = (existingObjects) => {
|
|
|
101
101
|
const cacheAdapter = cacheAdapterProvider.getCacheAdapter(TestEntity_1.testEntityConfiguration);
|
|
102
102
|
const entityCache = new ReadThroughEntityCache_1.default(TestEntity_1.testEntityConfiguration, cacheAdapter);
|
|
103
103
|
const dataManager = new EntityDataManager_1.default(databaseAdapter, entityCache, StubQueryContextProvider_1.default, metricsAdapter, TestEntity_1.default.name);
|
|
104
|
-
const entityLoaderFactory = new EntityLoaderFactory_1.default(TestEntity_1.testEntityConfiguration, TestEntity_1.default, privacyPolicy, dataManager);
|
|
104
|
+
const entityLoaderFactory = new EntityLoaderFactory_1.default(TestEntity_1.testEntityConfiguration, TestEntity_1.default, privacyPolicy, dataManager, metricsAdapter);
|
|
105
105
|
const entityMutatorFactory = new EntityMutatorFactory_1.default(TestEntity_1.testEntityConfiguration, TestEntity_1.default, privacyPolicy, mutationValidators, mutationTriggers, entityLoaderFactory, databaseAdapter, metricsAdapter);
|
|
106
106
|
return {
|
|
107
107
|
privacyPolicy,
|
|
@@ -115,16 +115,16 @@ const createEntityMutatorFactory = (existingObjects) => {
|
|
|
115
115
|
describe(EntityMutatorFactory_1.default, () => {
|
|
116
116
|
describe('forCreate', () => {
|
|
117
117
|
it('creates entities', async () => {
|
|
118
|
-
const viewerContext = ts_mockito_1.mock();
|
|
118
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
119
119
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
120
|
-
const id1 = uuid_1.v4();
|
|
121
|
-
const id2 = uuid_1.v4();
|
|
120
|
+
const id1 = (0, uuid_1.v4)();
|
|
121
|
+
const id2 = (0, uuid_1.v4)();
|
|
122
122
|
const { entityMutatorFactory } = createEntityMutatorFactory([
|
|
123
123
|
{
|
|
124
124
|
customIdField: id1,
|
|
125
125
|
stringField: 'huh',
|
|
126
126
|
testIndexedField: '4',
|
|
127
|
-
|
|
127
|
+
intField: 1,
|
|
128
128
|
dateField: new Date(),
|
|
129
129
|
nullableField: null,
|
|
130
130
|
},
|
|
@@ -132,7 +132,7 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
132
132
|
customIdField: id2,
|
|
133
133
|
stringField: 'huh',
|
|
134
134
|
testIndexedField: '5',
|
|
135
|
-
|
|
135
|
+
intField: 1,
|
|
136
136
|
dateField: new Date(),
|
|
137
137
|
nullableField: null,
|
|
138
138
|
},
|
|
@@ -144,16 +144,16 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
144
144
|
expect(newEntity).toBeTruthy();
|
|
145
145
|
});
|
|
146
146
|
it('checks privacy', async () => {
|
|
147
|
-
const viewerContext = ts_mockito_1.mock();
|
|
147
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
148
148
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
149
|
-
const id1 = uuid_1.v4();
|
|
150
|
-
const id2 = uuid_1.v4();
|
|
149
|
+
const id1 = (0, uuid_1.v4)();
|
|
150
|
+
const id2 = (0, uuid_1.v4)();
|
|
151
151
|
const { privacyPolicy, entityMutatorFactory } = createEntityMutatorFactory([
|
|
152
152
|
{
|
|
153
153
|
customIdField: id1,
|
|
154
154
|
stringField: 'huh',
|
|
155
155
|
testIndexedField: '4',
|
|
156
|
-
|
|
156
|
+
intField: 1,
|
|
157
157
|
dateField: new Date(),
|
|
158
158
|
nullableField: null,
|
|
159
159
|
},
|
|
@@ -161,29 +161,29 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
161
161
|
customIdField: id2,
|
|
162
162
|
stringField: 'huh',
|
|
163
163
|
testIndexedField: '5',
|
|
164
|
-
|
|
164
|
+
intField: 1,
|
|
165
165
|
dateField: new Date(),
|
|
166
166
|
nullableField: null,
|
|
167
167
|
},
|
|
168
168
|
]);
|
|
169
|
-
const spiedPrivacyPolicy = ts_mockito_1.spy(privacyPolicy);
|
|
169
|
+
const spiedPrivacyPolicy = (0, ts_mockito_1.spy)(privacyPolicy);
|
|
170
170
|
await entityMutatorFactory
|
|
171
171
|
.forCreate(viewerContext, queryContext)
|
|
172
172
|
.setField('stringField', 'huh')
|
|
173
173
|
.enforceCreateAsync();
|
|
174
|
-
ts_mockito_1.verify(spiedPrivacyPolicy.authorizeCreateAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default))).once();
|
|
174
|
+
(0, ts_mockito_1.verify)(spiedPrivacyPolicy.authorizeCreateAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.anything)())).once();
|
|
175
175
|
});
|
|
176
176
|
it('executes triggers', async () => {
|
|
177
|
-
const viewerContext = ts_mockito_1.mock();
|
|
177
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
178
178
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
179
|
-
const id1 = uuid_1.v4();
|
|
180
|
-
const id2 = uuid_1.v4();
|
|
179
|
+
const id1 = (0, uuid_1.v4)();
|
|
180
|
+
const id2 = (0, uuid_1.v4)();
|
|
181
181
|
const { mutationTriggers, entityMutatorFactory } = createEntityMutatorFactory([
|
|
182
182
|
{
|
|
183
183
|
customIdField: id1,
|
|
184
184
|
stringField: 'huh',
|
|
185
185
|
testIndexedField: '4',
|
|
186
|
-
|
|
186
|
+
intField: 1,
|
|
187
187
|
dateField: new Date(),
|
|
188
188
|
nullableField: null,
|
|
189
189
|
},
|
|
@@ -191,7 +191,7 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
191
191
|
customIdField: id2,
|
|
192
192
|
stringField: 'huh',
|
|
193
193
|
testIndexedField: '5',
|
|
194
|
-
|
|
194
|
+
intField: 1,
|
|
195
195
|
dateField: new Date(),
|
|
196
196
|
nullableField: null,
|
|
197
197
|
},
|
|
@@ -208,19 +208,19 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
208
208
|
afterUpdate: false,
|
|
209
209
|
beforeDelete: false,
|
|
210
210
|
afterDelete: false,
|
|
211
|
-
}, { type:
|
|
211
|
+
}, { type: EntityMutationInfo_1.EntityMutationType.CREATE });
|
|
212
212
|
});
|
|
213
213
|
it('executes validators', async () => {
|
|
214
|
-
const viewerContext = ts_mockito_1.mock();
|
|
214
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
215
215
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
216
|
-
const id1 = uuid_1.v4();
|
|
217
|
-
const id2 = uuid_1.v4();
|
|
216
|
+
const id1 = (0, uuid_1.v4)();
|
|
217
|
+
const id2 = (0, uuid_1.v4)();
|
|
218
218
|
const { mutationValidators, entityMutatorFactory } = createEntityMutatorFactory([
|
|
219
219
|
{
|
|
220
220
|
customIdField: id1,
|
|
221
221
|
stringField: 'huh',
|
|
222
222
|
testIndexedField: '4',
|
|
223
|
-
|
|
223
|
+
intField: 1,
|
|
224
224
|
dateField: new Date(),
|
|
225
225
|
nullableField: null,
|
|
226
226
|
},
|
|
@@ -228,7 +228,7 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
228
228
|
customIdField: id2,
|
|
229
229
|
stringField: 'huh',
|
|
230
230
|
testIndexedField: '5',
|
|
231
|
-
|
|
231
|
+
intField: 1,
|
|
232
232
|
dateField: new Date(),
|
|
233
233
|
nullableField: null,
|
|
234
234
|
},
|
|
@@ -238,21 +238,21 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
238
238
|
.forCreate(viewerContext, queryContext)
|
|
239
239
|
.setField('stringField', 'huh')
|
|
240
240
|
.enforceCreateAsync();
|
|
241
|
-
verifyValidatorCounts(viewerContext, validatorSpies, 1, { type:
|
|
241
|
+
verifyValidatorCounts(viewerContext, validatorSpies, 1, { type: EntityMutationInfo_1.EntityMutationType.CREATE });
|
|
242
242
|
});
|
|
243
243
|
});
|
|
244
244
|
describe('forUpdate', () => {
|
|
245
245
|
it('updates entities', async () => {
|
|
246
|
-
const viewerContext = ts_mockito_1.mock();
|
|
246
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
247
247
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
248
|
-
const id1 = uuid_1.v4();
|
|
249
|
-
const id2 = uuid_1.v4();
|
|
248
|
+
const id1 = (0, uuid_1.v4)();
|
|
249
|
+
const id2 = (0, uuid_1.v4)();
|
|
250
250
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
251
251
|
{
|
|
252
252
|
customIdField: id1,
|
|
253
253
|
stringField: 'huh',
|
|
254
254
|
testIndexedField: '3',
|
|
255
|
-
|
|
255
|
+
intField: 3,
|
|
256
256
|
dateField: new Date(),
|
|
257
257
|
nullableField: null,
|
|
258
258
|
},
|
|
@@ -260,12 +260,12 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
260
260
|
customIdField: id2,
|
|
261
261
|
stringField: 'huh',
|
|
262
262
|
testIndexedField: '4',
|
|
263
|
-
|
|
263
|
+
intField: 3,
|
|
264
264
|
dateField: new Date(),
|
|
265
265
|
nullableField: null,
|
|
266
266
|
},
|
|
267
267
|
]);
|
|
268
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
268
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
269
269
|
const updatedEntity = await entityMutatorFactory
|
|
270
270
|
.forUpdate(existingEntity, queryContext)
|
|
271
271
|
.setField('stringField', 'huh2')
|
|
@@ -273,20 +273,20 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
273
273
|
expect(updatedEntity).toBeTruthy();
|
|
274
274
|
expect(updatedEntity.getAllFields()).not.toMatchObject(existingEntity.getAllFields());
|
|
275
275
|
expect(updatedEntity.getField('stringField')).toEqual('huh2');
|
|
276
|
-
const reloadedEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
276
|
+
const reloadedEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
277
277
|
expect(reloadedEntity.getAllFields()).toMatchObject(updatedEntity.getAllFields());
|
|
278
278
|
});
|
|
279
279
|
it('checks privacy', async () => {
|
|
280
|
-
const viewerContext = ts_mockito_1.mock();
|
|
280
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
281
281
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
282
|
-
const id1 = uuid_1.v4();
|
|
283
|
-
const id2 = uuid_1.v4();
|
|
284
|
-
const { privacyPolicy, entityMutatorFactory, entityLoaderFactory
|
|
282
|
+
const id1 = (0, uuid_1.v4)();
|
|
283
|
+
const id2 = (0, uuid_1.v4)();
|
|
284
|
+
const { privacyPolicy, entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
285
285
|
{
|
|
286
286
|
customIdField: id1,
|
|
287
287
|
stringField: 'huh',
|
|
288
288
|
testIndexedField: '3',
|
|
289
|
-
|
|
289
|
+
intField: 3,
|
|
290
290
|
dateField: new Date(),
|
|
291
291
|
nullableField: null,
|
|
292
292
|
},
|
|
@@ -294,30 +294,30 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
294
294
|
customIdField: id2,
|
|
295
295
|
stringField: 'huh',
|
|
296
296
|
testIndexedField: '4',
|
|
297
|
-
|
|
297
|
+
intField: 3,
|
|
298
298
|
dateField: new Date(),
|
|
299
299
|
nullableField: null,
|
|
300
300
|
},
|
|
301
301
|
]);
|
|
302
|
-
const spiedPrivacyPolicy = ts_mockito_1.spy(privacyPolicy);
|
|
303
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
302
|
+
const spiedPrivacyPolicy = (0, ts_mockito_1.spy)(privacyPolicy);
|
|
303
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
304
304
|
await entityMutatorFactory
|
|
305
305
|
.forUpdate(existingEntity, queryContext)
|
|
306
306
|
.setField('stringField', 'huh2')
|
|
307
307
|
.enforceUpdateAsync();
|
|
308
|
-
ts_mockito_1.verify(spiedPrivacyPolicy.authorizeUpdateAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default))).once();
|
|
308
|
+
(0, ts_mockito_1.verify)(spiedPrivacyPolicy.authorizeUpdateAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.anything)())).once();
|
|
309
309
|
});
|
|
310
310
|
it('executes triggers', async () => {
|
|
311
|
-
const viewerContext = ts_mockito_1.mock();
|
|
311
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
312
312
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
313
|
-
const id1 = uuid_1.v4();
|
|
314
|
-
const id2 = uuid_1.v4();
|
|
315
|
-
const { mutationTriggers, entityMutatorFactory, entityLoaderFactory
|
|
313
|
+
const id1 = (0, uuid_1.v4)();
|
|
314
|
+
const id2 = (0, uuid_1.v4)();
|
|
315
|
+
const { mutationTriggers, entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
316
316
|
{
|
|
317
317
|
customIdField: id1,
|
|
318
318
|
stringField: 'huh',
|
|
319
319
|
testIndexedField: '3',
|
|
320
|
-
|
|
320
|
+
intField: 3,
|
|
321
321
|
dateField: new Date(),
|
|
322
322
|
nullableField: null,
|
|
323
323
|
},
|
|
@@ -325,13 +325,13 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
325
325
|
customIdField: id2,
|
|
326
326
|
stringField: 'huh',
|
|
327
327
|
testIndexedField: '4',
|
|
328
|
-
|
|
328
|
+
intField: 3,
|
|
329
329
|
dateField: new Date(),
|
|
330
330
|
nullableField: null,
|
|
331
331
|
},
|
|
332
332
|
]);
|
|
333
333
|
const triggerSpies = setUpMutationTriggerSpies(mutationTriggers);
|
|
334
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
334
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
335
335
|
await entityMutatorFactory
|
|
336
336
|
.forUpdate(existingEntity, queryContext)
|
|
337
337
|
.setField('stringField', 'huh2')
|
|
@@ -343,19 +343,19 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
343
343
|
afterUpdate: true,
|
|
344
344
|
beforeDelete: false,
|
|
345
345
|
afterDelete: false,
|
|
346
|
-
}, { type:
|
|
346
|
+
}, { type: EntityMutationInfo_1.EntityMutationType.UPDATE, previousValue: existingEntity });
|
|
347
347
|
});
|
|
348
348
|
it('executes validators', async () => {
|
|
349
|
-
const viewerContext = ts_mockito_1.mock();
|
|
349
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
350
350
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
351
|
-
const id1 = uuid_1.v4();
|
|
352
|
-
const id2 = uuid_1.v4();
|
|
353
|
-
const { mutationValidators, entityMutatorFactory, entityLoaderFactory
|
|
351
|
+
const id1 = (0, uuid_1.v4)();
|
|
352
|
+
const id2 = (0, uuid_1.v4)();
|
|
353
|
+
const { mutationValidators, entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
354
354
|
{
|
|
355
355
|
customIdField: id1,
|
|
356
356
|
stringField: 'huh',
|
|
357
357
|
testIndexedField: '3',
|
|
358
|
-
|
|
358
|
+
intField: 3,
|
|
359
359
|
dateField: new Date(),
|
|
360
360
|
nullableField: null,
|
|
361
361
|
},
|
|
@@ -363,78 +363,78 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
363
363
|
customIdField: id2,
|
|
364
364
|
stringField: 'huh',
|
|
365
365
|
testIndexedField: '4',
|
|
366
|
-
|
|
366
|
+
intField: 3,
|
|
367
367
|
dateField: new Date(),
|
|
368
368
|
nullableField: null,
|
|
369
369
|
},
|
|
370
370
|
]);
|
|
371
371
|
const validatorSpies = setUpMutationValidatorSpies(mutationValidators);
|
|
372
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
372
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id2));
|
|
373
373
|
await entityMutatorFactory
|
|
374
374
|
.forUpdate(existingEntity, queryContext)
|
|
375
375
|
.setField('stringField', 'huh2')
|
|
376
376
|
.enforceUpdateAsync();
|
|
377
377
|
verifyValidatorCounts(viewerContext, validatorSpies, 1, {
|
|
378
|
-
type:
|
|
378
|
+
type: EntityMutationInfo_1.EntityMutationType.UPDATE,
|
|
379
379
|
previousValue: existingEntity,
|
|
380
380
|
});
|
|
381
381
|
});
|
|
382
382
|
});
|
|
383
383
|
describe('forDelete', () => {
|
|
384
384
|
it('deletes entities', async () => {
|
|
385
|
-
const viewerContext = ts_mockito_1.mock();
|
|
385
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
386
386
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
387
|
-
const id1 = uuid_1.v4();
|
|
387
|
+
const id1 = (0, uuid_1.v4)();
|
|
388
388
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
389
389
|
{
|
|
390
390
|
customIdField: id1,
|
|
391
391
|
stringField: 'huh',
|
|
392
392
|
testIndexedField: '3',
|
|
393
|
-
|
|
393
|
+
intField: 3,
|
|
394
394
|
dateField: new Date(),
|
|
395
395
|
nullableField: null,
|
|
396
396
|
},
|
|
397
397
|
]);
|
|
398
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
398
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
399
399
|
expect(existingEntity).toBeTruthy();
|
|
400
400
|
await entityMutatorFactory.forDelete(existingEntity, queryContext).enforceDeleteAsync();
|
|
401
|
-
await expect(results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1))).rejects.toBeInstanceOf(Error);
|
|
401
|
+
await expect((0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1))).rejects.toBeInstanceOf(Error);
|
|
402
402
|
});
|
|
403
403
|
it('checks privacy', async () => {
|
|
404
|
-
const viewerContext = ts_mockito_1.mock();
|
|
404
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
405
405
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
406
|
-
const id1 = uuid_1.v4();
|
|
407
|
-
const { privacyPolicy, entityMutatorFactory, entityLoaderFactory
|
|
406
|
+
const id1 = (0, uuid_1.v4)();
|
|
407
|
+
const { privacyPolicy, entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
408
408
|
{
|
|
409
409
|
customIdField: id1,
|
|
410
410
|
stringField: 'huh',
|
|
411
411
|
testIndexedField: '3',
|
|
412
|
-
|
|
412
|
+
intField: 3,
|
|
413
413
|
dateField: new Date(),
|
|
414
414
|
nullableField: null,
|
|
415
415
|
},
|
|
416
416
|
]);
|
|
417
|
-
const spiedPrivacyPolicy = ts_mockito_1.spy(privacyPolicy);
|
|
418
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
417
|
+
const spiedPrivacyPolicy = (0, ts_mockito_1.spy)(privacyPolicy);
|
|
418
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
419
419
|
await entityMutatorFactory.forDelete(existingEntity, queryContext).enforceDeleteAsync();
|
|
420
|
-
ts_mockito_1.verify(spiedPrivacyPolicy.authorizeDeleteAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(TestEntity_1.default))).once();
|
|
420
|
+
(0, ts_mockito_1.verify)(spiedPrivacyPolicy.authorizeDeleteAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(TestEntity_1.default), (0, ts_mockito_1.anything)())).once();
|
|
421
421
|
});
|
|
422
422
|
it('executes triggers', async () => {
|
|
423
|
-
const viewerContext = ts_mockito_1.mock();
|
|
423
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
424
424
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
425
|
-
const id1 = uuid_1.v4();
|
|
426
|
-
const { mutationTriggers, entityMutatorFactory, entityLoaderFactory
|
|
425
|
+
const id1 = (0, uuid_1.v4)();
|
|
426
|
+
const { mutationTriggers, entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
427
427
|
{
|
|
428
428
|
customIdField: id1,
|
|
429
429
|
stringField: 'huh',
|
|
430
430
|
testIndexedField: '3',
|
|
431
|
-
|
|
431
|
+
intField: 3,
|
|
432
432
|
dateField: new Date(),
|
|
433
433
|
nullableField: null,
|
|
434
434
|
},
|
|
435
435
|
]);
|
|
436
436
|
const triggerSpies = setUpMutationTriggerSpies(mutationTriggers);
|
|
437
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
437
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
438
438
|
await entityMutatorFactory.forDelete(existingEntity, queryContext).enforceDeleteAsync();
|
|
439
439
|
verifyTriggerCounts(viewerContext, triggerSpies, {
|
|
440
440
|
beforeCreate: false,
|
|
@@ -443,65 +443,67 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
443
443
|
afterUpdate: false,
|
|
444
444
|
beforeDelete: true,
|
|
445
445
|
afterDelete: true,
|
|
446
|
-
}, { type:
|
|
446
|
+
}, { type: EntityMutationInfo_1.EntityMutationType.DELETE, cascadingDeleteCause: null });
|
|
447
447
|
});
|
|
448
448
|
it('does not execute validators', async () => {
|
|
449
|
-
const viewerContext = ts_mockito_1.mock();
|
|
449
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
450
450
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
451
|
-
const id1 = uuid_1.v4();
|
|
452
|
-
const { mutationValidators, entityMutatorFactory, entityLoaderFactory
|
|
451
|
+
const id1 = (0, uuid_1.v4)();
|
|
452
|
+
const { mutationValidators, entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
453
453
|
{
|
|
454
454
|
customIdField: id1,
|
|
455
455
|
stringField: 'huh',
|
|
456
456
|
testIndexedField: '3',
|
|
457
|
-
|
|
457
|
+
intField: 3,
|
|
458
458
|
dateField: new Date(),
|
|
459
459
|
nullableField: null,
|
|
460
460
|
},
|
|
461
461
|
]);
|
|
462
462
|
const validatorSpies = setUpMutationValidatorSpies(mutationValidators);
|
|
463
|
-
const existingEntity = await results_1.enforceAsyncResult(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
463
|
+
const existingEntity = await (0, results_1.enforceAsyncResult)(entityLoaderFactory.forLoad(viewerContext, queryContext).loadByIDAsync(id1));
|
|
464
464
|
await entityMutatorFactory.forDelete(existingEntity, queryContext).enforceDeleteAsync();
|
|
465
|
-
verifyValidatorCounts(viewerContext, validatorSpies, 0, {
|
|
465
|
+
verifyValidatorCounts(viewerContext, validatorSpies, 0, {
|
|
466
|
+
type: EntityMutationInfo_1.EntityMutationType.DELETE,
|
|
467
|
+
});
|
|
466
468
|
});
|
|
467
469
|
});
|
|
468
470
|
it('invalidates cache for fields upon create', async () => {
|
|
469
|
-
const viewerContext = ts_mockito_1.mock();
|
|
471
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
470
472
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
471
|
-
const id1 = uuid_1.v4();
|
|
473
|
+
const id1 = (0, uuid_1.v4)();
|
|
472
474
|
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
473
475
|
{
|
|
474
476
|
customIdField: id1,
|
|
475
477
|
stringField: 'huh',
|
|
476
478
|
testIndexedField: '3',
|
|
477
|
-
|
|
479
|
+
intField: 3,
|
|
478
480
|
dateField: new Date(),
|
|
479
481
|
nullableField: null,
|
|
480
482
|
},
|
|
481
483
|
]);
|
|
482
|
-
const entites1 = await entityUtils_1.enforceResultsAsync(entityLoaderFactory
|
|
484
|
+
const entites1 = await (0, entityUtils_1.enforceResultsAsync)(entityLoaderFactory
|
|
483
485
|
.forLoad(viewerContext, queryContext)
|
|
484
486
|
.loadManyByFieldEqualingAsync('stringField', 'huh'));
|
|
485
487
|
expect(entites1).toHaveLength(1);
|
|
486
|
-
await results_1.enforceAsyncResult(entityMutatorFactory
|
|
488
|
+
await (0, results_1.enforceAsyncResult)(entityMutatorFactory
|
|
487
489
|
.forCreate(viewerContext, queryContext)
|
|
488
490
|
.setField('stringField', 'huh')
|
|
489
491
|
.createAsync());
|
|
490
|
-
const entities2 = await entityUtils_1.enforceResultsAsync(entityLoaderFactory
|
|
492
|
+
const entities2 = await (0, entityUtils_1.enforceResultsAsync)(entityLoaderFactory
|
|
491
493
|
.forLoad(viewerContext, queryContext)
|
|
492
494
|
.loadManyByFieldEqualingAsync('stringField', 'huh'));
|
|
493
495
|
expect(entities2).toHaveLength(2);
|
|
494
496
|
});
|
|
495
497
|
it('throws error when field not valid', async () => {
|
|
496
|
-
const viewerContext = ts_mockito_1.mock();
|
|
498
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
497
499
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
498
|
-
const id1 = uuid_1.v4();
|
|
500
|
+
const id1 = (0, uuid_1.v4)();
|
|
499
501
|
const { entityMutatorFactory } = createEntityMutatorFactory([
|
|
500
502
|
{
|
|
501
503
|
customIdField: id1,
|
|
502
504
|
stringField: 'huh',
|
|
503
505
|
testIndexedField: '3',
|
|
504
|
-
|
|
506
|
+
intField: 3,
|
|
505
507
|
dateField: new Date(),
|
|
506
508
|
nullableField: null,
|
|
507
509
|
},
|
|
@@ -520,24 +522,24 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
520
522
|
.updateAsync()).rejects.toThrowError('Entity field not valid: TestEntity (stringField = 10)');
|
|
521
523
|
});
|
|
522
524
|
it('returns error result when not authorized to create', async () => {
|
|
523
|
-
const viewerContext = ts_mockito_1.instance(ts_mockito_1.mock(ViewerContext_1.default));
|
|
525
|
+
const viewerContext = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)(ViewerContext_1.default));
|
|
524
526
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
525
|
-
const privacyPolicyMock = ts_mockito_1.mock(SimpleTestEntity_1.SimpleTestEntityPrivacyPolicy);
|
|
526
|
-
const databaseAdapter = ts_mockito_1.instance(ts_mockito_1.mock());
|
|
527
|
-
const metricsAdapter = ts_mockito_1.instance(ts_mockito_1.mock());
|
|
528
|
-
const entityLoaderFactory = ts_mockito_1.instance(ts_mockito_1.mock(EntityLoaderFactory_1.default));
|
|
527
|
+
const privacyPolicyMock = (0, ts_mockito_1.mock)(SimpleTestEntity_1.SimpleTestEntityPrivacyPolicy);
|
|
528
|
+
const databaseAdapter = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)());
|
|
529
|
+
const metricsAdapter = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)());
|
|
530
|
+
const entityLoaderFactory = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)(EntityLoaderFactory_1.default));
|
|
529
531
|
const rejectionError = new Error();
|
|
530
|
-
ts_mockito_1.when(privacyPolicyMock.authorizeCreateAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(SimpleTestEntity_1.default))).thenReject(rejectionError);
|
|
531
|
-
ts_mockito_1.when(privacyPolicyMock.authorizeUpdateAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(SimpleTestEntity_1.default))).thenReject(rejectionError);
|
|
532
|
-
ts_mockito_1.when(privacyPolicyMock.authorizeDeleteAsync(viewerContext, ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anyOfClass(SimpleTestEntity_1.default))).thenReject(rejectionError);
|
|
533
|
-
const entityMutatorFactory = new EntityMutatorFactory_1.default(SimpleTestEntity_1.simpleTestEntityConfiguration, SimpleTestEntity_1.default, ts_mockito_1.instance(privacyPolicyMock), [], {}, entityLoaderFactory, databaseAdapter, metricsAdapter);
|
|
532
|
+
(0, ts_mockito_1.when)(privacyPolicyMock.authorizeCreateAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(SimpleTestEntity_1.default), (0, ts_mockito_1.anything)())).thenReject(rejectionError);
|
|
533
|
+
(0, ts_mockito_1.when)(privacyPolicyMock.authorizeUpdateAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(SimpleTestEntity_1.default), (0, ts_mockito_1.anything)())).thenReject(rejectionError);
|
|
534
|
+
(0, ts_mockito_1.when)(privacyPolicyMock.authorizeDeleteAsync(viewerContext, (0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anyOfClass)(SimpleTestEntity_1.default), (0, ts_mockito_1.anything)())).thenReject(rejectionError);
|
|
535
|
+
const entityMutatorFactory = new EntityMutatorFactory_1.default(SimpleTestEntity_1.simpleTestEntityConfiguration, SimpleTestEntity_1.default, (0, ts_mockito_1.instance)(privacyPolicyMock), [], {}, entityLoaderFactory, databaseAdapter, metricsAdapter);
|
|
534
536
|
const entityCreateResult = await entityMutatorFactory
|
|
535
537
|
.forCreate(viewerContext, queryContext)
|
|
536
538
|
.createAsync();
|
|
537
539
|
expect(entityCreateResult.ok).toBe(false);
|
|
538
540
|
expect(entityCreateResult.reason).toEqual(rejectionError);
|
|
539
541
|
expect(entityCreateResult.value).toBe(undefined);
|
|
540
|
-
const id1 = uuid_1.v4();
|
|
542
|
+
const id1 = (0, uuid_1.v4)();
|
|
541
543
|
const fakeEntity = new SimpleTestEntity_1.default(viewerContext, {
|
|
542
544
|
id: id1,
|
|
543
545
|
});
|
|
@@ -555,18 +557,18 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
555
557
|
expect(entityDeleteResult.value).toBe(undefined);
|
|
556
558
|
});
|
|
557
559
|
it('throws error when db adapter throws', async () => {
|
|
558
|
-
const viewerContext = ts_mockito_1.instance(ts_mockito_1.mock(ViewerContext_1.default));
|
|
560
|
+
const viewerContext = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)(ViewerContext_1.default));
|
|
559
561
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
560
|
-
const privacyPolicy = ts_mockito_1.instance(ts_mockito_1.mock(SimpleTestEntity_1.SimpleTestEntityPrivacyPolicy));
|
|
561
|
-
const databaseAdapterMock = ts_mockito_1.mock();
|
|
562
|
-
const metricsAdapter = ts_mockito_1.instance(ts_mockito_1.mock());
|
|
563
|
-
const entityLoaderFactory = ts_mockito_1.instance(ts_mockito_1.mock(EntityLoaderFactory_1.default));
|
|
562
|
+
const privacyPolicy = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)(SimpleTestEntity_1.SimpleTestEntityPrivacyPolicy));
|
|
563
|
+
const databaseAdapterMock = (0, ts_mockito_1.mock)();
|
|
564
|
+
const metricsAdapter = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)());
|
|
565
|
+
const entityLoaderFactory = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)(EntityLoaderFactory_1.default));
|
|
564
566
|
const rejectionError = new Error();
|
|
565
|
-
ts_mockito_1.when(databaseAdapterMock.insertAsync(ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anything())).thenReject(rejectionError);
|
|
566
|
-
ts_mockito_1.when(databaseAdapterMock.updateAsync(ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anything(), ts_mockito_1.anything(), ts_mockito_1.anything())).thenReject(rejectionError);
|
|
567
|
-
ts_mockito_1.when(databaseAdapterMock.deleteAsync(ts_mockito_1.anyOfClass(EntityQueryContext_1.EntityTransactionalQueryContext), ts_mockito_1.anything(), ts_mockito_1.anything())).thenReject(rejectionError);
|
|
568
|
-
const entityMutatorFactory = new EntityMutatorFactory_1.default(SimpleTestEntity_1.simpleTestEntityConfiguration, SimpleTestEntity_1.default, privacyPolicy, [], {}, entityLoaderFactory, ts_mockito_1.instance(databaseAdapterMock), metricsAdapter);
|
|
569
|
-
const id1 = uuid_1.v4();
|
|
567
|
+
(0, ts_mockito_1.when)(databaseAdapterMock.insertAsync((0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anything)())).thenReject(rejectionError);
|
|
568
|
+
(0, ts_mockito_1.when)(databaseAdapterMock.updateAsync((0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anything)(), (0, ts_mockito_1.anything)(), (0, ts_mockito_1.anything)())).thenReject(rejectionError);
|
|
569
|
+
(0, ts_mockito_1.when)(databaseAdapterMock.deleteAsync((0, ts_mockito_1.anyOfClass)(EntityQueryContext_1.EntityTransactionalQueryContext), (0, ts_mockito_1.anything)(), (0, ts_mockito_1.anything)())).thenReject(rejectionError);
|
|
570
|
+
const entityMutatorFactory = new EntityMutatorFactory_1.default(SimpleTestEntity_1.simpleTestEntityConfiguration, SimpleTestEntity_1.default, privacyPolicy, [], {}, entityLoaderFactory, (0, ts_mockito_1.instance)(databaseAdapterMock), metricsAdapter);
|
|
571
|
+
const id1 = (0, uuid_1.v4)();
|
|
570
572
|
const fakeEntity = new SimpleTestEntity_1.default(viewerContext, {
|
|
571
573
|
id: id1,
|
|
572
574
|
});
|
|
@@ -575,32 +577,32 @@ describe(EntityMutatorFactory_1.default, () => {
|
|
|
575
577
|
await expect(entityMutatorFactory.forDelete(fakeEntity, queryContext).deleteAsync()).rejects.toEqual(rejectionError);
|
|
576
578
|
});
|
|
577
579
|
it('records metrics appropriately', async () => {
|
|
578
|
-
const viewerContext = ts_mockito_1.mock();
|
|
580
|
+
const viewerContext = (0, ts_mockito_1.mock)();
|
|
579
581
|
const queryContext = StubQueryContextProvider_1.default.getQueryContext();
|
|
580
582
|
const { entityMutatorFactory, metricsAdapter } = createEntityMutatorFactory([]);
|
|
581
|
-
const spiedMetricsAdapter = ts_mockito_1.spy(metricsAdapter);
|
|
582
|
-
const newEntity = await results_1.enforceAsyncResult(entityMutatorFactory
|
|
583
|
+
const spiedMetricsAdapter = (0, ts_mockito_1.spy)(metricsAdapter);
|
|
584
|
+
const newEntity = await (0, results_1.enforceAsyncResult)(entityMutatorFactory
|
|
583
585
|
.forCreate(viewerContext, queryContext)
|
|
584
586
|
.setField('stringField', 'huh')
|
|
585
587
|
.createAsync());
|
|
586
|
-
await results_1.enforceAsyncResult(entityMutatorFactory
|
|
588
|
+
await (0, results_1.enforceAsyncResult)(entityMutatorFactory
|
|
587
589
|
.forUpdate(newEntity, queryContext)
|
|
588
590
|
.setField('stringField', 'wat')
|
|
589
591
|
.updateAsync());
|
|
590
|
-
await results_1.enforceAsyncResult(entityMutatorFactory.forDelete(newEntity, queryContext).deleteAsync());
|
|
591
|
-
ts_mockito_1.verify(spiedMetricsAdapter.logMutatorMutationEvent(ts_mockito_1.objectContaining({
|
|
592
|
+
await (0, results_1.enforceAsyncResult)(entityMutatorFactory.forDelete(newEntity, queryContext).deleteAsync());
|
|
593
|
+
(0, ts_mockito_1.verify)(spiedMetricsAdapter.logMutatorMutationEvent((0, ts_mockito_1.objectContaining)({
|
|
592
594
|
type: IEntityMetricsAdapter_1.EntityMetricsMutationType.CREATE,
|
|
593
595
|
entityClassName: TestEntity_1.default.name,
|
|
594
596
|
}))).once();
|
|
595
|
-
ts_mockito_1.verify(spiedMetricsAdapter.logMutatorMutationEvent(ts_mockito_1.objectContaining({
|
|
597
|
+
(0, ts_mockito_1.verify)(spiedMetricsAdapter.logMutatorMutationEvent((0, ts_mockito_1.objectContaining)({
|
|
596
598
|
type: IEntityMetricsAdapter_1.EntityMetricsMutationType.UPDATE,
|
|
597
599
|
entityClassName: TestEntity_1.default.name,
|
|
598
600
|
}))).once();
|
|
599
|
-
ts_mockito_1.verify(spiedMetricsAdapter.logMutatorMutationEvent(ts_mockito_1.objectContaining({
|
|
601
|
+
(0, ts_mockito_1.verify)(spiedMetricsAdapter.logMutatorMutationEvent((0, ts_mockito_1.objectContaining)({
|
|
600
602
|
type: IEntityMetricsAdapter_1.EntityMetricsMutationType.DELETE,
|
|
601
603
|
entityClassName: TestEntity_1.default.name,
|
|
602
604
|
}))).once();
|
|
603
|
-
ts_mockito_1.verify(spiedMetricsAdapter.logMutatorMutationEvent(ts_mockito_1.anything())).thrice();
|
|
605
|
+
(0, ts_mockito_1.verify)(spiedMetricsAdapter.logMutatorMutationEvent((0, ts_mockito_1.anything)())).thrice();
|
|
604
606
|
});
|
|
605
607
|
});
|
|
606
608
|
//# sourceMappingURL=EntityMutator-test.js.map
|