From aafb6faab17df52d9a6dfb4f9e34f0c58f35ad73 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Thu, 22 Aug 2024 20:31:20 +0100 Subject: [PATCH 1/5] Add src test method to workspace module. --- mod/workspace/_workspace.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mod/workspace/_workspace.js b/mod/workspace/_workspace.js index 41e2a60fe..bdb038441 100644 --- a/mod/workspace/_workspace.js +++ b/mod/workspace/_workspace.js @@ -35,11 +35,14 @@ const getLocale = require('./getLocale') const getLayer = require('./getLayer') +const getTemplate = require('./getTemplate') + const keyMethods = { layer, locale, locales, roles, + test, } let workspace; @@ -275,3 +278,23 @@ function roles(req, res) { res.send(roles) } +async function test(req, res) { + + const errArr = [] + + for (localeKey of Object.keys(workspace.locales)) { + + // Will get layer and assignTemplates to workspace. + await getLocale({locale: localeKey}) + } + + // From here on its Templates all the way down. + for (key of Object.keys(workspace.templates)) { + + const template = await getTemplate(key) + + if (template.err) errArr.push(`${key}: ${template.err.path}`) + } + + res.send(errArr.flat()) +} \ No newline at end of file From 0be1d0ac3f2617fad8d6161212636759a285a0bb Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Thu, 22 Aug 2024 20:33:51 +0100 Subject: [PATCH 2/5] declare variables --- mod/workspace/_workspace.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/workspace/_workspace.js b/mod/workspace/_workspace.js index bdb038441..af3ece59a 100644 --- a/mod/workspace/_workspace.js +++ b/mod/workspace/_workspace.js @@ -282,14 +282,14 @@ async function test(req, res) { const errArr = [] - for (localeKey of Object.keys(workspace.locales)) { + for (const localeKey of Object.keys(workspace.locales)) { // Will get layer and assignTemplates to workspace. await getLocale({locale: localeKey}) } // From here on its Templates all the way down. - for (key of Object.keys(workspace.templates)) { + for (const key of Object.keys(workspace.templates)) { const template = await getTemplate(key) From b26655593f99c976d30d7340c42d947f24f95967 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Thu, 22 Aug 2024 20:37:11 +0100 Subject: [PATCH 3/5] turtle test --- mod/workspace/_workspace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/workspace/_workspace.js b/mod/workspace/_workspace.js index af3ece59a..7912a2dd8 100644 --- a/mod/workspace/_workspace.js +++ b/mod/workspace/_workspace.js @@ -288,7 +288,7 @@ async function test(req, res) { await getLocale({locale: localeKey}) } - // From here on its Templates all the way down. + // From here on its 🐢 Templates all the way down. for (const key of Object.keys(workspace.templates)) { const template = await getTemplate(key) From 38b16239b4c599cec8c624fd999bf2cfbced6218 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Mon, 2 Sep 2024 15:52:52 +0100 Subject: [PATCH 4/5] document test method --- mod/workspace/_workspace.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/mod/workspace/_workspace.js b/mod/workspace/_workspace.js index 7912a2dd8..37e53e1d3 100644 --- a/mod/workspace/_workspace.js +++ b/mod/workspace/_workspace.js @@ -278,8 +278,35 @@ function roles(req, res) { res.send(roles) } +/** +@function test + +@description +The workspace/test method which is only available to user with admin credentials requests all locales in workspace. + +Requesting all locales should add any additional templates to the workspace. + +The test method will iterate over all workspace.templates and get from the getTemplate method to check whether any errors are logged on a template in regards to its src parameter. + +A flat array of template.err will be returned from the workspace/test method. + +@param {req} req HTTP request. +@param {req} res HTTP response. + +@property {Object} req.params +HTTP request parameter. +@property {Object} params.user +The user requesting the test method. +@property {Boolean} user.admin +The user is required to have admin priviliges. +*/ async function test(req, res) { + if (!req.params.user?.admin) { + res.status(403).send(`Admin credentials are required to test the workspace sources.`) + return + } + const errArr = [] for (const localeKey of Object.keys(workspace.locales)) { @@ -297,4 +324,4 @@ async function test(req, res) { } res.send(errArr.flat()) -} \ No newline at end of file +} From 3b5da4e1eeca73288e4cce2daccd74694d1735ab Mon Sep 17 00:00:00 2001 From: Simon Leech <56163132+simon-leech@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:48:32 +0100 Subject: [PATCH 5/5] Add new Template Paths Test --- public/tests/layer.test.mjs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/public/tests/layer.test.mjs b/public/tests/layer.test.mjs index 63042eb74..d0edea1b4 100644 --- a/public/tests/layer.test.mjs +++ b/public/tests/layer.test.mjs @@ -8,7 +8,26 @@ export async function layerTest(mapview) { const default_zoom = mapview.view?.z || 0; + await codi.describe(`${mapview.host} : Template Paths Test`, async () => { + + await codi.it('All the templates are valid', async () => { + // Call the /test workspace method - which should return an empty array if all templates are valid. + const test = await mapp.utils.xhr(`${mapp.host}/api/workspace/test`); + + // If the test fails, print out the invalid templates. + if (test.length > 0) { + test.forEach(template => { + console.error('INVALID PATH:', template); + }); + } + + codi.assertTrue(test.length === 0, `There are ${test.length} invalid paths for templates`); + + }); + }); + await codi.describe(`${mapview.host} : Layer Test`, async () => { + for (const key in mapview.layers) { if (mapview.layers.hasOwnProperty(key)) { await codi.it(`Layer test : ${key}`, async () => {