forked from sequelize/sequelize-sscce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sscce.ts
40 lines (33 loc) · 1.12 KB
/
sscce.ts
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
// Require the necessary things from Sequelize
import { Sequelize, Op, Model, DataTypes } from 'sequelize';
// This function should be used instead of `new Sequelize()`.
// It applies the config for your SSCCE to work on CI.
import createSequelizeInstance = require('./utils/create-sequelize-instance');
// This is an utility logger that should be preferred over `console.log()`.
import log = require('./utils/log');
// You can use sinon and chai assertions directly in your SSCCE if you want.
import sinon = require('sinon');
import { expect } from 'chai';
// Your SSCCE goes inside this function.
export async function run() {
const sequelize = createSequelizeInstance({
logQueryParameters: true,
benchmark: true,
define: {
timestamps: false // For less clutter in the SSCCE
}
});
class Foo extends Model {};
Foo.init({
name: DataTypes.TEXT
}, {
sequelize,
modelName: 'Foo'
});
const spy = sinon.spy();
sequelize.afterBulkSync(() => spy());
await sequelize.sync();
expect(spy).to.have.been.called;
log(await Foo.create({ name: 'TS foo' }));
expect(await Foo.count()).to.equal(1);
}