Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add src test method to workspace module. #1432

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions mod/workspace/_workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -275,3 +278,50 @@ 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)) {

// Will get layer and assignTemplates to workspace.
await getLocale({locale: localeKey})
}

// From here on its 🐢 Templates all the way down.
for (const key of Object.keys(workspace.templates)) {

const template = await getTemplate(key)

if (template.err) errArr.push(`${key}: ${template.err.path}`)
}

res.send(errArr.flat())
}
19 changes: 19 additions & 0 deletions public/tests/layer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading