/* eslint-disable unicorn/prefer-module */ /* * Copyright (C) 2019 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ import {expect} from 'chai'; import path from 'path'; import {fileURLToPath} from 'url'; import {stat, readFile} from 'fs/promises'; import {Validator} from '../src/index.js'; describe('Validator', function () { this.timeout(40_000); this.slow(5000); /** @type {import('json-schema').JSONSchema7} */ let schema; /** @type {import('@openstapps/core').SCThings[]} */ let instances = []; beforeEach(async function () { const resourceDirectory = path.join( path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'core', 'test', 'resources', ); /** @type {import('@openstapps/core').SCThings[]} */ instances = []; for (const file in await stat(resourceDirectory)) { if (file.endsWith('.json')) { const {instance} = JSON.parse(await readFile(path.join(resourceDirectory, file), 'utf8')); instances.push(instance); } } }); it('should validate schemas by their SCThingType', async function () { const validator = new Validator(); for (const instance of instances) { const validationResult = validator.validate(instance, instance.type); expect(validator.errors).to.be.empty; expect(validationResult).to.be.true; } }); });