Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init: setup basic SSCCE for issue based on updating a field with virtual relations #266

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/sscce-sequelize-6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ import sinon from 'sinon';
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
interface FooAttributes {
createdAt: Date;
active: boolean;
completedAt: Date;
time: number;
}

interface FooCreationAttributes {
createdAt: Date;
active: boolean;
}
// Your SSCCE goes inside this function.
export async function run() {
// This function should be used instead of `new Sequelize()`.
Expand All @@ -21,21 +31,31 @@ export async function run() {
},
});

class Foo extends Model {}
class Foo extends Model<FooAttributes, FooCreationAttributes> {
createdAt!: Date;
active!: boolean;
completedAt: Date|null = null;
time?: number;
}

Foo.init({
name: DataTypes.TEXT,
createdAt: DataTypes.DATE,
active: DataTypes.BOOLEAN,
completedAt: DataTypes.DATE,
time: {
type: DataTypes.INTEGER,
get() {
return Math.trunc(((this.completedAt ?? new Date()).getTime() - this.createdAt.getTime()) / 1000);
}
}
}, {
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);
await Foo.create({ createdAt: new Date(), active: true });

await Foo.update({ completedAt: sequelize.literal('createdAt') }, { where: { active: true } });
}
41 changes: 0 additions & 41 deletions src/sscce-sequelize-7.ts

This file was deleted.

Loading