From 7d69bdab70936e408cc03f5a838c6f76d402f084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 9 Apr 2019 15:54:52 +0200 Subject: [PATCH] Improve tests for empty vs. default values --- test/basic-querying.test.js | 22 +++++++++++----------- test/manipulation.test.js | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test/basic-querying.test.js b/test/basic-querying.test.js index 90fd7735f..3e79be45c 100644 --- a/test/basic-querying.test.js +++ b/test/basic-querying.test.js @@ -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) + ]); }); }); diff --git a/test/manipulation.test.js b/test/manipulation.test.js index 679e5be80..f5808eaac 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -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) + ]); }); }); });