Skip to content

Commit

Permalink
test: assert that generated data is valid (#32)
Browse files Browse the repository at this point in the history
This beefs up our tests for `generate` by making sure that they pass
`@comapeo/schema`'s `validate` function.
  • Loading branch information
EvanHahn authored Dec 12, 2024
1 parent 1822e61 commit 52bab50
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/generate.test.js
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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)
}
Expand All @@ -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,
Expand Down

0 comments on commit 52bab50

Please sign in to comment.