MCPcopy
hub / github.com/sequelize/sequelize / describeDeferrableTest

Function describeDeferrableTest

test/integration/sequelize/deferrable.test.js:14–82  ·  test/integration/sequelize/deferrable.test.js::describeDeferrableTest
(title, defineModels)

Source from the content-addressed store, hash-verified

12describe(Support.getTestDialectTeaser(class="st">'Sequelize'), () => {
13 describe(class="st">'Deferrable', () => {
14 const describeDeferrableTest = (title, defineModels) => {
15 describe(title, () => {
16 beforeEach(function() {
17 this.run = async function(deferrable, options) {
18 options = options || {};
19
20 const taskTableName = options.taskTableName || `tasks_${Support.rand()}`;
21 const transactionOptions = { deferrable: Sequelize.Deferrable.SET_DEFERRED, ...options };
22 const userTableName = `users_${Support.rand()}`;
23
24 const { Task, User } = await defineModels({ sequelize: this.sequelize, userTableName, deferrable, taskTableName });
25
26 return this.sequelize.transaction(transactionOptions, async t => {
27 const task0 = await Task
28 .create({ title: class="st">'a task', user_id: -1 }, { transaction: t });
29
30 const [task, user] = await Promise.all([task0, User.create({}, { transaction: t })]);
31 task.user_id = user.id;
32 return task.save({ transaction: t });
33 });
34 };
35 });
36
37 describe(class="st">'NOT', () => {
38 it(class="st">'does not allow the violation of the foreign key constraint', async function() {
39 await expect(this.run(Sequelize.Deferrable.NOT)).to.eventually.be.rejectedWith(Sequelize.ForeignKeyConstraintError);
40 });
41 });
42
43 describe(class="st">'INITIALLY_IMMEDIATE', () => {
44 it(class="st">'allows the violation of the foreign key constraint if the transaction is deferred', async function() {
45 const task = await this
46 .run(Sequelize.Deferrable.INITIALLY_IMMEDIATE);
47
48 expect(task.title).to.equal(class="st">'a task');
49 expect(task.user_id).to.equal(1);
50 });
51
52 it(class="st">'does not allow the violation of the foreign key constraint if the transaction is not deffered', async function() {
53 await expect(this.run(Sequelize.Deferrable.INITIALLY_IMMEDIATE, {
54 deferrable: undefined
55 })).to.eventually.be.rejectedWith(Sequelize.ForeignKeyConstraintError);
56 });
57
58 it(class="st">'allows the violation of the foreign key constraint if the transaction deferres only the foreign key constraint', async function() {
59 const taskTableName = `tasks_${Support.rand()}`;
60
61 const task = await this
62 .run(Sequelize.Deferrable.INITIALLY_IMMEDIATE, {
63 deferrable: Sequelize.Deferrable.SET_DEFERRED([`${taskTableName}_user_id_fkey`]),
64 taskTableName
65 });
66
67 expect(task.title).to.equal(class="st">'a task');
68 expect(task.user_id).to.equal(1);
69 });
70 });
71

Callers 1

deferrable.test.jsFile · 0.85

Calls 5

transactionMethod · 0.80
allMethod · 0.80
saveMethod · 0.80
createMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected