1 | const hapi = require('hapi')
|
2 | const akaya = require('akaya')
|
3 | const qs = require('qs')
|
4 | const url = require('url')
|
5 | const plugin = require('../src')
|
6 | const mockResponse = require('./fixtures/index')
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | const mockPluginOptions = {
|
16 | absolute: false,
|
17 | paramNames: {
|
18 | perPage: 'per_page',
|
19 | page: 'page',
|
20 | total: 'total'
|
21 | }
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | const setup = async (options, pluginOptions) => {
|
36 | pluginOptions = pluginOptions || mockPluginOptions
|
37 |
|
38 | const key = (options && options.key) || 'result'
|
39 | const fixtures = {
|
40 | server: hapi.server({
|
41 | port: 1337,
|
42 | host: 'localhost'
|
43 | }),
|
44 | host: 'http://localhost:1337/'
|
45 | }
|
46 |
|
47 | fixtures.server.route([
|
48 | {
|
49 | method: 'GET',
|
50 | path: '/',
|
51 | config: {
|
52 | id: 'foo',
|
53 | handler (req, h) {
|
54 | return h.bissle({ [key]: Array.from(mockResponse) }, options)
|
55 | }
|
56 | }
|
57 | },
|
58 | {
|
59 | method: 'GET',
|
60 | path: '/page',
|
61 | config: {
|
62 | handler (req, h) {
|
63 | return h.bissle({ [key]: Array.from(mockResponse) }, options)
|
64 | }
|
65 | }
|
66 | }
|
67 | ])
|
68 |
|
69 | await fixtures.server.register([akaya, {
|
70 | plugin,
|
71 | options: pluginOptions
|
72 | }])
|
73 |
|
74 | return fixtures
|
75 | }
|
76 |
|
77 | const getQueries = path => qs.parse(url.parse(path).query).query
|
78 | const getParams = path => qs.parse(url.parse(path).query).params
|
79 |
|
80 | module.exports = {
|
81 | setup,
|
82 | getQueries,
|
83 | getParams
|
84 | }
|