1 | const nock = require('nock')
|
2 | const test = require('ava')
|
3 | const helpers = require('./_helpers')
|
4 | const fixtures = require('./fixtures')
|
5 |
|
6 | const cfg = helpers.getOptions({ secret: fixtures.common.secret })
|
7 |
|
8 | test.afterEach.always('reset instances and prototypes', () => {
|
9 | nock.cleanAll()
|
10 | })
|
11 |
|
12 | test('server method – authentication supports mode: "optional" - will succeed without auth', async (t) => {
|
13 | const server = await helpers.getServer(cfg)
|
14 | const res = await server.inject({
|
15 | method: 'GET',
|
16 | url: '/mode-optional'
|
17 | })
|
18 |
|
19 | t.truthy(res)
|
20 | t.is(res.statusCode, 200)
|
21 | })
|
22 |
|
23 | test('server method – authentication supports mode: "optional" - will fail with invalid auth', async (t) => {
|
24 | const mockReq = helpers.mockRequest(fixtures.common.token, '/mode-optional')
|
25 | const server = await helpers.getServer(cfg)
|
26 | const res = await server.inject(mockReq)
|
27 |
|
28 | t.truthy(res)
|
29 | t.is(res.statusCode, 401)
|
30 | })
|
31 |
|
32 | test('server method – authentication supports mode: "try" - will succeed with invalid auth', async (t) => {
|
33 | const mockReq = helpers.mockRequest(fixtures.common.token, '/mode-try')
|
34 | const server = await helpers.getServer(cfg)
|
35 | const res = await server.inject(mockReq)
|
36 |
|
37 | t.truthy(res)
|
38 | t.is(res.statusCode, 200)
|
39 | })
|