Fix tests for empty/default values to pass on SQL

This commit is contained in:
Miroslav Bajtoš 2019-05-03 08:51:06 +02:00
parent 08e8725ba5
commit b0e3de1083
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
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 () => {
// https://github.com/strongloop/loopback-datasource-juggler/issues/1692
// Initially, all Products were always active, no property was needed
const Product = db.define('Product', {name: String});
// Initially, all Players were always active, no property was needed
const Player = db.define('Player', {name: String});
await db.automigrate('Product');
const created = await Product.create({name: 'Pen'});
await db.automigrate('Player');
const created = await Player.create({name: 'Pen'});
// Later on, we decide to introduce `active` property
Product.defineProperty('active', {
Player.defineProperty('active', {
type: Boolean,
default: false,
});
await db.autoupdate('Player');
// And updateOrCreate an existing record
const found = await Product.updateOrCreate({id: created.id, name: 'updated'});
found.toObject().should.eql({
id: created.id,
name: 'updated',
active: undefined,
});
const found = await Player.updateOrCreate({id: created.id, name: 'updated'});
should(found.toObject().active).be.oneOf([
undefined, // databases supporting `undefined` value
null, // databases representing `undefined` as `null`
]);
});
});
@ -1647,25 +1647,25 @@ describe('manipulation', function() {
it('preserves empty values from the database', async () => {
// https://github.com/strongloop/loopback-datasource-juggler/issues/1692
// Initially, all Products were always active, no property was needed
const Product = db.define('Product', {name: String});
// Initially, all Players were always active, no property was needed
const Player = db.define('Player', {name: String});
await db.automigrate('Product');
const created = await Product.create({name: 'Pen'});
await db.automigrate('Player');
const created = await Player.create({name: 'Pen'});
// Later on, we decide to introduce `active` property
Product.defineProperty('active', {
Player.defineProperty('active', {
type: Boolean,
default: false,
});
await db.autoupdate('Player');
// And findOrCreate an existing record
const [found] = await Product.findOrCreate({id: created.id}, {name: 'updated'});
found.toObject().should.eql({
id: created.id,
name: 'Pen',
active: undefined,
});
const [found] = await Player.findOrCreate({id: created.id}, {name: 'updated'});
should(found.toObject().active).be.oneOf([
undefined, // databases supporting `undefined` value
null, // databases representing `undefined` as `null`
]);
});
});