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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
711 additions
and
1125 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'), () => {
});
});
it
(
'should count all associations'
,
function
()
{
return
expect
(
this
.
user
.
countTasks
({})).
to
.
eventually
.
equal
(
2
);
it
(
'should count all associations'
,
async
function
()
{
expect
(
await
this
.
user
.
countTasks
({})).
to
.
equal
(
2
);
});
it
(
'should count filtered associations'
,
function
()
{
return
expect
(
this
.
user
.
countTasks
({
where
:
{
active
:
true
}
})).
to
.
eventually
.
equal
(
1
);
it
(
'should count filtered associations'
,
async
function
()
{
expect
(
await
this
.
user
.
countTasks
({
where
:
{
active
:
true
}
})).
to
.
equal
(
1
);
});
it
(
'should count scoped associations'
,
function
()
{
it
(
'should count scoped associations'
,
async
function
()
{
this
.
User
.
belongsToMany
(
this
.
Task
,
{
as
:
'activeTasks'
,
through
:
this
.
UserTask
,
...
...
@@ -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
()
{
const
user
=
this
.
user
;
it
(
'should count scoped through associations'
,
async
function
()
{
this
.
User
.
belongsToMany
(
this
.
Task
,
{
as
:
'startedTasks'
,
through
:
{
...
...
@@ -1474,20 +1468,13 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}
});
return
Promise
.
join
(
this
.
Task
.
create
().
then
(
task
=>
{
return
user
.
addTask
(
task
,
{
through
:
{
started
:
true
}
});
}),
this
.
Task
.
create
().
then
(
task
=>
{
return
user
.
addTask
(
task
,
{
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
await
this
.
user
.
addTask
(
await
this
.
Task
.
create
(),
{
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'), () => {
});
});
it
(
'supports setting same association twice'
,
function
()
{
const
Home
=
this
.
sequelize
.
define
(
'home'
,
{})
,
User
=
this
.
sequelize
.
define
(
'user'
);
it
(
'supports setting same association twice'
,
async
function
()
{
const
Home
=
this
.
sequelize
.
define
(
'home'
,
{})
;
const
User
=
this
.
sequelize
.
define
(
'user'
);
Home
.
belongsTo
(
User
);
const
ctx
=
{};
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
Promise
.
all
([
await
this
.
sequelize
.
sync
({
force
:
true
});
const
[
home
,
user
]
=
await
Promise
.
all
([
Home
.
create
(),
User
.
create
()
]);
}).
then
(([
home
,
user
])
=>
{
ctx
.
home
=
home
;
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'
));
});
await
home
.
setUser
(
user
);
expect
(
await
home
.
getUser
()).
to
.
have
.
property
(
'id'
,
user
.
id
);
});
});
...
...
test/integration/cls.test.js
View file @
9d3be83
...
...
@@ -19,46 +19,37 @@ if (current.dialect.supports.transactions) {
delete
Sequelize
.
_cls
;
});
beforeEach
(
function
()
{
return
Support
.
prepareTransactionTest
(
this
.
sequelize
).
then
(
sequelize
=>
{
this
.
sequelize
=
sequelize
;
beforeEach
(
async
function
()
{
this
.
sequelize
=
await
Support
.
prepareTransactionTest
(
this
.
sequelize
);
this
.
ns
=
cls
.
getNamespace
(
'sequelize'
);
this
.
User
=
this
.
sequelize
.
define
(
'user'
,
{
name
:
Sequelize
.
STRING
});
return
this
.
sequelize
.
sync
({
force
:
true
});
});
await
this
.
sequelize
.
sync
({
force
:
true
});
});
describe
(
'context'
,
()
=>
{
it
(
'does not use continuation storage on manually managed transactions'
,
function
()
{
return
Sequelize
.
_clsRun
(()
=>
{
return
this
.
sequelize
.
transaction
().
then
(
transaction
=>
{
return
Sequelize
.
_clsRun
(
async
()
=>
{
const
transaction
=
await
this
.
sequelize
.
transaction
();
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
;
return
Promise
.
join
(
this
.
sequelize
.
transaction
(()
=>
{
await
Promise
.
all
([
this
.
sequelize
.
transaction
(
async
()
=>
{
t1id
=
this
.
ns
.
get
(
'transaction'
).
id
;
return
Promise
.
resolve
();
}),
this
.
sequelize
.
transaction
(()
=>
{
this
.
sequelize
.
transaction
(
async
()
=>
{
t2id
=
this
.
ns
.
get
(
'transaction'
).
id
;
return
Promise
.
resolve
();
}),
()
=>
{
})
]);
expect
(
t1id
).
to
.
be
.
ok
;
expect
(
t2id
).
to
.
be
.
ok
;
expect
(
t1id
).
not
.
to
.
equal
(
t2id
);
}
);
});
it
(
'supports nested promise chains'
,
function
()
{
...
...
@@ -145,8 +136,8 @@ if (current.dialect.supports.transactions) {
it
(
'automagically uses the transaction in all calls with async/await'
,
function
()
{
return
this
.
sequelize
.
transaction
(
async
()
=>
{
await
this
.
User
.
create
({
name
:
'bob'
});
await
expect
(
this
.
User
.
findAll
({
transaction
:
null
})).
to
.
eventually
.
have
.
length
(
0
);
await
expect
(
this
.
User
.
findAll
({})).
to
.
eventually
.
have
.
length
(
1
);
expect
(
await
this
.
User
.
findAll
({
transaction
:
null
})).
to
.
have
.
length
(
0
);
expect
(
await
this
.
User
.
findAll
({})).
to
.
have
.
length
(
1
);
});
});
});
...
...
test/integration/model.test.js
View file @
9d3be83
This diff could not be displayed because it is too large.
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