Skip to content

Commit

Permalink
test: test that all generated values can be encoded
Browse files Browse the repository at this point in the history
After running this test I also noticed an issue with icons, where
(inexplicably) the `blobVersionId` would sometimes be a regular string,
not a version ID. I was able to fix this by changing the definition.

I think this is a useful change on its own, but it will make future
changes (such as upgrading some dependencies) much easier.
  • Loading branch information
EvanHahn committed Dec 2, 2024
1 parent 36a0727 commit 5b9d5d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/faker.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ function createFakerSchema(schema) {
return s
}
case 'Icon': {
s.properties.variants.items.oneOf.forEach((variant) =>
mutateWithFakerProperty(
variant.properties.blobVersionId,
'mapeo.versionId',
),
)
mutateWithFakerProperty(s.definitions.blobVersionId, 'mapeo.versionId')
return s
}
case 'Track': {
Expand Down
29 changes: 29 additions & 0 deletions test/generate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { encode } from '@comapeo/schema'
import test from 'node:test'
import { generate, listSchemas } from '../index.js'

test('generates encodable data', { concurrency: true }, async (t) => {
const COUNT = 1000

const schemaNames = Object.keys(listSchemas())

for (const schemaName of schemaNames) {
if (schemaName === 'coreOwnership') continue
await t.test(schemaName, () => {
for (const doc of generate(schemaName, { count: COUNT })) {
// This should not throw.
encode(doc)
}
})
}

await t.test('coreOwnership', () => {
for (const doc of generate('coreOwnership', { count: COUNT })) {
// This should not throw.
encode({
...doc,
identitySignature: Buffer.alloc(32),
})
}
})
})

0 comments on commit 5b9d5d7

Please sign in to comment.