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:
parent
520e0c3df3
commit
97363e01dc
2 changed files with 28 additions and 1 deletions
|
@ -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 },
|
||||
|
|
25
packages/integration-tests/src/tests/api/log.test.ts
Normal file
25
packages/integration-tests/src/tests/api/log.test.ts
Normal 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));
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue