-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsession-auth.test.js
45 lines (39 loc) · 1.28 KB
/
session-auth.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const testWithServer = require('./helpers/test-with-server');
const config = require('../config');
testWithServer('Authentication is ok', {}, async (t, ctx) => {
t.plan(2);
// mock config user
const user = config.user;
const password = config.password;
config.user = 'testUser';
config.password = 'securePassword';
const htmlRequest = {
method: 'POST',
url: '/session',
payload: { username: 'testUser', password: 'securePassword' }
};
const res = await ctx.server.inject(htmlRequest);
t.equal(res.statusCode, 302, 'Authentication is ok and staus code rediction 302');
t.equal(res.headers.location, '/', 'Redirect to home page');
config.user = user;
config.password = password;
t.end();
}, true);
testWithServer('Authentication is not ok', {}, async (t, ctx) => {
t.plan(1);
// mock config user
const user = config.user;
const password = config.password;
config.user = 'testUser';
config.password = 'securePassword';
const htmlRequest = {
method: 'POST',
url: '/session',
payload: { username: 'wrongUser', password: 'wrongPassword' }
};
const res = await ctx.server.inject(htmlRequest);
t.equal(res.statusCode, 200, 'status code 200, display login page');
config.user = user;
config.password = password;
t.end();
}, true);