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 9d3be832
authored
Jan 24, 2020
by
Pedro Augusto de Paula Barbosa
Committed by
Sushant
Jan 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(*): use async/await (#11864)
1 parent
6837a174
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
63 deletions
test/integration/associations/belongs-to-many.test.js
test/integration/associations/belongs-to.test.js
test/integration/cls.test.js
test/integration/model.test.js
test/integration/associations/belongs-to-many.test.js
View file @
9d3be83
...
@@ -1437,19 +1437,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...
@@ -1437,19 +1437,15 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
});
});
});
});
it
(
'should count all associations'
,
function
()
{
it
(
'should count all associations'
,
async
function
()
{
return
expect
(
this
.
user
.
countTasks
({})).
to
.
eventually
.
equal
(
2
);
expect
(
await
this
.
user
.
countTasks
({})).
to
.
equal
(
2
);
});
});
it
(
'should count filtered associations'
,
function
()
{
it
(
'should count filtered associations'
,
async
function
()
{
return
expect
(
this
.
user
.
countTasks
({
expect
(
await
this
.
user
.
countTasks
({
where
:
{
active
:
true
}
})).
to
.
equal
(
1
);
where
:
{
active
:
true
}
})).
to
.
eventually
.
equal
(
1
);
});
});
it
(
'should count scoped associations'
,
function
()
{
it
(
'should count scoped associations'
,
async
function
()
{
this
.
User
.
belongsToMany
(
this
.
Task
,
{
this
.
User
.
belongsToMany
(
this
.
Task
,
{
as
:
'activeTasks'
,
as
:
'activeTasks'
,
through
:
this
.
UserTask
,
through
:
this
.
UserTask
,
...
@@ -1458,12 +1454,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...
@@ -1458,12 +1454,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}
}
});
});
return
expect
(
this
.
user
.
countActiveTasks
({})).
to
.
eventually
.
equal
(
1
);
expect
(
await
this
.
user
.
countActiveTasks
({})).
to
.
equal
(
1
);
});
});
it
(
'should count scoped through associations'
,
function
()
{
it
(
'should count scoped through associations'
,
async
function
()
{
const
user
=
this
.
user
;
this
.
User
.
belongsToMany
(
this
.
Task
,
{
this
.
User
.
belongsToMany
(
this
.
Task
,
{
as
:
'startedTasks'
,
as
:
'startedTasks'
,
through
:
{
through
:
{
...
@@ -1474,20 +1468,13 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...
@@ -1474,20 +1468,13 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}
}
});
});
return
Promise
.
join
(
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
this
.
Task
.
create
().
then
(
task
=>
{
await
this
.
user
.
addTask
(
await
this
.
Task
.
create
(),
{
return
user
.
addTask
(
task
,
{
through
:
{
started
:
true
}
});
}),
this
.
Task
.
create
().
then
(
task
=>
{
return
user
.
addTask
(
task
,
{
through
:
{
started
:
true
}
through
:
{
started
:
true
}
});
});
})
}
).
then
(()
=>
{
return
expect
(
user
.
countStartedTasks
({})).
to
.
eventually
.
equal
(
2
);
expect
(
await
this
.
user
.
countStartedTasks
({})).
to
.
equal
(
2
);
});
});
});
});
});
...
...
test/integration/associations/belongs-to.test.js
View file @
9d3be83
...
@@ -381,27 +381,19 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
...
@@ -381,27 +381,19 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => {
});
});
});
});
it
(
'supports setting same association twice'
,
function
()
{
it
(
'supports setting same association twice'
,
async
function
()
{
const
Home
=
this
.
sequelize
.
define
(
'home'
,
{})
,
const
Home
=
this
.
sequelize
.
define
(
'home'
,
{})
;
User
=
this
.
sequelize
.
define
(
'user'
);
const
User
=
this
.
sequelize
.
define
(
'user'
);
Home
.
belongsTo
(
User
);
Home
.
belongsTo
(
User
);
const
ctx
=
{};
await
this
.
sequelize
.
sync
({
force
:
true
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
const
[
home
,
user
]
=
await
Promise
.
all
([
return
Promise
.
all
([
Home
.
create
(),
Home
.
create
(),
User
.
create
()
User
.
create
()
]);
]);
}).
then
(([
home
,
user
])
=>
{
await
home
.
setUser
(
user
);
ctx
.
home
=
home
;
expect
(
await
home
.
getUser
()).
to
.
have
.
property
(
'id'
,
user
.
id
);
ctx
.
user
=
user
;
return
home
.
setUser
(
user
);
}).
then
(()
=>
{
return
ctx
.
home
.
setUser
(
ctx
.
user
);
}).
then
(()
=>
{
return
expect
(
ctx
.
home
.
getUser
()).
to
.
eventually
.
have
.
property
(
'id'
,
ctx
.
user
.
get
(
'id'
));
});
});
});
});
});
...
...
test/integration/cls.test.js
View file @
9d3be83
...
@@ -19,46 +19,37 @@ if (current.dialect.supports.transactions) {
...
@@ -19,46 +19,37 @@ if (current.dialect.supports.transactions) {
delete
Sequelize
.
_cls
;
delete
Sequelize
.
_cls
;
});
});
beforeEach
(
function
()
{
beforeEach
(
async
function
()
{
return
Support
.
prepareTransactionTest
(
this
.
sequelize
).
then
(
sequelize
=>
{
this
.
sequelize
=
await
Support
.
prepareTransactionTest
(
this
.
sequelize
);
this
.
sequelize
=
sequelize
;
this
.
ns
=
cls
.
getNamespace
(
'sequelize'
);
this
.
ns
=
cls
.
getNamespace
(
'sequelize'
);
this
.
User
=
this
.
sequelize
.
define
(
'user'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'user'
,
{
name
:
Sequelize
.
STRING
name
:
Sequelize
.
STRING
});
});
return
this
.
sequelize
.
sync
({
force
:
true
});
await
this
.
sequelize
.
sync
({
force
:
true
});
});
});
});
describe
(
'context'
,
()
=>
{
describe
(
'context'
,
()
=>
{
it
(
'does not use continuation storage on manually managed transactions'
,
function
()
{
it
(
'does not use continuation storage on manually managed transactions'
,
function
()
{
return
Sequelize
.
_clsRun
(()
=>
{
return
Sequelize
.
_clsRun
(
async
()
=>
{
return
this
.
sequelize
.
transaction
().
then
(
transaction
=>
{
const
transaction
=
await
this
.
sequelize
.
transaction
();
expect
(
this
.
ns
.
get
(
'transaction'
)).
not
.
to
.
be
.
ok
;
expect
(
this
.
ns
.
get
(
'transaction'
)).
not
.
to
.
be
.
ok
;
return
transaction
.
rollback
();
await
transaction
.
rollback
();
});
});
});
});
});
it
(
'supports several concurrent transactions'
,
function
()
{
it
(
'supports several concurrent transactions'
,
async
function
()
{
let
t1id
,
t2id
;
let
t1id
,
t2id
;
return
Promise
.
join
(
await
Promise
.
all
([
this
.
sequelize
.
transaction
(()
=>
{
this
.
sequelize
.
transaction
(
async
()
=>
{
t1id
=
this
.
ns
.
get
(
'transaction'
).
id
;
t1id
=
this
.
ns
.
get
(
'transaction'
).
id
;
return
Promise
.
resolve
();
}),
}),
this
.
sequelize
.
transaction
(()
=>
{
this
.
sequelize
.
transaction
(
async
()
=>
{
t2id
=
this
.
ns
.
get
(
'transaction'
).
id
;
t2id
=
this
.
ns
.
get
(
'transaction'
).
id
;
})
return
Promise
.
resolve
();
]);
}),
()
=>
{
expect
(
t1id
).
to
.
be
.
ok
;
expect
(
t1id
).
to
.
be
.
ok
;
expect
(
t2id
).
to
.
be
.
ok
;
expect
(
t2id
).
to
.
be
.
ok
;
expect
(
t1id
).
not
.
to
.
equal
(
t2id
);
expect
(
t1id
).
not
.
to
.
equal
(
t2id
);
}
);
});
});
it
(
'supports nested promise chains'
,
function
()
{
it
(
'supports nested promise chains'
,
function
()
{
...
@@ -145,8 +136,8 @@ if (current.dialect.supports.transactions) {
...
@@ -145,8 +136,8 @@ if (current.dialect.supports.transactions) {
it
(
'automagically uses the transaction in all calls with async/await'
,
function
()
{
it
(
'automagically uses the transaction in all calls with async/await'
,
function
()
{
return
this
.
sequelize
.
transaction
(
async
()
=>
{
return
this
.
sequelize
.
transaction
(
async
()
=>
{
await
this
.
User
.
create
({
name
:
'bob'
});
await
this
.
User
.
create
({
name
:
'bob'
});
await
expect
(
this
.
User
.
findAll
({
transaction
:
null
})).
to
.
eventually
.
have
.
length
(
0
);
expect
(
await
this
.
User
.
findAll
({
transaction
:
null
})).
to
.
have
.
length
(
0
);
await
expect
(
this
.
User
.
findAll
({})).
to
.
eventually
.
have
.
length
(
1
);
expect
(
await
this
.
User
.
findAll
({})).
to
.
have
.
length
(
1
);
});
});
});
});
});
});
...
...
test/integration/model.test.js
View file @
9d3be83
This diff is collapsed.
Click to expand it.
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