'use strict' const test = require('ava') const Hapi = require('@hapi/hapi') const plugin = require('../lib/plugins/notification') /** * Route parameters */ const params = { profile_id: 37 } const mockReturn = { queue: [ { mocked_profile_id: 1, target_id: 2, is_deleted: false }, { mocked_profile_id: 2, target_id: 3, is_deleted: false }, { mocked_profile_id: 3, target_id: 1, is_deleted: false }, ], } const pathToTest = { method: 'GET', url: `/${params.profile_id}/subscribe`, } test('path /subscribe should return ok on GET', async t => { /** * Create a new server and register services, * models and routes for testing * - * NOTE: We use a mocked registerModel() and register * models manually. Normally this is handled by * Schwifty at runtime. */ const server = Hapi.server() /** * Register Routes and Services as usual */ await plugin.register(server) /** * Test the server with registered models and services */ const { payload } = await server.inject(pathToTest) console.log('---') console.log(payload) const res = JSON.parse(payload) t.deepEqual(res.ok, true) t.deepEqual( res.data, mockReturn.queue.map(entry => entry.target_id), ) })