This repository has been archived by the owner on Jul 20, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30d6069
commit b462031
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import "jasmine" | ||
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`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as jsonschema from "jsonschema" | ||
import * as localizedString from "./localized-string" | ||
import * as columnSet from "./column-set" | ||
import * as label from "./label" | ||
|
||
export const schema: jsonschema.Schema = { | ||
description: `An entity type.`, | ||
type: `object`, | ||
additionalProperties: false, | ||
required: [ | ||
`singular`, | ||
`plural`, | ||
`label`, | ||
`columns` | ||
], | ||
properties: { | ||
singular: localizedString.schema, | ||
plural: localizedString.schema, | ||
label: label.schema, | ||
columns: columnSet.schema | ||
} | ||
} | ||
|
||
/** | ||
* An entity type. | ||
*/ | ||
export type Type = { | ||
/** | ||
* Maps localization identifiers to the name of the entity type, in singular | ||
* form, in those localizations. | ||
*/ | ||
readonly singular: localizedString.Type | ||
|
||
/** | ||
* Maps localization identifiers to the name of the entity type, in plural | ||
* form, in those localizations. | ||
*/ | ||
readonly plural: localizedString.Type | ||
|
||
/** | ||
* A list of chains of column identifiers which can be followed to find | ||
* values which are concatenated to build a label. | ||
*/ | ||
readonly label: label.Type | ||
|
||
/** | ||
* Maps column identifiers to schemas. | ||
*/ | ||
readonly columns: columnSet.Type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters