-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathsscce-sequelize-7.ts
More file actions
56 lines (46 loc) · 2.37 KB
/
sscce-sequelize-7.ts
File metadata and controls
56 lines (46 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { CreationOptional, DataTypes, DialectName, InferAttributes, InferCreationAttributes, Model } from '@sequelize/core';
import { Attribute, PrimaryKey } from '@sequelize/core/decorators-legacy';
import { createSequelize7Instance } 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 7
// 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 = createSequelize7Instance({
logQueryParameters: true,
benchmark: true,
define: {
// For less clutter in the SSCCE
timestamps: false,
},
});
class Foo extends Model<InferAttributes<Foo>, InferCreationAttributes<Foo>> {
@Attribute(DataTypes.STRING(100))
@PrimaryKey
declare name: string;
@Attribute(DataTypes.STRING(100))
@PrimaryKey
declare rank: string;
@Attribute(DataTypes.STRING(100))
declare role: CreationOptional<string>;
}
sequelize.addModels([Foo]);
await sequelize.sync({ force: true });
// 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.TEXT });
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;
}