@fye/xservices-client
Version:
FYE Micros Xservices Client
99 lines (82 loc) • 2.58 kB
JavaScript
var expect = require('expect.js');
var XService = require('../lib/xservice');
describe('XService', function() {
var x = new XService();
describe('._convertBool', function() {
it('should convert strings to booleans', function() {
expect(x._convertBool('true')).to.be.ok();
expect(x._convertBool('false')).to.not.be.ok();
expect(x._convertBool('balls')).to.not.be.ok();
});
});
describe('._convertFields', function() {
var obj = require('./fixtures/convert_fields');
var a = x._convertFields({
obj: obj,
bools: [ 'bar', 'boop'],
floats: [ 'blop', 'baz' ],
ints: [ 'foo' ],
numbers: [ 'blip' ],
dates: [ 'bat' ]
});
it('should convert booleans', function() {
var bools = x._convertFields({
obj: obj,
bools: [ 'bar', 'boop']
});
expect(a.bar).to.be.a('boolean');
expect(a.boop).to.be.a('boolean');
expect(a.bar).to.be.ok();
expect(a.boop).to.not.be.ok();
expect(bools.bar).to.be.a('boolean');
expect(bools.boop).to.be.a('boolean');
expect(bools.bar).to.be.ok();
expect(bools.boop).to.not.be.ok();
});
it('should convert floats', function() {
var floats = x._convertFields({
obj: obj,
floats: [ 'blop', 'baz' ]
});
expect(a.blop).to.be.a('number');
expect(a.baz).to.be.a('number');
expect(a.blop).to.be(133.7);
expect(a.baz).to.be(2.00);
expect(floats.blop).to.be.a('number');
expect(floats.baz).to.be.a('number');
expect(floats.blop).to.be(133.7);
expect(floats.baz).to.be(2.00);
});
it('should convert integers', function() {
var ints = x._convertFields({
obj: obj,
ints: [ 'foo' ]
});
expect(a.foo).to.be.a('number');
expect(a.foo).to.be(1);
expect(ints.foo).to.be.a('number');
expect(ints.foo).to.be(1);
});
it('should convert numbers', function() {
var nums = x._convertFields({
obj: obj,
numbers: [ 'blip' ]
});
expect(a.blip).to.be.a('number');
expect(a.blip).to.be(-1);
expect(nums.blip).to.be.a('number');
expect(nums.blip).to.be(-1);
});
it('should convert dates', function() {
var dates = x._convertFields({
obj: obj,
dates: [ 'bat' ]
});
var date = new Date('2014-09-10T00:00:00-04:00');
expect(a.bat).to.be.a(Date);
expect(a.bat).to.eql(date);
expect(dates.bat).to.be.a(Date);
expect(dates.bat).to.eql(date);
});
});
});