Parcourir la source

Update /dataCollect documentation and test

rigwild il y a 4 ans
Parent
commit
f06789ca33
2 fichiers modifiés avec 13 ajouts et 4 suppressions
  1. 7 2
      server/routes/dataCollect.js
  2. 6 2
      test/server/api/dataCollect.js

+ 7 - 2
server/routes/dataCollect.js

@@ -20,10 +20,13 @@ const router = express.Router()
  * @apiDescription Collect user's data
  *
  * @apiParam {String} uuid The unique user identifier
+ * @apiParam {String} userId The user ID
+ * @apiParam {String} experimentId The experiment ID
+ * @apiParam {String} uuid The unique user identifier
  * @apiParam {Object} screen Screen data, `window.screen` @see https://developer.mozilla.org/en-US/docs/Web/API/Screen
  *
  * @apiExample Usage example
- * curl -i -L -H "Content-Type: application/json" -X POST "http://diran.univ-littoral.fr/api/dataCollect" -d {"uuid":"test","screen":{"width":1920,"height":1024}}
+ * curl -i -L -H "Content-Type: application/json" -X POST "http://diran.univ-littoral.fr/api/dataCollect" -d {"uuid":"test","userId":"rigwild","experimentId":"expe-test","screen":{"width":1920,"height":1024}}
  *
  * @apiSuccessExample {string} Success response example
  * HTTP/1.1 200 OK /api/dataCollect
@@ -33,7 +36,7 @@ const router = express.Router()
  * @apiErrorExample {json} Missing parameter
  * HTTP/1.1 400 Bad Request
  * {
- *   "message": "Missing parameter(s). Required parameters : uuid, screen."
+ *   "message": "Missing parameter(s). Required parameters : uuid, userId, experimentId, screen."
  * }
  *
  * @apiError (Error 4xx) 400_[2] Invalid query parameter
@@ -43,6 +46,8 @@ const router = express.Router()
  *   "message": "Invalid body parameter(s).",
  *   "data": [
  *     "\"uuid\" must be a string.",
+ *     "\"userId\" must be a string.",
+ *     "\"experimentId\" must be a string.",
  *     "\"screen\" must be a valid object."
  *   ]
  * }

+ 6 - 2
test/server/api/dataCollect.js

@@ -17,24 +17,28 @@ test('POST /dataCollect - No body', async t => {
   t.is(res.status, 400, json(res))
   t.true(res.body.message.includes('Missing parameter'), json(res.body))
   t.true(res.body.message.includes('uuid'), json(res.body))
+  t.true(res.body.message.includes('userId'), json(res.body))
+  t.true(res.body.message.includes('experimentId'), json(res.body))
   t.true(res.body.message.includes('screen'), json(res.body))
 })
 
 test('POST /dataCollect - Invalid body parameters', async t => {
   const res = await request(t.context.server)
     .post(`${apiPrefix}/dataCollect`)
-    .send({ uuid: 42, screen: 'not an object' })
+    .send({ uuid: 42, userId: 42, experimentId: 42, screen: 'not an object' })
 
   t.is(res.status, 400, json(res))
   t.true(res.body.message.includes('Invalid body parameter'), json(res.body))
   t.truthy(res.body.data.find(x => x.includes('"uuid" must be a string.')), json(res.body))
+  t.truthy(res.body.data.find(x => x.includes('"userId" must be a string.')), json(res.body))
+  t.truthy(res.body.data.find(x => x.includes('"experimentId" must be a string.')), json(res.body))
   t.truthy(res.body.data.find(x => x.includes('"screen" must be a valid object.')), json(res.body))
 })
 
 test('POST /dataCollect - Valid body parameters', async t => {
   const res = await request(t.context.server)
     .post(`${apiPrefix}/dataCollect`)
-    .send({ uuid: 'test', screen: { width: 1920, height: 1080 } })
+    .send({ uuid: 'test', userId: 'user-test', experimentId: 'expe-test', screen: { width: 1920, height: 1080 } })
 
   t.is(res.status, 200, json(res))
   t.is(res.body.message, 'OK', json(res.body))