More consise type tests
This commit is contained in:
parent
6224243791
commit
75ba0580bc
|
@ -14,12 +14,11 @@ describe('model-helper', function() {
|
||||||
buf: Buffer // {type: 'string', format: 'byte'}
|
buf: Buffer // {type: 'string', format: 'byte'}
|
||||||
});
|
});
|
||||||
var props = def.properties;
|
var props = def.properties;
|
||||||
expect(props.str.type).to.equal('string');
|
expect(props.str).to.eql({ type: 'string' });
|
||||||
expect(props.num.type).to.equal('number');
|
expect(props.num).to.eql({ type: 'number', format: 'double' });
|
||||||
expect(props.num.format).to.equal('double');
|
expect(props.date).eql({ type: 'string', format: 'date' });
|
||||||
expect(props.date.type).to.equal('string');
|
expect(props.bool).to.eql({ type: 'boolean' });
|
||||||
expect(props.bool.type).to.equal('boolean');
|
expect(props.buf).to.eql({ type: 'string', format: 'byte' });
|
||||||
expect(props.buf.type).to.equal('string');
|
|
||||||
});
|
});
|
||||||
it('converts string types', function() {
|
it('converts string types', function() {
|
||||||
var def = getDefinition({
|
var def = getDefinition({
|
||||||
|
@ -30,12 +29,11 @@ describe('model-helper', function() {
|
||||||
buf: 'buffer' // {type: 'string', format: 'byte'}
|
buf: 'buffer' // {type: 'string', format: 'byte'}
|
||||||
});
|
});
|
||||||
var props = def.properties;
|
var props = def.properties;
|
||||||
expect(props.str.type).to.equal('string');
|
expect(props.str).to.eql({ type: 'string' });
|
||||||
expect(props.num.type).to.equal('number');
|
expect(props.num).to.eql({ type: 'number', format: 'double' });
|
||||||
expect(props.num.format).to.equal('double');
|
expect(props.date).eql({ type: 'string', format: 'date' });
|
||||||
expect(props.date.type).to.equal('string');
|
expect(props.bool).to.eql({ type: 'boolean' });
|
||||||
expect(props.bool.type).to.equal('boolean');
|
expect(props.buf).to.eql({ type: 'string', format: 'byte' });
|
||||||
expect(props.buf.type).to.equal('string');
|
|
||||||
});
|
});
|
||||||
describe('array definitions', function() {
|
describe('array definitions', function() {
|
||||||
// There are three types we want to checK:
|
// There are three types we want to checK:
|
||||||
|
@ -47,8 +45,9 @@ describe('model-helper', function() {
|
||||||
array: [String]
|
array: [String]
|
||||||
});
|
});
|
||||||
var props = def.properties;
|
var props = def.properties;
|
||||||
expect(props.array.type).to.equal('array');
|
expect(props.array).to.eql({ type: 'array', items: {
|
||||||
expect(props.array.items.type).to.equal('string');
|
type: 'string'
|
||||||
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts ["string"] type', function() {
|
it('converts ["string"] type', function() {
|
||||||
|
@ -56,8 +55,9 @@ describe('model-helper', function() {
|
||||||
array: ['string']
|
array: ['string']
|
||||||
});
|
});
|
||||||
var props = def.properties;
|
var props = def.properties;
|
||||||
expect(props.array.type).to.equal('array');
|
expect(props.array).to.eql({ type: 'array', items: {
|
||||||
expect(props.array.items.type).to.equal('string');
|
type: 'string'
|
||||||
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts [{type: "string", length: 64}] type', function() {
|
it('converts [{type: "string", length: 64}] type', function() {
|
||||||
|
@ -65,8 +65,10 @@ describe('model-helper', function() {
|
||||||
array: [{type: 'string', length: 64}]
|
array: [{type: 'string', length: 64}]
|
||||||
});
|
});
|
||||||
var props = def.properties;
|
var props = def.properties;
|
||||||
expect(props.array.type).to.equal('array');
|
expect(props.array).to.eql({ type: 'array', items: {
|
||||||
expect(props.array.items.type).to.equal('string');
|
type: 'string',
|
||||||
|
length: 64
|
||||||
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts [{type: "date"}] type (with `format`)', function() {
|
it('converts [{type: "date"}] type (with `format`)', function() {
|
||||||
|
@ -74,15 +76,15 @@ describe('model-helper', function() {
|
||||||
array: [{type: 'date'}]
|
array: [{type: 'date'}]
|
||||||
});
|
});
|
||||||
var props = def.properties;
|
var props = def.properties;
|
||||||
expect(props.array.type).to.equal('array');
|
expect(props.array).to.eql({ type: 'array', items: {
|
||||||
expect(props.array.items.type).to.equal('string');
|
type: 'string', format: 'date'
|
||||||
expect(props.array.items.format).to.equal('date');
|
}});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Simulates the format of a rmeoting class.
|
// Simulates the format of a remoting class.
|
||||||
function getDefinition(model) {
|
function getDefinition(model) {
|
||||||
Object.keys(model).forEach(function(name) {
|
Object.keys(model).forEach(function(name) {
|
||||||
model[name] = {type: model[name]};
|
model[name] = {type: model[name]};
|
||||||
|
|
Loading…
Reference in New Issue