Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Refactored testing of entity types (#6).
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed May 28, 2019
1 parent b462031 commit 705f322
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 62 deletions.
63 changes: 1 addition & 62 deletions src/entity-type.tests.ts
Expand Up @@ -3,66 +3,5 @@ import * as entityType from "./entity-type"
import * as shared from "./shared.tests"

describe(`entity type`, () => {
shared.run(shared.nonObjects, value => shared.rejects(
entityType.schema, value, `instance`, `is not of a type(s) object`
))
describe(`unexpected properties`, () => shared.rejects(entityType.schema, {
singular: {},
plural: {},
label: [],
columns: {},
unexpected: {}
}, `instance`, `additionalProperty "unexpected" exists in instance when not allowed`))
describe(`singular`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
plural: {},
label: [],
columns: {}
}, `instance`, `requires property "singular"`))
shared.testLocalizedString(entityType.schema, instance => ({
singular: instance,
plural: {},
label: [],
columns: {},
}), `instance.singular`)
})
describe(`plural`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
singular: {},
label: [],
columns: {}
}, `instance`, `requires property "plural"`))
shared.testLocalizedString(entityType.schema, instance => ({
singular: {},
plural: instance,
label: [],
columns: {},
}), `instance.plural`)
})
describe(`label`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
singular: {},
plural: {},
columns: {}
}, `instance`, `requires property "label"`))
shared.testLabel(entityType.schema, instance => ({
singular: {},
plural: {},
label: instance,
columns: {},
}), `instance.label`)
})
describe(`columns`, () => {
describe(`missing`, () => shared.rejects(entityType.schema, {
singular: {},
plural: {},
label: []
}, `instance`, `requires property "columns"`))
shared.testColumnSet(entityType.schema, instance => ({
singular: {},
plural: {},
label: [],
columns: instance,
}), `instance.columns`)
})
shared.testEntityType(entityType.schema, value => value, `instance`)
})
72 changes: 72 additions & 0 deletions src/shared.tests.ts
Expand Up @@ -820,3 +820,75 @@ export function testLabel(
[`long_w`, `2thetp`, `wanna_`, `depest`, `lore__`]
])))
}

export function testEntityType(
schema: jsonschema.Schema,
instanceFactory: InstanceFactory,
property: string
): void {
run(nonObjects, value => rejects(
schema, instanceFactory(value), property, `is not of a type(s) object`
))
describe(`unexpected properties`, () => rejects(
schema,
instanceFactory({
singular: {},
plural: {},
label: [],
columns: {},
unexpected: {}
}), property, `additionalProperty "unexpected" exists in instance when not allowed`
))
describe(`singular`, () => {
describe(`missing`, () => rejects(schema, instanceFactory({
plural: {},
label: [],
columns: {}
}), property, `requires property "singular"`))
testLocalizedString(schema, value => instanceFactory({
singular: value,
plural: {},
label: [],
columns: {},
}), `${property}.singular`)
})
describe(`plural`, () => {
describe(`missing`, () => rejects(schema, instanceFactory({
singular: {},
label: [],
columns: {}
}), property, `requires property "plural"`))
testLocalizedString(schema, value => instanceFactory({
singular: {},
plural: value,
label: [],
columns: {},
}), `${property}.plural`)
})
describe(`label`, () => {
describe(`missing`, () => rejects(schema, instanceFactory({
singular: {},
plural: {},
columns: {}
}), property, `requires property "label"`))
testLabel(schema, value => instanceFactory({
singular: {},
plural: {},
label: value,
columns: {},
}), `${property}.label`)
})
describe(`columns`, () => {
describe(`missing`, () => rejects(schema, instanceFactory({
singular: {},
plural: {},
label: []
}), property, `requires property "columns"`))
testColumnSet(schema, value => instanceFactory({
singular: {},
plural: {},
label: [],
columns: value,
}), `${property}.columns`)
})
}

0 comments on commit 705f322

Please sign in to comment.