diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts deleted file mode 100644 index 132a311d5..000000000 --- a/src/sscce-sequelize-6.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { DataTypes, Model } from 'sequelize'; -import { createSequelize6Instance } from '../dev/create-sequelize-instance'; -import { expect } from 'chai'; -import sinon from 'sinon'; - -// if your issue is dialect specific, remove the dialects you don't need to test on. -export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); - -// You can delete this file if you don't want your SSCCE to be tested against Sequelize 6 - -// Your SSCCE goes inside this function. -export async function run() { - // This function should be used instead of `new Sequelize()`. - // It applies the config for your SSCCE to work on CI. - const sequelize = createSequelize6Instance({ - logQueryParameters: true, - benchmark: true, - define: { - // For less clutter in the SSCCE - timestamps: false, - }, - }); - - class Foo extends Model {} - - Foo.init({ - name: DataTypes.TEXT, - }, { - sequelize, - modelName: 'Foo', - }); - - // You can use sinon and chai assertions directly in your SSCCE. - const spy = sinon.spy(); - sequelize.afterBulkSync(() => spy()); - await sequelize.sync({ force: true }); - expect(spy).to.have.been.called; - - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); -} diff --git a/src/sscce-sequelize-7.ts b/src/sscce-sequelize-7.ts index 603cb219c..ec97caf05 100644 --- a/src/sscce-sequelize-7.ts +++ b/src/sscce-sequelize-7.ts @@ -1,5 +1,5 @@ import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from '@sequelize/core'; -import { Attribute, NotNull } from '@sequelize/core/decorators-legacy'; +import { Attribute, PrimaryKey } from '@sequelize/core/decorators-legacy'; import { createSequelize7Instance } from '../dev/create-sequelize-instance'; import { expect } from 'chai'; import sinon from 'sinon'; @@ -23,21 +23,34 @@ export async function run() { }); class Foo extends Model, InferCreationAttributes> { - declare id: CreationOptional; - @Attribute(DataTypes.TEXT) - @NotNull + @PrimaryKey declare name: string; + + @Attribute(DataTypes.TEXT) + @PrimaryKey + declare rank: string; + + @Attribute(DataTypes.TEXT) + declare role: CreationOptional; } sequelize.addModels([Foo]); - - // You can use sinon and chai assertions directly in your SSCCE. - const spy = sinon.spy(); - sequelize.afterBulkSync(() => spy()); await sequelize.sync({ force: true }); - expect(spy).to.have.been.called; - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); + // Inserting two entries with different name and rank succeeds + await expect(Foo.create({ name: "fish", rank: "novice" })).to.eventually.be.fulfilled; + await expect(Foo.create({ name: "fish", rank: "expert" })).to.eventually.be.fulfilled; + + // Inserting two entries with same name and rank fails + await expect(Foo.create({ name: "cat", rank: "expert" })).to.eventually.be.fulfilled; + await expect(Foo.create({ name: "cat", rank: "expert" })).to.eventually.be.rejected; + + // Altering an unrelated column should not change the above behaviour + await Foo.truncate(); + await sequelize.queryInterface.changeColumn("Foos", "role", { type: DataTypes.INTEGER }); + await expect(Foo.create({ name: "bear", rank: "novice" })).to.eventually.be.fulfilled; + await expect(Foo.create({ name: "bear", rank: "expert" })).to.eventually.be.fulfilled; + await expect(Foo.create({ name: "dog", rank: "expert" })).to.eventually.be.fulfilled; + await expect(Foo.create({ name: "dog", rank: "expert" })).to.eventually.be.rejected; }