Issues (83)

tests/router/common-api-router.test.js (14 issues)

1
/** global: jest */
2
/* global jest describe test expect beforeAll afterAll jasmine */
3
4
// Load local environments
5
require('dotenv').config();
0 ignored issues
show
Expected 1 empty line after require statement not followed by another require.
Loading history...
6
process.env.PORT = 9000;
7
8
const Server = require('../../src/server');
9
const User = require('../../src/repository/User');
10
const config = require('../../src/config/server.config.js');
11
12
jest.dontMock('console');
13
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;  // 10s
0 ignored issues
show
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
14
15
const serverPromise = Server.start();
16
17
const user1 = {
18
  username: 'testuser',
19
  password: 'testuser',
20
  isTemporary: false,
21
};
22
23
const validPassword = 'valid-password';
24
const shortPassword = 'short';
25
26
describe('User', () => {
27
  let id;
28
  const loginUrl = `${config.url.apiPrefix}/login`;
29
  const changePasswordUrl = `${config.url.apiPrefix}/passwords`;
30
31
  beforeAll(() => User.add(user1).then((result) => {
32
    id = result.data[0]._id;
33
  }));
34
35
  test('login success', () => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
36
    return serverPromise.then((server) => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
37
      return server.inject({ url: loginUrl, method: 'POST', payload: user1 }).then((response) => {
38
        expect(response.statusCode).toBe(200);
39
        const payload = JSON.parse(response.payload);
40
        expect(payload).toBeDefined();
41
        expect(payload.success).toBe(true);
42
      });
43
    });
44
  });
45
46
  test('login fail', () => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
47
    return serverPromise.then((server) => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
48
      return server.inject({
49
        url: loginUrl,
50
        method: 'POST',
51
        payload: { username: user1.username, password: `no-${user1.password}` }
0 ignored issues
show
Missing trailing comma.
Loading history...
52
      }).then((response) => {
53
        expect(response.statusCode).toBe(401);
54
        const payload = JSON.parse(response.payload);
55
        expect(payload).toBeDefined();
56
        expect(payload.success).toBe(false);
57
       });
0 ignored issues
show
Expected indentation of 6 spaces but found 7.
Loading history...
58
    });
59
  });
60
61
  test('change password', () => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
62
    return serverPromise.then((server) => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
63
      return server.inject({
64
        url: changePasswordUrl,
65
        method: 'PUT',
66
        payload: { password: validPassword },
67
        credentials: { username: 'testuser' },
68
      }).then((response) => {
69
        expect(response.statusCode).toBe(200);
70
      });
71
    });
72
  });
73
74
  test('change password without authentication', () => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
75
    return serverPromise.then((server) => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
76
      return server.inject({ url: changePasswordUrl, method: 'PUT', payload: { password: shortPassword } })
77
        .then((response) => {
78
          expect(response.statusCode).toBe(401);
79
        });
80
    });
81
  });
82
83
  test('change password with invalid password', () => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
84
    return serverPromise.then((server) => {
0 ignored issues
show
Unexpected block statement surrounding arrow body; move the returned value immediately after the =>.
Loading history...
85
      return server.inject({
86
        url: changePasswordUrl,
87
        method: 'PUT',
88
        payload: { password: shortPassword },
89
        credentials: { username: 'testuser' },
90
      }).then((response) => {
91
        expect(response.statusCode).toBe(400);
92
      });
93
    });
94
  });
95
96
  afterAll(() => User.remove(id));
97
});
98