Vulcan/packages/vulcan-forms/test/schema_utils.test.js

51 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-09-12 11:59:00 +09:00
import { getNestedSchema } from '../lib/modules/schema_utils.js'
import SimpleSchema from 'simpl-schema'
2018-07-24 16:07:42 +02:00
import expect from 'expect'
const addressSchema = {
street: {
type: String,
},
country: {
type: String,
},
}
const addressSimpleSchema = new SimpleSchema(addressSchema)
2018-07-24 16:07:42 +02:00
describe('schema_utils', function () {
describe('getNestedSchema', function () {
it('get nested schema of an array', function () {
const simpleSchema = new SimpleSchema({
addresses: {
type: Array
},
2018-09-12 11:59:00 +09:00
'addresses.$': {
// this is due to SimpleSchema objects structure
type: addressSimpleSchema
}
})
const nestedSchema = getNestedSchema('addresses', simpleSchema)
// nestedSchema is a complex SimpleSchema object, so we can only
// test its type instead (might not be the simplest way though)
expect(Object.keys(nestedSchema._schema)).toEqual(Object.keys(addressSchema))
})
it('get nested schema of an object', function () {
const simpleSchema = new SimpleSchema({
meetingPlace: {
type: addressSimpleSchema
}
})
const nestedSchema = getNestedSchema('meetingPlace', simpleSchema)
expect(Object.keys(nestedSchema._schema)).toEqual(Object.keys(addressSchema))
})
it('return null for other types', function () {
const simpleSchema = new SimpleSchema({
createdAt: {
type: Date
}
})
const nestedSchema = getNestedSchema('createdAt', simpleSchema)
expect(nestedSchema).toBeNull()
2018-07-24 16:07:42 +02:00
})
})
})