Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tests for empty vs. default values #1707

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions test/basic-querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]);
});
});

Expand Down
22 changes: 11 additions & 11 deletions test/manipulation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we want to preserve the checks for id and name as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those properties are not really affected by default values, I feel it's ok to not check them - we have other tests in place to verify.

undefined, // databases supporting `undefined` value
null, // databases representing `undefined` as `null` (e.g. SQL)
]);
});
});
});
Expand Down