Skip to content

Commit

Permalink
test cases for package manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Feb 7, 2024
1 parent a41c893 commit a017798
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/manifest/src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"nodes",
"schema"
],
"title": "XYO Manifest"
"title": "XYO Manifest",
"type": "object"
}
1 change: 1 addition & 0 deletions packages/manifest/src/spec/cases/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './dappManifest'
export * from './manifest'
2 changes: 2 additions & 0 deletions packages/manifest/src/spec/cases/manifest/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './invalidCase'
export * from './validCase'
23 changes: 23 additions & 0 deletions packages/manifest/src/spec/cases/manifest/invalidCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const invalidPackageManifestSchema = {
nodes: [
{
config3: {
accountPath: "0'",
name: 1,
schema: 'network.xyo.node.config',
},
modules: {
public2: [
{
config: {
accountPath: "1'",
name: 'SomeArchivist',
schema: 'network.xyo.archivist.config',
},
},
],
},
},
],
schema: 'network.xyo.foo.manifest',
}
23 changes: 23 additions & 0 deletions packages/manifest/src/spec/cases/manifest/validCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const validPackageManifestSchema = {
nodes: [
{
config: {
accountPath: "0'",
name: 'DappNode',
schema: 'network.xyo.node.config',
},
modules: {
public: [
{
config: {
accountPath: "1'",
name: 'SomeArchivist',
schema: 'network.xyo.archivist.config',
},
},
],
},
},
],
schema: 'network.xyo.manifest',
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import Ajv, { ValidateFunction } from 'ajv'

import dappPackageManifestSchema from '../dapp-package-manifest-schema.json'
import packageManifestSchema from '../schema.json'
// eslint-disable-next-line import/no-internal-modules
import sharedDefinitions from '../shared/definitions-schema.json'
import { invalidDappPackageManifestSchema, validDappPackageManifestSchema } from './cases/dappManifest'
import { invalidDappPackageManifestSchema, invalidPackageManifestSchema, validDappPackageManifestSchema, validPackageManifestSchema } from './cases'

const cases = [
{
describeName: 'PackageManifestSchema',
expectedErrorCount: 3,
invalidCase: invalidPackageManifestSchema,
schemaToTest: packageManifestSchema,
validCase: validPackageManifestSchema,
},
{
describeName: 'DappPackageManifestSchema',
expectedErrorCount: 4,
invalidCase: invalidDappPackageManifestSchema,
schemaToTest: dappPackageManifestSchema,
validCase: validDappPackageManifestSchema,
},
]

describe.each(cases)('ManifestSchemas', ({ describeName, validCase, invalidCase, schemaToTest }) => {
describe.each(cases)('ManifestSchemas', ({ describeName, expectedErrorCount, validCase, invalidCase, schemaToTest }) => {
describe(describeName, () => {
let validate: ValidateFunction | undefined

Expand All @@ -36,8 +45,9 @@ describe.each(cases)('ManifestSchemas', ({ describeName, validCase, invalidCase,
it('invalid schema', () => {
if (validate) {
const valid = validate(invalidCase)
console.log(describeName, validate?.errors)
expect(valid).toBe(false)
expect(validate.errors?.length).toBe(4)
expect(validate.errors?.length).toBe(expectedErrorCount)
} else {
throw new Error('Schema did not compile successfully')
}
Expand Down

0 comments on commit a017798

Please sign in to comment.