Skip to content

Commit

Permalink
fixup! try to fix the test on SQL dbs
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Nov 15, 2019
1 parent 8a58239 commit 67019c4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions test/manipulation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2664,18 +2664,31 @@ describe('manipulation', function() {
});

it('preserves custom type of auto-generated id property', async () => {
const userId = 'custom user id';
// NOTE: This test is trying to reproduce the behavior observed
// when using property defined as follows:
// {type: 'string', generated: true, mongodb: {dataType: 'ObjectID'}}
// We want to test that behavior for all connectors, which is tricky,
// because not all connectors support autogenerated string PK values.

const User = db.define('User', {
const User = db.define('UserWithStringId', {
id: {
type: String,
id: true,
generated: true,
useDefaultIdType: false,
// `useDefaultIdType` is applied only when `generated: true`
generated: true,
},
name: String,
}, {forceId: false});

// disable `generated: true` because many SQL databases cannot
// auto-generate string ids
User.definition.properties.id.generated = false;
User.definition.rawProperties.id.generated = false;
await db.automigrate(User.modelName);

const userId = 'custom user id';

const createdUser = await User.create({id: userId, name: 'testUser'});
// strict equality check
createdUser.id.should.equal(userId);
Expand Down

0 comments on commit 67019c4

Please sign in to comment.