dataCollect.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict'
  2. import test from 'ava'
  3. import request from 'supertest'
  4. import { apiPrefix } from '../../config'
  5. import { json, getHttpServer } from './_test_functions'
  6. // ROUTE /dataCollect
  7. // Before each tests, start a server
  8. test.beforeEach(async t => (t.context.server = await getHttpServer()))
  9. test('POST /dataCollect - No body', async t => {
  10. const res = await request(t.context.server)
  11. .post(`${apiPrefix}/dataCollect`)
  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('uuid'), json(res.body))
  15. t.true(res.body.message.includes('screen'), json(res.body))
  16. })
  17. test('POST /dataCollect - Invalid body parameters', async t => {
  18. const res = await request(t.context.server)
  19. .post(`${apiPrefix}/dataCollect`)
  20. .send({ uuid: 42, screen: 'not an object' })
  21. t.is(res.status, 400, json(res))
  22. t.true(res.body.message.includes('Invalid body parameter'), json(res.body))
  23. t.truthy(res.body.data.find(x => x.includes('"uuid" must be a string.')), json(res.body))
  24. t.truthy(res.body.data.find(x => x.includes('"screen" must be a valid object.')), json(res.body))
  25. })
  26. test('POST /dataCollect - Valid body parameters', async t => {
  27. const res = await request(t.context.server)
  28. .post(`${apiPrefix}/dataCollect`)
  29. .send({ uuid: 'test', screen: { width: 1920, height: 1080 } })
  30. t.is(res.status, 200, json(res))
  31. t.is(res.body.message, 'OK', json(res.body))
  32. })