From 52bab5013e6f53c859f938806db425fc4fd7f2d1 Mon Sep 17 00:00:00 2001 From: Evan Hahn Date: Thu, 12 Dec 2024 14:09:31 -0600 Subject: [PATCH] test: assert that generated data is valid (#32) This beefs up our tests for `generate` by making sure that they pass `@comapeo/schema`'s `validate` function. --- test/generate.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/generate.test.js b/test/generate.test.js index e7db4ad..6954244 100644 --- a/test/generate.test.js +++ b/test/generate.test.js @@ -1,8 +1,9 @@ -import { encode } from '@comapeo/schema' +import { encode, validate, valueOf } from '@comapeo/schema' +import assert from 'node:assert/strict' import test from 'node:test' import { generate, listSchemas } from '../index.js' -test('generates encodable data', { concurrency: true }, async (t) => { +test('generates valid data', { concurrency: true }, async (t) => { const COUNT = 1000 const schemaNames = Object.keys(listSchemas()) @@ -11,6 +12,7 @@ test('generates encodable data', { concurrency: true }, async (t) => { if (schemaName === 'coreOwnership') continue await t.test(schemaName, () => { for (const doc of generate(schemaName, { count: COUNT })) { + assert(validate(schemaName, valueOf(doc)), 'doc is valid') // This should not throw. encode(doc) } @@ -19,6 +21,7 @@ test('generates encodable data', { concurrency: true }, async (t) => { await t.test('coreOwnership', () => { for (const doc of generate('coreOwnership', { count: COUNT })) { + assert(validate('coreOwnership', doc), 'doc is valid') // This should not throw. encode({ ...doc,