UNPKG

1.23 kBJavaScriptView Raw
1const nock = require('nock')
2const test = require('ava')
3const helpers = require('./_helpers')
4const fixtures = require('./fixtures')
5
6const cfg = helpers.getOptions({ secret: fixtures.common.secret })
7
8test.afterEach.always('reset instances and prototypes', () => {
9 nock.cleanAll()
10})
11
12test('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
23test('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
32test('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})