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 81ce8ee3
authored
Apr 19, 2020
by
Andy Edwards
Committed by
GitHub
Apr 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(model): asyncify methods (#12122)
1 parent
bccb447b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
19 additions
and
31 deletions
lib/model.js
test/integration/instance.test.js
test/integration/model.test.js
test/unit/increment.test.js
test/unit/instance/save.test.js
test/unit/model/destroy.test.js
test/unit/model/findall.test.js
test/unit/model/update.test.js
lib/model.js
View file @
81ce8ee
This diff is collapsed.
Click to expand it.
test/integration/instance.test.js
View file @
81ce8ee
...
...
@@ -651,10 +651,9 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
describe
(
'restore'
,
()
=>
{
it
(
'returns an error if the model is not paranoid'
,
function
()
{
return
this
.
User
.
create
({
username
:
'Peter'
,
secretValue
:
'42'
}).
then
(
user
=>
{
expect
(()
=>
{
user
.
restore
();}).
to
.
throw
(
Error
,
'Model is not paranoid'
);
});
it
(
'returns an error if the model is not paranoid'
,
async
function
()
{
const
user
=
await
this
.
User
.
create
({
username
:
'Peter'
,
secretValue
:
'42'
});
await
expect
(
user
.
restore
()).
to
.
be
.
rejectedWith
(
Error
,
'Model is not paranoid'
);
});
it
(
'restores a previously deleted model'
,
function
()
{
...
...
test/integration/model.test.js
View file @
81ce8ee
...
...
@@ -1555,11 +1555,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
describe
(
'restore'
,
()
=>
{
it
(
'synchronously throws an error if the model is not paranoid'
,
async
function
()
{
expect
(()
=>
{
this
.
User
.
restore
({
where
:
{
secretValue
:
'42'
}
});
throw
new
Error
(
'Did not throw synchronously'
);
}).
to
.
throw
(
Error
,
'Model is not paranoid'
);
it
(
'rejects with an error if the model is not paranoid'
,
async
function
()
{
await
expect
(
this
.
User
.
restore
({
where
:
{
secretValue
:
'42'
}
})).
to
.
be
.
rejectedWith
(
Error
,
'Model is not paranoid'
);
});
it
(
'restores a previously deleted model'
,
async
function
()
{
...
...
test/unit/increment.test.js
View file @
81ce8ee
...
...
@@ -18,14 +18,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
count
:
Sequelize
.
BIGINT
});
it
(
'should reject if options are missing'
,
()
=>
{
return
expect
(()
=>
Model
.
increment
([
'id'
,
'count'
]))
.
to
.
throw
(
'Missing where attribute in the options parameter'
);
it
(
'should reject if options are missing'
,
async
()
=>
{
await
expect
(
Model
.
increment
([
'id'
,
'count'
]))
.
to
.
be
.
rejectedWith
(
'Missing where attribute in the options parameter'
);
});
it
(
'should reject if options.where are missing'
,
()
=>
{
return
expect
(()
=>
Model
.
increment
([
'id'
,
'count'
],
{
by
:
10
}))
.
to
.
throw
(
'Missing where attribute in the options parameter'
);
it
(
'should reject if options.where are missing'
,
async
()
=>
{
await
expect
(
Model
.
increment
([
'id'
,
'count'
],
{
by
:
10
}))
.
to
.
be
.
rejectedWith
(
'Missing where attribute in the options parameter'
);
});
});
});
...
...
test/unit/instance/save.test.js
View file @
81ce8ee
...
...
@@ -9,15 +9,13 @@ const chai = require('chai'),
describe
(
Support
.
getTestDialectTeaser
(
'Instance'
),
()
=>
{
describe
(
'save'
,
()
=>
{
it
(
'should disallow saves if no primary key values is present'
,
()
=>
{
it
(
'should disallow saves if no primary key values is present'
,
async
()
=>
{
const
Model
=
current
.
define
(
'User'
,
{
}),
instance
=
Model
.
build
({},
{
isNewRecord
:
false
});
expect
(()
=>
{
instance
.
save
();
}).
to
.
throw
();
await
expect
(
instance
.
save
()).
to
.
be
.
rejected
;
});
describe
(
'options tests'
,
()
=>
{
...
...
test/unit/model/destroy.test.js
View file @
81ce8ee
...
...
@@ -35,13 +35,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this
.
stubDelete
.
restore
();
});
it
(
'can detect complex objects'
,
()
=>
{
it
(
'can detect complex objects'
,
async
()
=>
{
const
Where
=
function
()
{
this
.
secretValue
=
'1'
;
};
expect
(()
=>
{
User
.
destroy
({
where
:
new
Where
()
});
}).
to
.
throw
();
await
expect
(
User
.
destroy
({
where
:
new
Where
()
})).
to
.
be
.
rejected
;
});
});
});
test/unit/model/findall.test.js
View file @
81ce8ee
...
...
@@ -65,9 +65,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect
(
this
.
warnOnInvalidOptionsStub
.
calledOnce
).
to
.
equal
(
true
);
});
it
(
'Throws an error when the attributes option is formatted incorrectly'
,
()
=>
{
const
errorFunction
=
Model
.
findAll
.
bind
(
Model
,
{
attributes
:
'name'
});
expect
(
errorFunction
).
to
.
throw
(
sequelizeErrors
.
QueryError
);
it
(
'Throws an error when the attributes option is formatted incorrectly'
,
async
()
=>
{
await
expect
(
Model
.
findAll
({
attributes
:
'name'
})).
to
.
be
.
rejectedWith
(
sequelizeErrors
.
QueryError
);
});
});
...
...
test/unit/model/update.test.js
View file @
81ce8ee
...
...
@@ -46,12 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it
(
'can detect complexe objects'
,
function
()
{
it
(
'can detect complexe objects'
,
async
function
()
{
const
Where
=
function
()
{
this
.
secretValue
=
'1'
;
};
expect
(()
=>
{
this
.
User
.
update
(
this
.
updates
,
{
where
:
new
Where
()
});
}).
to
.
throw
();
await
expect
(
this
.
User
.
update
(
this
.
updates
,
{
where
:
new
Where
()
})).
to
.
be
.
rejected
;
});
});
});
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