Skip to content

Commit

Permalink
Reproduce bug - loopbackio#34
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoftek committed Feb 26, 2017
1 parent e8fb022 commit 6ec9586
Show file tree
Hide file tree
Showing 3 changed files with 1,743 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var DataSource = require('loopback-datasource-juggler').DataSource;
var path = require('path');
var os = require('os');

console.log('tmpdir',os.tmpdir())
var config = require('rc')('loopback', {
test: {
sqlite: {
Expand Down
79 changes: 79 additions & 0 deletions test/sqlite.handleUndefinedObject.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright IBM Corp. 2015. All Rights Reserved.
// Node module: loopback-connector-sqlite3
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0

var should = require('should');
require('./init');

var Post, db;

/*global describe, before, it, getDataSource*/
describe('handle undefined object', function() {
before(function() {
db = getDataSource();

Post = db.define('HandleUndefinedObject', {
field1: {
type: 'number'
},
field2: {
type: 'object'
}
});
});

it('should run migration', function(done) {
db.automigrate('HandleUndefinedObject', function() {
done();
});
});

it('should handle object field in fields list', function(done) {
var tstPost = new Post();
tstPost.field1 = 1;
tstPost.field2 = {val: 2};
tstPost.save(function(err, p) {
should.not.exist(err);
Post.findOne({where: {id: p.id}}, function(err, p) {
should.not.exist(err);
p.field1.should.equal(1);
p.field2.should.deepEqual({val: 2});
done();
});
});
});

it('should handle object field not in fields list', function(done) {
var tstPost = new Post();
tstPost.field1 = 1;
tstPost.field2 = {val: 2};
tstPost.save(function(err, p) {
should.not.exist(err);
Post.findOne({where: {id: p.id}, fields: ['field1']}, function(err, p) {
should.not.exist(err);
p.field1.should.be.equal(1);
should.not.exist(p.field2);
done();
});
});
});

// it('should insert default value and \'third\' field', function(done) {
// var tstPost = new Post();
// tstPost.third = 3;
// tstPost.save(function(err, p) {
// should.not.exist(err);
// Post.findOne({where: {id: p.id}}, function(err, p) {
// should.not.exist(err);
// p.defaultInt.should.be.equal(5);
// should.not.exist(p.first);
// should.not.exist(p.second);
// should.exist(p.third);
// p.third.should.be.equal(3);
// });
// done();
// });
// });

});
Loading

0 comments on commit 6ec9586

Please sign in to comment.