Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions registry/server/apps/repositories/AppsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AppsRepository {
return;
}
if (filters.id || filters.name) {
query.whereIn('name', [...(filters.id ?? filters.name ?? [])]);
query.whereIn(`${Tables.Apps}.name`, [...(filters.id ?? filters.name ?? [])]);
}
}

Expand All @@ -62,14 +62,14 @@ export class AppsRepository {
if (kind.length === 0) {
return;
}
query.whereIn('kind', kind);
query.whereIn(`${Tables.Apps}.kind`, kind);
}

private addFilterByQuery(query: Knex.QueryBuilder, filters: AppsGetListFilters) {
if (!filters.q) {
return;
}
query.where('name', 'like', `%${filters.q}%`);
query.where(`${Tables.Apps}.name`, 'like', `%${filters.q}%`);
}

private addFilterByDomainId(query: Knex.QueryBuilder, filters: AppsGetListFilters) {
Expand All @@ -92,8 +92,12 @@ export class AppsRepository {
query
.leftJoin(Tables.RouteSlots, `${Tables.RouteSlots}.appName`, `${Tables.Apps}.name`)
.leftJoin(Tables.Routes, `${Tables.Routes}.id`, `${Tables.RouteSlots}.routeId`)
.where(`${Tables.Routes}.domainId`, filters.domainId)
.orWhere(`${Tables.Apps}.enforceDomain`, filters.domainId)
.where(function () {
this.where(`${Tables.Routes}.domainId`, filters.domainId).orWhere(
`${Tables.Apps}.enforceDomain`,
filters.domainId,
);
})
.groupBy(`${Tables.Apps}.name`)
.groupBy('v.versionId');
}
Expand Down
54 changes: 54 additions & 0 deletions registry/tests/apps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,60 @@ describe(`Tests ${example.url}`, () => {
}
});

it('should successfully return records filtered by name search (q) and domainId combined', async () => {
const teardownFns: (() => Promise<void>)[] = [];

try {
for (const app of example.appsList) {
await req.post(example.url).send(app).expect(200);
}
teardownFns.unshift(async () => {
for (const app of example.appsList) {
await req.delete(example.url + app.name).expect(204);
}
});

const template = {
name: 'hello500',
content: '<html><head></head><body class="custom">hello500</body></html>',
};
await req.post('/api/v1/template').send(template).expect(200);
teardownFns.unshift(async () => {
await req.delete('/api/v1/template/' + template.name).expect(204);
});

const domain = { domainName: 'example.com', template500: template.name };
const {
body: { id: routerDomainId },
} = await req.post('/api/v1/router_domains').send(domain).expect(200);
teardownFns.unshift(async () => {
await req.delete('/api/v1/router_domains/' + routerDomainId).expect(204);
});

const route = {
next: false,
slots: { myslot: { appName: example.appsList[1].name, kind: 'primary' } },
route: 'myroute',
domainId: routerDomainId,
};
const {
body: { id: routeId },
} = await req.post('/api/v1/route').send(route).expect(200);
teardownFns.unshift(async () => {
await req.delete('/api/v1/route/' + routeId).expect(204);
});

const query = makeFilterQuery({ q: 'app1', domainId: routerDomainId });
const response = await req.get(`${example.url}?${query}`).expect(200);

expectAppsListEqual(response.body, [example.appsList[1]]);
} finally {
for (const fn of teardownFns) {
await fn();
}
}
});

it('should successfully filter by name array (single name)', async () => {
try {
for (const app of example.appsList) {
Expand Down
Loading