You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

notification.spec.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict'
  2. const test = require('ava')
  3. const Hapi = require('@hapi/hapi')
  4. const plugin = require('../lib/plugins/notification')
  5. /**
  6. * Route parameters
  7. */
  8. const params = {
  9. profile_id: 37
  10. }
  11. const mockReturn = {
  12. queue: [
  13. { mocked_profile_id: 1, target_id: 2, is_deleted: false },
  14. { mocked_profile_id: 2, target_id: 3, is_deleted: false },
  15. { mocked_profile_id: 3, target_id: 1, is_deleted: false },
  16. ],
  17. }
  18. const pathToTest = {
  19. method: 'GET',
  20. url: `/${params.profile_id}/subscribe`,
  21. }
  22. test('path /subscribe should return ok on GET', async t => {
  23. /**
  24. * Create a new server and register services,
  25. * models and routes for testing
  26. * -
  27. * NOTE: We use a mocked registerModel() and register
  28. * models manually. Normally this is handled by
  29. * Schwifty at runtime.
  30. */
  31. const server = Hapi.server()
  32. /**
  33. * Register Routes and Services as usual
  34. */
  35. await plugin.register(server)
  36. /**
  37. * Test the server with registered models and services
  38. */
  39. const { payload } = await server.inject(pathToTest)
  40. console.log('---')
  41. console.log(payload)
  42. const res = JSON.parse(payload)
  43. t.deepEqual(res.ok, true)
  44. t.deepEqual(
  45. res.data,
  46. mockReturn.queue.map(entry => entry.target_id),
  47. )
  48. })