add tests for emitting refresh keys
Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Fixes a bug to be able to utilize refresh keys after the entity is loaded from cache
|
||||
@@ -127,19 +127,25 @@ describe('UrlReaderProcessor', () => {
|
||||
mockCache.get.mockResolvedValue(cacheItem);
|
||||
const processor = new UrlReaderProcessor({ reader, logger });
|
||||
|
||||
const generated = (await new Promise<CatalogProcessorResult>(emit =>
|
||||
processor.readLocation(
|
||||
spec,
|
||||
false,
|
||||
emit,
|
||||
defaultEntityDataParser,
|
||||
mockCache,
|
||||
),
|
||||
)) as CatalogProcessorEntityResult;
|
||||
const emitted = new Array<CatalogProcessorResult>();
|
||||
await processor.readLocation(
|
||||
spec,
|
||||
false,
|
||||
r => emitted.push(r),
|
||||
defaultEntityDataParser,
|
||||
mockCache,
|
||||
);
|
||||
|
||||
const entity = emitted[0];
|
||||
const refresh = emitted[1];
|
||||
|
||||
expect(entity.type).toBe('entity');
|
||||
expect(entity.location).toEqual(spec);
|
||||
expect(entity.entity).toEqual({ mock: 'entity' });
|
||||
|
||||
expect(refresh.type).toBe('refresh');
|
||||
expect(refresh.key).toBe('url:http://localhost/component.yaml');
|
||||
|
||||
expect(generated.type).toBe('entity');
|
||||
expect(generated.location).toEqual(spec);
|
||||
expect(generated.entity).toEqual({ mock: 'entity' });
|
||||
expect(mockCache.get).toBeCalledWith('v1');
|
||||
expect(mockCache.get).toBeCalledTimes(1);
|
||||
expect(mockCache.set).toBeCalledTimes(0);
|
||||
|
||||
Reference in New Issue
Block a user