Merge pull request #1733 from strongloop/fix/postgresql

Fix tests for empty vs. default values to pass on SQL
This commit is contained in:
Miroslav Bajtoš 2019-05-03 09:04:08 +02:00 committed by GitHub
commit 78c4bfbc2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 22 deletions

View File

@ -985,25 +985,25 @@ describe('manipulation', function() {
it('preserves empty values from the database', async () => { it('preserves empty values from the database', async () => {
// https://github.com/strongloop/loopback-datasource-juggler/issues/1692 // https://github.com/strongloop/loopback-datasource-juggler/issues/1692
// Initially, all Products were always active, no property was needed // Initially, all Players were always active, no property was needed
const Product = db.define('Product', {name: String}); const Player = db.define('Player', {name: String});
await db.automigrate('Product'); await db.automigrate('Player');
const created = await Product.create({name: 'Pen'}); const created = await Player.create({name: 'Pen'});
// Later on, we decide to introduce `active` property // Later on, we decide to introduce `active` property
Product.defineProperty('active', { Player.defineProperty('active', {
type: Boolean, type: Boolean,
default: false, default: false,
}); });
await db.autoupdate('Player');
// And updateOrCreate an existing record // And updateOrCreate an existing record
const found = await Product.updateOrCreate({id: created.id, name: 'updated'}); const found = await Player.updateOrCreate({id: created.id, name: 'updated'});
found.toObject().should.eql({ should(found.toObject().active).be.oneOf([
id: created.id, undefined, // databases supporting `undefined` value
name: 'updated', null, // databases representing `undefined` as `null`
active: undefined, ]);
});
}); });
}); });
@ -1647,25 +1647,25 @@ describe('manipulation', function() {
it('preserves empty values from the database', async () => { it('preserves empty values from the database', async () => {
// https://github.com/strongloop/loopback-datasource-juggler/issues/1692 // https://github.com/strongloop/loopback-datasource-juggler/issues/1692
// Initially, all Products were always active, no property was needed // Initially, all Players were always active, no property was needed
const Product = db.define('Product', {name: String}); const Player = db.define('Player', {name: String});
await db.automigrate('Product'); await db.automigrate('Player');
const created = await Product.create({name: 'Pen'}); const created = await Player.create({name: 'Pen'});
// Later on, we decide to introduce `active` property // Later on, we decide to introduce `active` property
Product.defineProperty('active', { Player.defineProperty('active', {
type: Boolean, type: Boolean,
default: false, default: false,
}); });
await db.autoupdate('Player');
// And findOrCreate an existing record // And findOrCreate an existing record
const [found] = await Product.findOrCreate({id: created.id}, {name: 'updated'}); const [found] = await Player.findOrCreate({id: created.id}, {name: 'updated'});
found.toObject().should.eql({ should(found.toObject().active).be.oneOf([
id: created.id, undefined, // databases supporting `undefined` value
name: 'Pen', null, // databases representing `undefined` as `null`
active: undefined, ]);
});
}); });
}); });