Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit c31d68da
authored
May 22, 2020
by
Andy Edwards
Committed by
GitHub
May 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(integration/sequelize): asyncify (#12295)
1 parent
b17e7d8f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
39 deletions
test/integration/sequelize/deferrable.test.js
test/integration/sequelize/deferrable.test.js
View file @
c31d68d
...
@@ -14,7 +14,7 @@ if (!Support.sequelize.dialect.supports.deferrableConstraints) {
...
@@ -14,7 +14,7 @@ if (!Support.sequelize.dialect.supports.deferrableConstraints) {
describe
(
Support
.
getTestDialectTeaser
(
'Sequelize'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'Sequelize'
),
()
=>
{
describe
(
'Deferrable'
,
()
=>
{
describe
(
'Deferrable'
,
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
run
=
function
(
deferrable
,
options
)
{
this
.
run
=
async
function
(
deferrable
,
options
)
{
options
=
options
||
{};
options
=
options
||
{};
const
taskTableName
=
options
.
taskTableName
||
`tasks_
${
config
.
rand
()}
`
;
const
taskTableName
=
options
.
taskTableName
||
`tasks_
${
config
.
rand
()}
`
;
...
@@ -42,69 +42,62 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
...
@@ -42,69 +42,62 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
}
}
);
);
return
User
.
sync
({
force
:
true
}).
then
(()
=>
{
await
User
.
sync
({
force
:
true
});
return
Task
.
sync
({
force
:
true
});
await
Task
.
sync
({
force
:
true
});
}).
then
(()
=>
{
return
this
.
sequelize
.
transaction
(
transactionOptions
,
t
=>
{
return
this
.
sequelize
.
transaction
(
transactionOptions
,
async
t
=>
{
return
Task
const
task0
=
await
Task
.
create
({
title
:
'a task'
,
user_id
:
-
1
},
{
transaction
:
t
})
.
create
({
title
:
'a task'
,
user_id
:
-
1
},
{
transaction
:
t
});
.
then
(
task
=>
{
return
Promise
.
all
([
task
,
User
.
create
({},
{
transaction
:
t
})]);
const
[
task
,
user
]
=
await
Promise
.
all
([
task0
,
User
.
create
({},
{
transaction
:
t
})]);
})
task
.
user_id
=
user
.
id
;
.
then
(([
task
,
user
])
=>
{
return
task
.
save
({
transaction
:
t
});
task
.
user_id
=
user
.
id
;
return
task
.
save
({
transaction
:
t
});
});
});
});
});
};
};
});
});
describe
(
'NOT'
,
()
=>
{
describe
(
'NOT'
,
()
=>
{
it
(
'does not allow the violation of the foreign key constraint'
,
function
()
{
it
(
'does not allow the violation of the foreign key constraint'
,
async
function
()
{
return
expect
(
this
.
run
(
Sequelize
.
Deferrable
.
NOT
)).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ForeignKeyConstraintError
);
await
expect
(
this
.
run
(
Sequelize
.
Deferrable
.
NOT
)).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ForeignKeyConstraintError
);
});
});
});
});
describe
(
'INITIALLY_IMMEDIATE'
,
()
=>
{
describe
(
'INITIALLY_IMMEDIATE'
,
()
=>
{
it
(
'allows the violation of the foreign key constraint if the transaction is deferred'
,
function
()
{
it
(
'allows the violation of the foreign key constraint if the transaction is deferred'
,
async
function
()
{
return
this
const
task
=
await
this
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_IMMEDIATE
)
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_IMMEDIATE
);
.
then
(
task
=>
{
expect
(
task
.
title
).
to
.
equal
(
'a task'
);
expect
(
task
.
title
).
to
.
equal
(
'a task'
);
expect
(
task
.
user_id
).
to
.
equal
(
1
);
expect
(
task
.
user_id
).
to
.
equal
(
1
);
});
});
});
it
(
'does not allow the violation of the foreign key constraint if the transaction is not deffered'
,
function
()
{
it
(
'does not allow the violation of the foreign key constraint if the transaction is not deffered'
,
async
function
()
{
return
expect
(
this
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_IMMEDIATE
,
{
await
expect
(
this
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_IMMEDIATE
,
{
deferrable
:
undefined
deferrable
:
undefined
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ForeignKeyConstraintError
);
})).
to
.
eventually
.
be
.
rejectedWith
(
Sequelize
.
ForeignKeyConstraintError
);
});
});
it
(
'allows the violation of the foreign key constraint if the transaction deferres only the foreign key constraint'
,
function
()
{
it
(
'allows the violation of the foreign key constraint if the transaction deferres only the foreign key constraint'
,
async
function
()
{
const
taskTableName
=
`tasks_
${
config
.
rand
()}
`
;
const
taskTableName
=
`tasks_
${
config
.
rand
()}
`
;
return
this
const
task
=
await
this
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_IMMEDIATE
,
{
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_IMMEDIATE
,
{
deferrable
:
Sequelize
.
Deferrable
.
SET_DEFERRED
([
`
${
taskTableName
}
_user_id_fkey`
]),
deferrable
:
Sequelize
.
Deferrable
.
SET_DEFERRED
([
`
${
taskTableName
}
_user_id_fkey`
]),
taskTableName
taskTableName
})
.
then
(
task
=>
{
expect
(
task
.
title
).
to
.
equal
(
'a task'
);
expect
(
task
.
user_id
).
to
.
equal
(
1
);
});
});
expect
(
task
.
title
).
to
.
equal
(
'a task'
);
expect
(
task
.
user_id
).
to
.
equal
(
1
);
});
});
});
});
describe
(
'INITIALLY_DEFERRED'
,
()
=>
{
describe
(
'INITIALLY_DEFERRED'
,
()
=>
{
it
(
'allows the violation of the foreign key constraint'
,
function
()
{
it
(
'allows the violation of the foreign key constraint'
,
async
function
()
{
return
this
const
task
=
await
this
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_DEFERRED
)
.
run
(
Sequelize
.
Deferrable
.
INITIALLY_DEFERRED
);
.
then
(
task
=>
{
expect
(
task
.
title
).
to
.
equal
(
'a task'
);
expect
(
task
.
title
).
to
.
equal
(
'a task'
);
expect
(
task
.
user_id
).
to
.
equal
(
1
);
expect
(
task
.
user_id
).
to
.
equal
(
1
);
});
});
});
});
});
});
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment