mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
test(core): improve the coverage of koa-log (#1683)
This commit is contained in:
parent
17e5476955
commit
77250c6135
1 changed files with 18 additions and 0 deletions
|
@ -44,9 +44,11 @@ describe('koaLog middleware', () => {
|
|||
log,
|
||||
};
|
||||
ctx.request.ip = ip;
|
||||
const additionalMockPayload: LogPayload = { foo: 'bar' };
|
||||
|
||||
const next = async () => {
|
||||
ctx.log(type, mockPayload);
|
||||
ctx.log(type, additionalMockPayload);
|
||||
};
|
||||
await koaLog()(ctx, next);
|
||||
|
||||
|
@ -55,6 +57,7 @@ describe('koaLog middleware', () => {
|
|||
type,
|
||||
payload: {
|
||||
...mockPayload,
|
||||
...additionalMockPayload,
|
||||
result: LogResult.Success,
|
||||
ip,
|
||||
userAgent,
|
||||
|
@ -62,6 +65,21 @@ describe('koaLog middleware', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should not insert a log when there is no log type', async () => {
|
||||
const ctx: WithLogContext<ReturnType<typeof createContextWithRouteParameters>> = {
|
||||
...createContextWithRouteParameters({ headers: { 'user-agent': userAgent } }),
|
||||
// Bypass middleware context type assert
|
||||
addLogContext,
|
||||
log,
|
||||
};
|
||||
ctx.request.ip = ip;
|
||||
|
||||
// eslint-disable-next-line unicorn/consistent-function-scoping
|
||||
const next = async () => Promise.resolve();
|
||||
await koaLog()(ctx, next);
|
||||
expect(insertLogMock).not.toBeCalled();
|
||||
});
|
||||
|
||||
describe('should insert an error log with the error message when next() throws an error', () => {
|
||||
it('should log with error message when next throws a normal Error', async () => {
|
||||
const ctx: WithLogContext<ReturnType<typeof createContextWithRouteParameters>> = {
|
||||
|
|
Loading…
Reference in a new issue