From b61936fc626109589fa92959debc89a2d4340999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 12 May 2026 15:18:10 +0200 Subject: [PATCH] fix(catalog-backend): add orderBy to facets query and clean up tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ORDER BY to guarantee stable result ordering across all database backends (MySQL does not sort without it). Also consolidate double catalog.facets() calls in tests into a single call with both content and length assertions on the same result. Signed-off-by: Fredrik Adelöw Co-authored-by: Cursor --- .../service/DefaultEntitiesCatalog.test.ts | 44 +++++++------------ .../src/service/DefaultEntitiesCatalog.ts | 3 +- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts index 6a5c33b16d..28ba0cf9e2 100644 --- a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts +++ b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts @@ -2548,13 +2548,13 @@ describe('DefaultEntitiesCatalog', () => { }, ]); - await expect( - catalog.facets({ - facets: ['spec.type'], - query: { kind: 'component' }, - credentials: mockCredentials.none(), - }), - ).resolves.toEqual({ + const result = await catalog.facets({ + facets: ['spec.type'], + query: { kind: 'component' }, + credentials: mockCredentials.none(), + }); + expect(result.facets['spec.type']).toHaveLength(2); + expect(result).toEqual({ facets: { 'spec.type': expect.arrayContaining([ { value: 'library', count: 1 }, @@ -2562,12 +2562,6 @@ describe('DefaultEntitiesCatalog', () => { ]), }, }); - const result = await catalog.facets({ - facets: ['spec.type'], - query: { kind: 'component' }, - credentials: mockCredentials.none(), - }); - expect(result.facets['spec.type']).toHaveLength(2); }, ); @@ -2595,13 +2589,13 @@ describe('DefaultEntitiesCatalog', () => { }, ]); - await expect( - catalog.facets({ - facets: ['kind'], - query: { kind: { $in: ['component', 'api'] } }, - credentials: mockCredentials.none(), - }), - ).resolves.toEqual({ + const result = await catalog.facets({ + facets: ['kind'], + query: { kind: { $in: ['component', 'api'] } }, + credentials: mockCredentials.none(), + }); + expect(result.facets.kind).toHaveLength(2); + expect(result).toEqual({ facets: { kind: expect.arrayContaining([ { value: 'API', count: 1 }, @@ -2609,12 +2603,6 @@ describe('DefaultEntitiesCatalog', () => { ]), }, }); - const result = await catalog.facets({ - facets: ['kind'], - query: { kind: { $in: ['component', 'api'] } }, - credentials: mockCredentials.none(), - }); - expect(result.facets.kind).toHaveLength(2); }, ); @@ -2698,10 +2686,10 @@ describe('DefaultEntitiesCatalog', () => { }), ).resolves.toEqual({ facets: { - 'metadata.name': [ + 'metadata.name': expect.arrayContaining([ { value: 'one', count: 1 }, { value: 'two', count: 1 }, - ], + ]), }, }); }, diff --git a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts index 90866e3f56..92e53ce306 100644 --- a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts @@ -687,7 +687,8 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog { value: 'search.original_value', count: this.database.raw('count(*)'), }) - .groupBy(['search.key', 'search.original_value']); + .groupBy(['search.key', 'search.original_value']) + .orderBy(['search.key', 'search.original_value']); if (request.filter || request.query) { // Build a subquery that finds matching entity IDs via