Parcourir la source

Export ping, change doc routes name to /route. Ping route test

rigwild il y a 4 ans
Parent
commit
8ddb066e9a

+ 8 - 3
server/routes/getImage.js

@@ -10,9 +10,9 @@ import { asyncMiddleware, checkSceneName, checkRequiredParameters, getSceneFiles
 const router = express.Router()
 
 /**
- * @api {get} /getImage?sceneName=:sceneName&imageQuality=:imageQuality&nearestQuality=:nearestQuality Get an image from a scene
+ * @api {get} /getImage?sceneName=:sceneName&imageQuality=:imageQuality&nearestQuality=:nearestQuality /getImage
  * @apiVersion 0.1.0
- * @apiName GetImage
+ * @apiName getImage
  * @apiGroup API
  *
  * @apiDescription Get an image from a scene with the required quality
@@ -24,7 +24,12 @@ const router = express.Router()
  * @apiExample Usage example
  * curl -i -L -X GET "http://diran.univ-littoral.fr/api/getImage?sceneName=bathroom&imageQuality=200"
  *
- * @apiSuccess {String} data Path to the image
+ * @apiSuccess {Object} data Informations on the image
+ * @apiSuccess {String} data.link Path to the image
+ * @apiSuccess {String} data.fileName File name of the image
+ * @apiSuccess {String} data.sceneName Scene name of the image
+ * @apiSuccess {Number} data.quality Quality of the image
+ * @apiSuccess {String} data.ext Extension of the image
  * @apiSuccessExample {json} Success response example
  * HTTP/1.1 200 OK /api/getImage?sceneName=bathroom&imageQuality=200
  * {

+ 12 - 5
server/routes/getImageExtracts.js

@@ -13,12 +13,12 @@ import { getImage } from './getImage'
 const router = express.Router()
 
 /**
- * @api {get} /getImageExtracts?sceneName=:sceneName&imageQuality=:imageQuality&horizontalExtractCount=:horizontalExtractCount&verticalExtractCount=:verticalExtractCount&nearestQuality=:nearestQuality Get image extracts
+ * @api {get} /getImageExtracts?sceneName=:sceneName&imageQuality=:imageQuality&horizontalExtractCount=:horizontalExtractCount&verticalExtractCount=:verticalExtractCount&nearestQuality=:nearestQuality /getImageExtracts
  * @apiVersion 0.1.0
- * @apiName GetImageExtracts
+ * @apiName getImageExtracts
  * @apiGroup API
  *
- * @apiDescription Get an image from a scene with the required quality and cut it with the requested configuration
+ * @apiDescription Get an image from a scene with the required quality and cut it into multiple extracts with the requested configuration
  *
  * @apiParam {String} sceneName The selected scene
  * @apiParam {String="min","max","median", "any integer"} imageQuality The required quality of the image (can be an integer, `min`, `max` or `median`)
@@ -29,12 +29,19 @@ const router = express.Router()
  * @apiExample Usage example
  * curl -i -L -X GET "http://diran.univ-littoral.fr/api/getImageExtracts?sceneName=bathroom&imageQuality=200&horizontalExtractCount=1&verticalExtractCount=2"
  *
- * @apiSuccess {String[]} data Path to the extracted images
+ * @apiSuccess {Object} data Path to the extracted images
+ * @apiSuccess {String[]} data.extracts Path to the extracted images
+ * @apiSuccess {Object} data.info Informations on the original image
+ * @apiSuccess {String} data.info.link Path to the original image
+ * @apiSuccess {String} data.info.fileName File name of the original image
+ * @apiSuccess {String} data.info.sceneName Scene name of the original image
+ * @apiSuccess {Number} data.info.quality Quality of the original image
+ * @apiSuccess {String} data.info.ext Extension of the original image
  * @apiSuccessExample {json} Success response example
  * HTTP/1.1 200 OK /api/getImageExtracts?sceneName=bathroom&imageQuality=200&horizontalExtractCount=1&verticalExtractCount=2
  * {
  *   "data": {
- *     extracts: [
+ *     "extracts": [
  *       "/api/images/bathroom/extracts/x1_y2/zone00001/bathroom_zone00001_200.png",
  *       "/api/images/bathroom/extracts/x1_y2/zone00002/bathroom_zone00002_200.png"
  *     ],

+ 2 - 1
server/routes/index.js

@@ -5,6 +5,7 @@ import listScenes from './listScenes'
 import listSceneQualities from './listSceneQualities'
 import getImage from './getImage'
 import getImageExtracts from './getImageExtracts'
+import ping from './ping'
 
 const router = express.Router()
 
@@ -12,6 +13,6 @@ router.use('/listScenes', listScenes)
 router.use('/listSceneQualities', listSceneQualities)
 router.use('/getImage', getImage)
 router.use('/getImageExtracts', getImageExtracts)
-router.get('/ping', (req, res) => res.send('pong'))
+router.get('/ping', ping)
 
 export default router

+ 2 - 2
server/routes/listSceneQualities.js

@@ -6,9 +6,9 @@ import { asyncMiddleware, checkRequiredParameters, getSceneFilesData } from '../
 const router = express.Router()
 
 /**
- * @api {get} /listSceneQualities?sceneName=:sceneName Get a list of available qualities for a scene
+ * @api {get} /listSceneQualities?sceneName=:sceneName /listSceneQualities
  * @apiVersion 0.1.0
- * @apiName ListScenesQualities
+ * @apiName listScenesQualities
  * @apiGroup API
  *
  * @apiDescription List all available qualities for a given scene

+ 2 - 2
server/routes/listScenes.js

@@ -10,9 +10,9 @@ import { imagesPath } from '../../config'
 const router = express.Router()
 
 /**
- * @api {get} /listScenes Get a list of all available scenes
+ * @api {get} /listScenes /listScenes
  * @apiVersion 0.1.0
- * @apiName GetListScenes
+ * @apiName listScenes
  * @apiGroup API
  *
  * @apiDescription List all scenes availables in your `IMAGES_PATH` directory

+ 25 - 0
server/routes/ping.js

@@ -0,0 +1,25 @@
+'use strict'
+
+import express from 'express'
+
+const router = express.Router()
+
+/**
+ * @api {get} /ping /ping
+ * @apiVersion 0.1.0
+ * @apiName ping
+ * @apiGroup API
+ *
+ * @apiDescription Check if the API is up
+ *
+ * @apiExample Usage example
+ * curl -i -L -X GET "http://diran.univ-littoral.fr/api/ping"
+ *
+ * @apiSuccessExample {string} Success response example
+ * HTTP/1.1 200 OK /api/ping
+ * pong
+ */
+
+router.get('/ping', (req, res) => res.send('pong'))
+
+export default router

+ 19 - 0
test/api/ping.js

@@ -0,0 +1,19 @@
+'use strict'
+
+import test from 'ava'
+import request from 'supertest'
+import { apiPrefix } from '../../config'
+import { json, getHttpServer } from './_test_functions'
+
+// ROUTE /ping
+
+// Before each tests, start a server
+test.beforeEach(async t => (t.context.server = await getHttpServer()))
+
+test('GET /ping', async t => {
+  const res = await request(t.context.server)
+    .get(`${apiPrefix}/ping`)
+
+  t.is(res.status, 200, json(res))
+  t.is(res.text, 'pong')
+})