From 219c103fb88860ecb7ff6aeb1240fca167eb53d1 Mon Sep 17 00:00:00 2001 From: tree Date: Sun, 8 Oct 2023 01:16:03 +0200 Subject: [PATCH] categories validation --- src/categories.yaml | 10 ++++++---- utils/test.js | 23 ++++++++++++++++------- utils/w3pdata.js | 7 +------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/categories.yaml b/src/categories.yaml index 98b2733f..111c347b 100644 --- a/src/categories.yaml +++ b/src/categories.yaml @@ -12,7 +12,7 @@ name: Layer 2 - id: hardware name: Hardware -- id: vpm +- id: vpn name: VPN - id: did name: DID @@ -38,8 +38,8 @@ name: NFT - id: other name: Other -- id: alliance - name: Alliance +- id: alliances + name: Alliances - id: mixing-management name: Mixing management - id: data-management @@ -48,5 +48,7 @@ name: Donate - id: rd name: R&D -- id: mixing-services +- id: mixing-service name: Mixing services +- id: node + name: Node diff --git a/utils/test.js b/utils/test.js index 2831f379..a95b27db 100644 --- a/utils/test.js +++ b/utils/test.js @@ -27,19 +27,28 @@ const matrix = { const schemaDir = "./schema"; const schemas = await loadSchemas(); +schemas.project.properties.categories.items.enum = w3pd.data.categories.map(c => c.id) + for (const col of Object.keys(w3pd.data)) { const validator = ajv.compile(schemas[matrix[col]]); + const ids = [] for (const item of w3pd.data[col]) { + const testName = `${col}/${item.id} ` + (col === 'projects' ? `[${item.categories?.join(', ')}]` : '') - if(Object.keys(item).length === 1) { - continue + if (ids.includes(item.id)) { + Deno.test(testName + ' (id-duplicates)', () => { + throw { message: `Duplicate project id="${item.id}"` } + }); } - Deno.test(`${col}/${item.id} ` + (col === 'projects' ? `[${item.categories?.join(', ')}]` : ''), () => { - if (!validator(item)) { - throw validator.errors; - } - }); + if(Object.keys(item).length > 1) { + Deno.test(testName + ' (schema)', () => { + if (!validator(item)) { + throw validator.errors; + } + }); + } + ids.push(item.id) } } diff --git a/utils/w3pdata.js b/utils/w3pdata.js index b73bd465..34e18596 100644 --- a/utils/w3pdata.js +++ b/utils/w3pdata.js @@ -27,12 +27,7 @@ export class W3PData { } const pDir = `${catDir}/${pd.name}`; const indexFn = `${pDir}/index.yaml`; - try { - await Deno.stat(indexFn); - } catch(e) { - continue - } - + const index = yaml.load( await Deno.readTextFile(indexFn), );