Skip to content

Commit

Permalink
feat!: Make load/create/update/delete entity authorization result int…
Browse files Browse the repository at this point in the history
…erfaces consistent (#253)
  • Loading branch information
wschurman authored Feb 24, 2025
1 parent 275c63d commit 4d56065
Show file tree
Hide file tree
Showing 42 changed files with 1,044 additions and 359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ describe(GenericLocalMemoryCacher, () => {

const date = new Date();
const entity1Created = await LocalMemoryTestEntity.creator(viewerContext)
.enforcing()
.setField('name', 'blah')
.setField('dateField', date)
.enforceCreateAsync();
.createAsync();

// loading an entity should put it in cache
const entity1 = await LocalMemoryTestEntity.loader(viewerContext)
Expand Down Expand Up @@ -103,9 +104,10 @@ describe(GenericLocalMemoryCacher, () => {

const date = new Date();
const entity1Created = await LocalMemoryTestEntity.creator(viewerContext)
.enforcing()
.setField('name', 'blah')
.setField('dateField', date)
.enforceCreateAsync();
.createAsync();

// loading an entity will try to put it in cache but it's a noop cache, so it should be a miss
const entity1 = await LocalMemoryTestEntity.loader(viewerContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ describe(GenericRedisCacher, () => {
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);

const entity1Created = await RedisTestEntity.creator(viewerContext)
.enforcing()
.setField('name', 'blah')
.enforceCreateAsync();
.createAsync();

// loading an entity should put it in cache. load by multiple requests and multiple fields in same tick to ensure batch works
mgetSpy.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ describe(GenericRedisCacher, () => {
const cacheKeyMaker = genericCacher['makeCacheKey'].bind(genericCacher);

const entity1Created = await RedisTestEntity.creator(viewerContext)
.enforcing()
.setField('name', 'blah')
.enforceCreateAsync();
.createAsync();

// loading an entity should put it in cache
const entity1 = await RedisTestEntity.loader(viewerContext)
Expand Down Expand Up @@ -99,7 +100,10 @@ describe(GenericRedisCacher, () => {
);
const date = new Date();
const entity1 = await enforceAsyncResult(
RedisTestEntity.creator(viewerContext).setField('dateField', date).createAsync(),
RedisTestEntity.creator(viewerContext)
.withAuthorizationResults()
.setField('dateField', date)
.createAsync(),
);
expect(entity1.getField('dateField')).toEqual(date);

Expand All @@ -121,7 +125,10 @@ describe(GenericRedisCacher, () => {
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
);
const entity1 = await enforceAsyncResult(
RedisTestEntity.creator(viewerContext).setField('name', '').createAsync(),
RedisTestEntity.creator(viewerContext)
.withAuthorizationResults()
.setField('name', '')
.createAsync(),
);
const entity2 = await RedisTestEntity.loader(viewerContext)
.enforcing()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ describe(GenericRedisCacher, () => {
);
const date = new Date();
const entity1Created = await RedisTestEntity.creator(viewerContext)
.enforcing()
.setField('name', 'blah')
.setField('dateField', date)
.enforceCreateAsync();
.createAsync();
const testKey = `test-id-key-${entity1Created.getID()}`;
const objectMap = new Map<string, Readonly<RedisTestEntityFields>>([
[testKey, entity1Created.getAllFields()],
Expand Down Expand Up @@ -93,9 +94,10 @@ describe(GenericRedisCacher, () => {
);
const date = new Date();
const entity1Created = await RedisTestEntity.creator(viewerContext)
.enforcing()
.setField('name', 'blah')
.setField('dateField', date)
.enforceCreateAsync();
.createAsync();
const testKey = `test-id-key-${entity1Created.getID()}`;
const objectMap = new Map<string, Readonly<RedisTestEntityFields>>([
[testKey, entity1Created.getAllFields()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe(GenericRedisCacher, () => {
);

await expect(
RedisTestEntity.creator(vc1).setField('name', 'blah').enforceCreateAsync(),
RedisTestEntity.creator(vc1).enforcing().setField('name', 'blah').createAsync(),
).rejects.toThrow(EntityCacheAdapterTransientError);
});
});
Loading

0 comments on commit 4d56065

Please sign in to comment.