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
Hide 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'), () => {
...
@@ -651,10 +651,9 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
describe
(
'restore'
,
()
=>
{
describe
(
'restore'
,
()
=>
{
it
(
'returns an error if the model is not paranoid'
,
function
()
{
it
(
'returns an error if the model is not paranoid'
,
async
function
()
{
return
this
.
User
.
create
({
username
:
'Peter'
,
secretValue
:
'42'
}).
then
(
user
=>
{
const
user
=
await
this
.
User
.
create
({
username
:
'Peter'
,
secretValue
:
'42'
});
expect
(()
=>
{
user
.
restore
();}).
to
.
throw
(
Error
,
'Model is not paranoid'
);
await
expect
(
user
.
restore
()).
to
.
be
.
rejectedWith
(
Error
,
'Model is not paranoid'
);
});
});
});
it
(
'restores a previously deleted model'
,
function
()
{
it
(
'restores a previously deleted model'
,
function
()
{
...
...
test/integration/model.test.js
View file @
81ce8ee
...
@@ -1555,11 +1555,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -1555,11 +1555,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
describe
(
'restore'
,
()
=>
{
describe
(
'restore'
,
()
=>
{
it
(
'synchronously throws an error if the model is not paranoid'
,
async
function
()
{
it
(
'rejects with an error if the model is not paranoid'
,
async
function
()
{
expect
(()
=>
{
await
expect
(
this
.
User
.
restore
({
where
:
{
secretValue
:
'42'
}
})).
to
.
be
.
rejectedWith
(
Error
,
'Model is not paranoid'
);
this
.
User
.
restore
({
where
:
{
secretValue
:
'42'
}
});
throw
new
Error
(
'Did not throw synchronously'
);
}).
to
.
throw
(
Error
,
'Model is not paranoid'
);
});
});
it
(
'restores a previously deleted model'
,
async
function
()
{
it
(
'restores a previously deleted model'
,
async
function
()
{
...
...
test/unit/increment.test.js
View file @
81ce8ee
...
@@ -18,14 +18,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -18,14 +18,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
count
:
Sequelize
.
BIGINT
count
:
Sequelize
.
BIGINT
});
});
it
(
'should reject if options are missing'
,
()
=>
{
it
(
'should reject if options are missing'
,
async
()
=>
{
return
expect
(()
=>
Model
.
increment
([
'id'
,
'count'
]))
await
expect
(
Model
.
increment
([
'id'
,
'count'
]))
.
to
.
throw
(
'Missing where attribute in the options parameter'
);
.
to
.
be
.
rejectedWith
(
'Missing where attribute in the options parameter'
);
});
});
it
(
'should reject if options.where are missing'
,
()
=>
{
it
(
'should reject if options.where are missing'
,
async
()
=>
{
return
expect
(()
=>
Model
.
increment
([
'id'
,
'count'
],
{
by
:
10
}))
await
expect
(
Model
.
increment
([
'id'
,
'count'
],
{
by
:
10
}))
.
to
.
throw
(
'Missing where attribute in the options parameter'
);
.
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'),
...
@@ -9,15 +9,13 @@ const chai = require('chai'),
describe
(
Support
.
getTestDialectTeaser
(
'Instance'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'Instance'
),
()
=>
{
describe
(
'save'
,
()
=>
{
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'
,
{
const
Model
=
current
.
define
(
'User'
,
{
}),
}),
instance
=
Model
.
build
({},
{
isNewRecord
:
false
});
instance
=
Model
.
build
({},
{
isNewRecord
:
false
});
expect
(()
=>
{
await
expect
(
instance
.
save
()).
to
.
be
.
rejected
;
instance
.
save
();
}).
to
.
throw
();
});
});
describe
(
'options tests'
,
()
=>
{
describe
(
'options tests'
,
()
=>
{
...
...
test/unit/model/destroy.test.js
View file @
81ce8ee
...
@@ -35,13 +35,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -35,13 +35,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this
.
stubDelete
.
restore
();
this
.
stubDelete
.
restore
();
});
});
it
(
'can detect complex objects'
,
()
=>
{
it
(
'can detect complex objects'
,
async
()
=>
{
const
Where
=
function
()
{
this
.
secretValue
=
'1'
;
};
const
Where
=
function
()
{
this
.
secretValue
=
'1'
;
};
expect
(()
=>
{
await
expect
(
User
.
destroy
({
where
:
new
Where
()
})).
to
.
be
.
rejected
;
User
.
destroy
({
where
:
new
Where
()
});
}).
to
.
throw
();
});
});
});
});
});
});
test/unit/model/findall.test.js
View file @
81ce8ee
...
@@ -65,9 +65,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -65,9 +65,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect
(
this
.
warnOnInvalidOptionsStub
.
calledOnce
).
to
.
equal
(
true
);
expect
(
this
.
warnOnInvalidOptionsStub
.
calledOnce
).
to
.
equal
(
true
);
});
});
it
(
'Throws an error when the attributes option is formatted incorrectly'
,
()
=>
{
it
(
'Throws an error when the attributes option is formatted incorrectly'
,
async
()
=>
{
const
errorFunction
=
Model
.
findAll
.
bind
(
Model
,
{
attributes
:
'name'
});
await
expect
(
Model
.
findAll
({
attributes
:
'name'
})).
to
.
be
.
rejectedWith
(
sequelizeErrors
.
QueryError
);
expect
(
errorFunction
).
to
.
throw
(
sequelizeErrors
.
QueryError
);
});
});
});
});
...
...
test/unit/model/update.test.js
View file @
81ce8ee
...
@@ -46,12 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -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'
;
};
const
Where
=
function
()
{
this
.
secretValue
=
'1'
;
};
expect
(()
=>
{
await
expect
(
this
.
User
.
update
(
this
.
updates
,
{
where
:
new
Where
()
})).
to
.
be
.
rejected
;
this
.
User
.
update
(
this
.
updates
,
{
where
:
new
Where
()
});
}).
to
.
throw
();
});
});
});
});
});
});
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