Skip to content

Commit

Permalink
Composite Key Test
Browse files Browse the repository at this point in the history
Added test for composite key
  • Loading branch information
ataft committed Oct 6, 2021
1 parent b1bf144 commit 257bc77
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/id.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,61 @@ describe('Manipulating id column', function() {
});
});

it('should create composite key', function(done) {
const schema =
{
name: 'CompositeKeyTest',
options: {
idInjection: false,
mssql: {
schema: 'dbo',
table: 'COMPOSITE_KEY_TEST',
},
},
properties: {
idOne: {
type: 'Number',
id: true,
generated: false,
},
idTwo: {
type: 'Number',
id: true,
generated: false,
},
name: {
type: 'String',
required: false,
length: 40,
},
},
};

const models = ds.modelBuilder.buildModels(schema);
const Model = models.CompositeKeyTest;
Model.attachTo(ds);

ds.automigrate(function(err) {
assert(!err);
async.series([
function(callback) {
Model.destroyAll(callback);
},
function(callback) {
Model.create({idOne: 1, idTwo: 2, name: 'w1'},
callback);
},
function(callback) {
ds.discoverPrimaryKeys('COMPOSITE_KEY_TEST', function(err, models) {
if (err) return done(err);
assert(models.length === 2);
callback();
});
},
], done);
});
});

it('should use bigint id', function(done) {
const schema =
{
Expand Down

0 comments on commit 257bc77

Please sign in to comment.