Address Copilot review: fix pagination test and add credentials assertion

Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Made-with: Cursor
This commit is contained in:
Fredrik Adelöw
2026-04-03 23:23:42 +02:00
parent 999f308ad5
commit e7fdf2997f
2 changed files with 19 additions and 8 deletions
@@ -186,9 +186,9 @@ describe('DefaultTechDocsCollatorFactory', () => {
});
it('paginates through catalog entities using batchSize', async () => {
// A parallelismLimit of 1 results in a batchSize of 50 per request.
// The catalog returns fewer entities than the batchSize, so the loop
// exits after a single page, producing 3 documents (1 entity × 3 search index docs).
// parallelismLimit of 1 batchSize of 50 per request.
// First page returns exactly 50 (no techdocs annotation) triggering a
// second request; second page returns the real entity with annotation.
const _config = new ConfigReader({
...config.get(),
search: {
@@ -199,17 +199,24 @@ describe('DefaultTechDocsCollatorFactory', () => {
},
},
});
factory = DefaultTechDocsCollatorFactory.fromConfig(_config, options);
const paginationCatalog = catalogServiceMock({ entities: [] });
jest
.spyOn(paginationCatalog, 'getEntities')
.mockResolvedValueOnce({ items: Array(50).fill({}) })
.mockResolvedValueOnce({ items: expectedEntities });
factory = DefaultTechDocsCollatorFactory.fromConfig(_config, {
...options,
catalog: paginationCatalog,
});
collator = await factory.getCollator();
const pipeline = TestPipeline.fromCollator(collator);
const { documents } = await pipeline.execute();
// Only 1 entity with TechDocs configured multiplied by 3 pages.
expect(paginationCatalog.getEntities).toHaveBeenCalledTimes(2);
// First page: 50 entities with no techdocs annotation → 0 docs
// Second page: 1 entity × 3 search index docs → 3 docs
expect(documents).toHaveLength(3);
expect(_config.get('search.collators.techdocs.parallelismLimit')).toEqual(
1,
);
});
describe('with legacyPathCasing configuration', () => {
@@ -62,12 +62,16 @@ describe('CachedEntityLoader', () => {
it('writes entities to cache for user credentials', async () => {
cache.get.mockResolvedValue(undefined);
const catalog = catalogServiceMock({ entities: [entity] });
jest.spyOn(catalog, 'getEntityByRef');
auth.isPrincipal.mockReturnValue(true);
const loader = new CachedEntityLoader({ auth, catalog, cache });
const result = await loader.load(userCredentials, entityName);
expect(result).toEqual(entity);
expect(catalog.getEntityByRef).toHaveBeenCalledWith(entityName, {
credentials: userCredentials,
});
expect(cache.set).toHaveBeenCalledWith(
'catalog:component:default/test:user:default/test-user',
entity,