Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit dca140c

Browse files
committed
add logout tests
1 parent 3c594d7 commit dca140c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

express-handlers.jest-test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ const mockResponse = () => {
99
return res;
1010
};
1111

12-
const { checkAuth } = require('./express-handlers');
12+
const { logout, checkAuth } = require('./express-handlers');
1313

1414
// describe('login', () => {});
15-
// describe('logout', () => {});
15+
describe('logout', () => {
16+
test('should set session.data to null', async () => {
17+
const req = mockRequest({ username: 'hugo' });
18+
const res = mockResponse();
19+
await logout(req, res);
20+
expect(req.session.data).toBeNull();
21+
});
22+
test('should 200', async () => {
23+
const req = mockRequest({ username: 'hugo' });
24+
const res = mockResponse();
25+
await logout(req, res);
26+
expect(res.status).toHaveBeenCalledWith(200);
27+
});
28+
});
1629
describe('checkAuth', () => {
1730
test('should 401 if session data is not set', async () => {
1831
const req = mockRequest();

express-handlers.sinon-test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ const mockResponse = () => {
1212
return res;
1313
};
1414

15-
const { checkAuth } = require('./express-handlers');
15+
const { logout, checkAuth } = require('./express-handlers');
16+
17+
test('logout > should set session.data to null', async (t) => {
18+
const req = mockRequest({ username: 'hugo' });
19+
const res = mockResponse();
20+
await logout(req, res);
21+
t.is(req.session.data, null);
22+
});
23+
24+
test('logout > should 200', async (t) => {
25+
const req = mockRequest({ username: 'hugo' });
26+
const res = mockResponse();
27+
await logout(req, res);
28+
t.true(res.status.calledWith(200));
29+
});
1630

1731
test('checkAuth > should 401 if session data is not set', async (t) => {
1832
const req = mockRequest();

0 commit comments

Comments
 (0)