From fa6fcc68ccc1e3af244d8c68470a7afb51e3b7c2 Mon Sep 17 00:00:00 2001 From: Loic Date: Tue, 28 Mar 2023 11:24:41 +0200 Subject: [PATCH] [feat] compute GET /configuration --- changelog.md | 1 + src/js/administrator/administrator.js | 11 ++++++++ src/js/apis/admin/1.0.0/index.js | 27 +++++++++++++++++++ .../cucumber/configurations/local-admin.json | 1 + .../cucumber/features/req-admin-1.0.0.feature | 24 +++++++++++++++++ 5 files changed, 64 insertions(+) diff --git a/changelog.md b/changelog.md index 2e00f61..414d2ef 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ ADDED: - Ajout de la route GET /admin/1.0.0/services dans l'API d'administration - Ajout de la route GET /admin/1.0.0/services/{service} dans l'API d'administration - Ajout de la route GET /admin/1.0.0/services/{service}/restart dans l'API d'administration + - Ajout de la route GET /admin/1.0.0/configuration dans l'API d'administration - Il est maintenant possible démarrer un administrateur sans services pré-configurés CHANGED: diff --git a/src/js/administrator/administrator.js b/src/js/administrator/administrator.js index 49084f4..bcca61d 100644 --- a/src/js/administrator/administrator.js +++ b/src/js/administrator/administrator.js @@ -56,6 +56,17 @@ module.exports = class Administrator { } + /** + * + * @function + * @name get configuration + * @description Récupérer la configuration de l'administrateur + * + */ + get configuration () { + return this._configuration; + } + /** * * @function diff --git a/src/js/apis/admin/1.0.0/index.js b/src/js/apis/admin/1.0.0/index.js index 19fa757..f82474c 100644 --- a/src/js/apis/admin/1.0.0/index.js +++ b/src/js/apis/admin/1.0.0/index.js @@ -69,6 +69,33 @@ router.route("/health") }); +// Configuration +// Pour avoir ou changer la configuration de l'administrateur +router.route("/configuration") + + .get(async function(req, res, next) { + + LOGGER.debug("requete GET sur /admin/1.0.0/configuration?"); + LOGGER.debug(req.originalUrl); + + // On récupère l'instance d'Administrator pour répondre aux requêtes + let administrator = req.app.get("administrator"); + + try { + + // Envoie à l'administrateur et récupération de l'objet réponse + const configurationResponse = administrator.configuration; + LOGGER.debug(configurationResponse); + + res.set('content-type', 'application/json'); + res.status(200).json(configurationResponse); + + } catch (error) { + return next(error); + } + + }); + // Services // Pour avoir des informations sur les services router.route("/services") diff --git a/test/functional/request/cucumber/configurations/local-admin.json b/test/functional/request/cucumber/configurations/local-admin.json index aee46ec..1b4a3e6 100644 --- a/test/functional/request/cucumber/configurations/local-admin.json +++ b/test/functional/request/cucumber/configurations/local-admin.json @@ -7,6 +7,7 @@ "1.0.0": { "health": "/admin/1.0.0/health", "version": "/admin/1.0.0/version", + "configuration": "/admin/1.0.0/configuration", "services": "/admin/1.0.0/services", "services/": "/admin/1.0.0/services/", "services//restart": "/admin/1.0.0/services//restart" diff --git a/test/functional/request/cucumber/features/req-admin-1.0.0.feature b/test/functional/request/cucumber/features/req-admin-1.0.0.feature index 2ea6b63..092f0cf 100644 --- a/test/functional/request/cucumber/features/req-admin-1.0.0.feature +++ b/test/functional/request/cucumber/features/req-admin-1.0.0.feature @@ -66,6 +66,30 @@ Feature: Road2 with data Then the server should send a response with status 404 And the response should contain "Not found" + Scenario: [admin/1.0.0] Configuration de l'administrateur + Given an "GET" request on operation "configuration" in api "admin" "1.0.0" + When I send the request + Then the server should send a response with status 200 + And the response should contain "administration" + + Scenario: [admin/1.0.0] Configuration de l'administrateur avec un mauvais parametre + Given an "GET" request on operation "configuration" in api "admin" "1.0.0" + And with query parameters: + | key | value | + | test | other | + When I send the request + Then the server should send a response with status 200 + And the response should contain "administration" + + Scenario: [admin/1.0.0] Configuration de l'administrateur en POST ne marche pas + Given an "POST" request on operation "configuration" in api "admin" "1.0.0" + And with query parameters: + | key | value | + | test | other | + When I send the request + Then the server should send a response with status 404 + And the response should contain "Not found" + Scenario: [admin/1.0.0] Configurations des services Given an "GET" request on operation "services" in api "admin" "1.0.0" When I send the request