fix(catalog-backend): add orderBy to facets query and clean up tests
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 <freben@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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 },
|
||||
],
|
||||
]),
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user