Improve tests for empty vs. default values
This commit is contained in:
parent
84eee5a69e
commit
7d69bdab70
|
@ -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)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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)
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue