experimentCollect.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 /experimentCollect
  7. // Before each tests, start a server
  8. test.beforeEach(async t => (t.context.server = await getHttpServer()))
  9. test('POST /experimentCollect - No body', async t => {
  10. const res = await request(t.context.server)
  11. .post(`${apiPrefix}/experimentCollect`)
  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('msgId'), json(res.body))
  15. t.true(res.body.message.includes('msg'), json(res.body))
  16. })
  17. test('POST /experimentCollect - Invalid body parameters', async t => {
  18. const res = await request(t.context.server)
  19. .post(`${apiPrefix}/experimentCollect`)
  20. .send({ msgId: { notAstring: 'not a string' }, msg: 'Valid data' })
  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('"msgId" must be a string.')), json(res.body))
  24. })
  25. test('POST /experimentCollect - Valid body parameters', async t => {
  26. const res = await request(t.context.server)
  27. .post(`${apiPrefix}/experimentCollect`)
  28. .send({ msgId: 'TEST_FEATURE', msg: { some: 'data' } })
  29. t.is(res.status, 204)
  30. })