Skip to content

Commit e44a08b

Browse files
committed
Use LogMock and check for logger infos to be called
1 parent 9358315 commit e44a08b

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/auth/AuthService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class AuthService {
2727
return authorization.split(' ')[1];
2828
}
2929

30-
this.log.info('No Token provided by the client');
30+
this.log.info('No Token provided by the client');
3131
return;
3232
}
3333

test/unit/auth/AuthService.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@ import { Request } from 'express';
22
import * as request from 'request';
33
import * as MockExpressRequest from 'mock-express-request';
44
import * as nock from 'nock';
5+
import { LogMock } from './../lib/LogMock';
56
import { AuthService } from './../../../src/auth/AuthService';
6-
import { LoggerInterface } from './../../../src/core/LoggerInterface';
77
import { env } from './../../../src/core/env';
88

99

1010
describe('AuthService', () => {
1111

1212
let authService: AuthService;
13+
let log: LogMock;
1314
beforeEach(() => {
14-
const log: LoggerInterface = {
15-
debug: () => void 0,
16-
info: () => void 0,
17-
warn: () => void 0,
18-
error: () => void 0,
19-
};
15+
log = new LogMock();
2016
authService = new AuthService(request, log);
2117
});
2218

@@ -39,12 +35,14 @@ describe('AuthService', () => {
3935
});
4036
const token = authService.parseTokenFromRequest(req);
4137
expect(token).toBeUndefined();
38+
expect(log.infoMock).toBeCalledWith('info', 'No Token provided by the client', []);
4239
});
4340

4441
test('Should return undefined if there is no "Authorization" header', () => {
4542
const req: Request = new MockExpressRequest();
4643
const token = authService.parseTokenFromRequest(req);
4744
expect(token).toBeUndefined();
45+
expect(log.infoMock).toBeCalledWith('info', 'No Token provided by the client', []);
4846
});
4947
});
5048

0 commit comments

Comments
 (0)