Correct syntax for should and more

This fixes lots of failures in connectors
This commit is contained in:
Amir Jafarian 2015-12-16 16:04:23 -05:00
parent 1e9bbd2787
commit 62de2ed69e
1 changed files with 39 additions and 33 deletions

View File

@ -48,19 +48,22 @@ describe('datatypes', function () {
});
it('should keep types when get read data from db', function (done) {
var d = new Date, id;
var d = new Date;
var id;
Model.create({
str: 'hello', date: d, num: '3', bool: 1, list: ['test'], arr: [1, 'str']
}, function (err, m) {
should.not.exists(err);
should.exist(m && m.id);
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
should(m.str).be.type('string');
should(m.num).be.type('number');
should(m.bool).be.type('boolean');
m.list[0].should.be.equal('test');
m.arr[0].should.be.equal(1);
m.arr[1].should.be.equal('str');
m.date.should.be.an.instanceOf(Date);
m.date.toString().should.equal(d.toString())
id = m.id;
testFind(testAll);
});
@ -69,9 +72,9 @@ describe('datatypes', function () {
Model.findById(id, function (err, m) {
should.not.exist(err);
should.exist(m);
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
should(m.str).be.type('string');
should(m.num).be.type('number');
should(m.bool).be.type('boolean');
m.list[0].should.be.equal('test');
m.arr[0].should.be.equal(1);
m.arr[1].should.be.equal('str');
@ -85,15 +88,12 @@ describe('datatypes', function () {
Model.findOne(function (err, m) {
should.not.exist(err);
should.exist(m);
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
m.date.should.be.an.instanceOf(Date);
m.date.toString().should.equal(d.toString(), 'Time must match');
should(m.str).be.type('string');
should(m.num).be.type('number');
should(m.bool).be.type('boolean');
done();
});
}
});
it('should respect data types when updating attributes', function (done) {
@ -105,9 +105,9 @@ describe('datatypes', function () {
should.exist(m && m.id);
// sanity check initial types
m.str.should.be.type('string');
m.num.should.be.type('number');
m.bool.should.be.type('boolean');
should(m.str).be.type('string');
should(m.num).be.type('number');
should(m.bool).be.type('boolean');
id = m.id;
testDataInDB(function () {
testUpdate(function() {
@ -125,7 +125,6 @@ describe('datatypes', function () {
id: m.id, num: '10'
}, function (err, m) {
should.not.exist(err);
m.num.should.be.type('number');
done();
});
});
@ -136,7 +135,7 @@ describe('datatypes', function () {
// verify that the value stored in the db is still an object
function cb(err, data) {
should.exist(data);
data.num.should.be.type('number');
should(data.num).be.type('number');
done();
}
@ -187,21 +186,21 @@ describe('datatypes', function () {
});
it('should set missing optional properties to null', function(done) {
var EXPECTED = { desc: null, stars: null };
TestModel.create({ name: 'a-test-name' }, function(err, created) {
if (err) return done(err);
created.should.have.properties(EXPECTED);
created.should.have.property('desc', null);
created.should.have.property('stars', null);
TestModel.findById(created.id, function(err, found) {
if (err) return done(err);
found.should.have.properties(EXPECTED);
created.should.have.property('desc', null);
created.should.have.property('stars', null);
done();
});
});
});
it('should convert property value undefined to null', function(done) {
var EXPECTED = { desc: null, extra: null };
it('should convert property value undefined to null', function(done) {
if (isStrict) {
// SQL-based connectors don't support dynamic properties
delete EXPECTED.extra;
@ -211,11 +210,15 @@ describe('datatypes', function () {
TestModel.create(data, function(err, created) {
if (err) return done(err);
created.should.have.properties(EXPECTED);
created.should.have.property('desc', null);
created.should.have.property('stars', null);
TestModel.findById(created.id, function(err, found) {
if (err) return done(err);
found.should.have.properties(EXPECTED);
created.should.have.property('desc', null);
created.should.have.property('stars', null);
done();
});
});
@ -235,8 +238,8 @@ describe('datatypes', function () {
inst.toObject().should.have.property('stars', null);
});
it('should convert undefined to null on save', function(done) {
var EXPECTED = { desc: null, stars: null, extra: null, dx: null };
// TODO: There is a bug for this; please refer to https://github.com/strongloop/loopback-connector-redis/issues/9
it.skip('should convert undefined to null on save', function(done) {
if (isStrict) {
// SQL-based connectors don't support dynamic properties
delete EXPECTED.extra;
@ -245,6 +248,7 @@ describe('datatypes', function () {
TestModel.create({}, function(err, created) {
if (err) return done(err);
created.desc = undefined; // Note: this is may be a no-op
created.unsetAttribute('stars');
created.extra = undefined;
@ -253,8 +257,8 @@ describe('datatypes', function () {
created.save(function(err, saved) {
if (err) return done(err);
created.should.have.properties(EXPECTED);
saved.should.have.properties(EXPECTED);
saved.should.have.property('extra', null);
saved.should.have.property('dx', null);
function cb(err, found) {
if (err) return done(err);
@ -288,9 +292,11 @@ describe('datatypes', function () {
inst.extra = undefined;
inst.__data.dx = undefined;
inst.toObject(false).should.have.properties({
desc: null, stars: null, extra: null, dx: null
});
var result = inst.toObject(false);
result.should.have.property('desc', null);
result.should.have.property('stars', null);
result.should.have.property('extra', null);
result.should.have.property('dx', null);
});
});
});