octoblu-device-schema-transmogrifier
Version:
Transmogrifies message and device schemas from version NULL to v1.0.0 for meshblu devices
89 lines (74 loc) • 2.47 kB
text/coffeescript
{beforeEach, context, describe, it} = global
{expect} = require 'chai'
_ = require 'lodash'
OctobluDeviceSchemaTransmogrifier = require '../'
describe 'migrating message schemas', ->
context 'with an unknown version', ->
context 'a messageSchema with a single schema object', ->
beforeEach ->
=
messageSchema:
type: 'object'
properties:
sup:
type: 'string'
messageFormSchema: [{
key: 'sup'
}]
= new OctobluDeviceSchemaTransmogrifier
= .transmogrify()
it 'should create the correct message schema array', ->
expect(.schemas.message).to.deep.equal
default:
type: 'object'
'x-form-schema':
angular:
'message.default.angular'
properties:
sup:
type: 'string'
it 'should create the correct form message schema array', ->
expect(.schemas.form.message).to.deep.equal
default:
angular:
[{
key: 'sup'
}]
it 'should remove old message schema', ->
expect(.messageSchema).not.to.exist
context 'with no schema at all', ->
beforeEach ->
= {}
= new OctobluDeviceSchemaTransmogrifier
= .transmogrify()
it 'should set an empty schema', ->
expect(.schemas).to.deep.equal {
version: '1.0.0'
message: {}
configure: {}
form: {}
}
describe 'migrating a v1.0.0 schema', ->
beforeEach ->
=
schemas:
version: '1.0.0'
= new OctobluDeviceSchemaTransmogrifier _.cloneDeep()
= .transmogrify()
it 'should do nothing', ->
expect().to.deep.equal {
schemas:
version: '1.0.0'
}
describe 'migrating a v2.0.0 schema', ->
beforeEach ->
=
schemas:
version: '2.0.0'
= new OctobluDeviceSchemaTransmogrifier _.cloneDeep()
= .transmogrify()
it 'should do nothing', ->
expect().to.deep.equal {
schemas:
version: '2.0.0'
}