listScenesQualities.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict'
  2. import test from 'ava'
  3. import request from 'supertest'
  4. import { apiPrefix } from '../../../config'
  5. import { json, getHttpServer } from '../../utils/_test_functions'
  6. // ROUTE /listSceneQualities
  7. // Before each tests, start a server
  8. test.beforeEach(async t => (t.context.server = await getHttpServer()))
  9. test('GET /listSceneQualities', async t => {
  10. const res = await request(t.context.server)
  11. .get(`${apiPrefix}/listSceneQualities`)
  12. t.is(res.status, 400, json(res))
  13. t.true(res.body.message.includes('Missing parameter'), json(res.body))
  14. t.true(res.body.message.includes('sceneName'), json(res.body))
  15. })
  16. test('GET /listSceneQualities?sceneName=invalid/../scene', async t => {
  17. const res = await request(t.context.server)
  18. .get(`${apiPrefix}/listSceneQualities?sceneName=invalid/../scene`)
  19. t.is(res.status, 400, json(res))
  20. t.truthy(res.body.message.match(/The requested scene name.*is not valid/), json(res.body))
  21. })
  22. test('GET /listSceneQualities?sceneName=unknown-scene-name', async t => {
  23. const res = await request(t.context.server)
  24. .get(`${apiPrefix}/listSceneQualities?sceneName=unknown-scene-name`)
  25. t.is(res.status, 500, json(res))
  26. t.truthy(res.body.message.match(/Can't access.*scene dir.*Check it exist.*and you have read permission/), json(res.body))
  27. })
  28. test('GET /listSceneQualities?sceneName=bathroom', async t => {
  29. const res = await request(t.context.server)
  30. .get(`${apiPrefix}/listSceneQualities?sceneName=bathroom`)
  31. t.is(res.status, 200, json(res))
  32. t.true(Array.isArray(res.body.data) && res.body.data.every(x => Number.isInteger(x)), json(res.body))
  33. })