0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

test(core): add api response guard and error case tests to log api (#3807)

This commit is contained in:
wangsijie 2023-05-08 11:00:58 +08:00 committed by GitHub
parent 520e0c3df3
commit 97363e01dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -20,6 +20,8 @@ export default function logRoutes<T extends AuthedRouter>(
applicationId: string().optional(),
logKey: string().optional(),
}),
response: Logs.guard.omit({ tenantId: true }).array(),
status: 200,
}),
async (ctx, next) => {
const { limit, offset } = ctx.pagination;
@ -43,7 +45,7 @@ export default function logRoutes<T extends AuthedRouter>(
router.get(
'/logs/:id',
koaGuard({ params: object({ id: string().min(1) }), response: Logs.guard }),
koaGuard({ params: object({ id: string().min(1) }), response: Logs.guard, status: [200, 404] }),
async (ctx, next) => {
const {
params: { id },

View file

@ -0,0 +1,25 @@
import { getLog, getLogs } from '#src/api/index.js';
import { createResponseWithCode } from '#src/helpers/admin-tenant.js';
describe('logs', () => {
it('should get logs successfully', async () => {
const logs = await getLogs();
expect(logs.length).toBeGreaterThan(0);
});
it('should get log detail successfully', async () => {
const logs = await getLogs();
const logId = logs[0]?.id;
expect(logId).not.toBeUndefined();
if (logId) {
await expect(getLog(logId)).resolves.toHaveProperty('id', logId);
}
});
it('should throw on getting non-exist log detail', async () => {
await expect(getLog('non-exist-log-id')).rejects.toMatchObject(createResponseWithCode(404));
});
});