From 257bc7760cd965a3d04bf051f08d5d2d94492df1 Mon Sep 17 00:00:00 2001 From: ataft <11670864+ataft@users.noreply.github.com> Date: Wed, 6 Oct 2021 10:11:31 -0700 Subject: [PATCH] Composite Key Test Added test for composite key --- test/id.test.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/id.test.js b/test/id.test.js index b330edf..af0dc40 100644 --- a/test/id.test.js +++ b/test/id.test.js @@ -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 = {