Skip to content

Commit

Permalink
Add test case for bulk upsert automatic key error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Scheurer committed May 29, 2024
1 parent c8b54c3 commit 40c0399
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/sscce-sequelize-6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ export async function run() {
const sequelize = createSequelize6Instance({
logQueryParameters: true,
benchmark: true,
define: {
// For less clutter in the SSCCE
timestamps: false,
},
});

class Foo extends Model {}

Foo.init({
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
name: DataTypes.TEXT,
}, {
sequelize,
Expand All @@ -36,6 +37,16 @@ export async function run() {
await sequelize.sync({ force: true });
expect(spy).to.have.been.called;

console.log(await Foo.create({ name: 'TS foo' }));
const foo = await Foo.create({
id: 'e8388762-1daa-11ef-b9f0-b7d47c40e7e3',
name: 'hello'
});
expect(await Foo.count()).to.equal(1);
expect(async ()=>{
await Foo.bulkCreate(
[{ id: 'e8388762-1daa-11ef-b9f0-b7d47c40e7e3' }],
{ updateOnDuplicate: ['createdAt'] }
);
}).to.not.throw();
expect(await Foo.count()).to.equal(1);
}

0 comments on commit 40c0399

Please sign in to comment.