Improve tests for empty vs. default values

This commit is contained in:
Miroslav Bajtoš 2019-04-09 15:54:52 +02:00
parent 84eee5a69e
commit 7d69bdab70
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
2 changed files with 22 additions and 22 deletions

View File

@ -926,25 +926,25 @@ describe('basic-querying', 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 query existing data
const found = await Product.findOne();
found.toObject().should.eql({
id: created.id,
name: 'Pen',
active: undefined,
});
const found = await Player.findOne();
should(found.toObject().active).be.oneOf([
undefined, // databases supporting `undefined` value
null, // databases representing `undefined` as `null` (e.g. SQL)
]);
});
});

View File

@ -2615,25 +2615,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 upsertWithWhere an existing record
const found = await Product.upsertWithWhere({id: created.id}, {name: 'updated'});
found.toObject().should.eql({
id: created.id,
name: 'updated',
active: undefined,
});
const found = await Player.upsertWithWhere({id: created.id}, {name: 'updated'});
should(found.toObject().active).be.oneOf([
undefined, // databases supporting `undefined` value
null, // databases representing `undefined` as `null` (e.g. SQL)
]);
});
});
});