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 1e7e4108
authored
Mar 18, 2019
by
Simon Schick
Committed by
Sushant
Mar 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(tests): use sinon resolves (#10567)
1 parent
80a79315
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
118 additions
and
170 deletions
test/integration/dialects/abstract/connection-manager.test.js
test/integration/dialects/postgres/range.test.js
test/integration/sequelize.transaction.test.js
test/support.js
test/unit/associations/belongs-to-many.test.js
test/unit/associations/has-many.test.js
test/unit/connection-manager.test.js
test/unit/dialects/mssql/query.test.js
test/unit/hooks.test.js
test/unit/instance-validator.test.js
test/unit/instance/decrement.test.js
test/unit/instance/destroy.test.js
test/unit/instance/increment.test.js
test/unit/instance/reload.test.js
test/unit/instance/restore.test.js
test/unit/instance/save.test.js
test/unit/model/bulkcreate.test.js
test/unit/model/count.test.js
test/unit/model/destroy.test.js
test/unit/model/find-and-count-all.test.js
test/unit/model/find-create-find.test.js
test/unit/model/find-or-create.test.js
test/unit/model/findall.test.js
test/unit/model/findone.test.js
test/unit/model/update.test.js
test/unit/model/upsert.test.js
test/unit/model/validation.test.js
test/unit/sql/change-column.test.js
test/unit/transaction.test.js
test/integration/dialects/abstract/connection-manager.test.js
View file @
1e7e410
...
@@ -7,8 +7,7 @@ const chai = require('chai'),
...
@@ -7,8 +7,7 @@ const chai = require('chai'),
Config
=
require
(
'../../../config/config'
),
Config
=
require
(
'../../../config/config'
),
ConnectionManager
=
require
(
'../../../../lib/dialects/abstract/connection-manager'
),
ConnectionManager
=
require
(
'../../../../lib/dialects/abstract/connection-manager'
),
Pool
=
require
(
'sequelize-pool'
).
Pool
,
Pool
=
require
(
'sequelize-pool'
).
Pool
,
_
=
require
(
'lodash'
),
_
=
require
(
'lodash'
);
Promise
=
require
(
'../../../../lib/promise'
);
const
baseConf
=
Config
[
Support
.
getTestDialect
()];
const
baseConf
=
Config
[
Support
.
getTestDialect
()];
const
poolEntry
=
{
const
poolEntry
=
{
...
@@ -22,6 +21,7 @@ describe('Connection Manager', () => {
...
@@ -22,6 +21,7 @@ describe('Connection Manager', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
sandbox
=
sinon
.
createSandbox
();
sandbox
=
sinon
.
createSandbox
();
sandbox
.
usingPromise
(
require
(
'bluebird'
));
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -75,15 +75,13 @@ describe('Connection Manager', () => {
...
@@ -75,15 +75,13 @@ describe('Connection Manager', () => {
const
sequelize
=
Support
.
createSequelizeInstance
(
options
);
const
sequelize
=
Support
.
createSequelizeInstance
(
options
);
const
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
const
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
const
resolvedPromise
=
new
Promise
(
resolve
=>
{
const
res
=
{
resolve
({
queryType
:
'read'
queryType
:
'read'
};
});
});
const
connectStub
=
sandbox
.
stub
(
connectionManager
,
'_connect'
).
re
turns
(
resolvedPromise
);
const
connectStub
=
sandbox
.
stub
(
connectionManager
,
'_connect'
).
re
solves
(
res
);
sandbox
.
stub
(
connectionManager
,
'_disconnect'
).
re
turns
(
resolvedPromise
);
sandbox
.
stub
(
connectionManager
,
'_disconnect'
).
re
solves
(
res
);
sandbox
.
stub
(
sequelize
,
'databaseVersion'
).
re
turns
(
resolvedPromise
);
sandbox
.
stub
(
sequelize
,
'databaseVersion'
).
re
solves
(
res
);
connectionManager
.
initPools
();
connectionManager
.
initPools
();
const
queryOptions
=
{
const
queryOptions
=
{
...
@@ -121,15 +119,12 @@ describe('Connection Manager', () => {
...
@@ -121,15 +119,12 @@ describe('Connection Manager', () => {
const
sequelize
=
Support
.
createSequelizeInstance
(
options
);
const
sequelize
=
Support
.
createSequelizeInstance
(
options
);
const
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
const
connectionManager
=
new
ConnectionManager
(
Support
.
getTestDialect
(),
sequelize
);
const
resolvedPromise
=
new
Promise
(
resolve
=>
{
const
res
=
{
resolve
({
queryType
:
'read'
queryType
:
'read'
};
});
const
connectStub
=
sandbox
.
stub
(
connectionManager
,
'_connect'
).
resolves
(
res
);
});
sandbox
.
stub
(
connectionManager
,
'_disconnect'
).
resolves
(
res
);
sandbox
.
stub
(
sequelize
,
'databaseVersion'
).
resolves
(
res
);
const
connectStub
=
sandbox
.
stub
(
connectionManager
,
'_connect'
).
returns
(
resolvedPromise
);
sandbox
.
stub
(
connectionManager
,
'_disconnect'
).
returns
(
resolvedPromise
);
sandbox
.
stub
(
sequelize
,
'databaseVersion'
).
returns
(
resolvedPromise
);
connectionManager
.
initPools
();
connectionManager
.
initPools
();
const
queryOptions
=
{
const
queryOptions
=
{
...
...
test/integration/dialects/postgres/range.test.js
View file @
1e7e410
...
@@ -186,7 +186,7 @@ if (dialect.match(/^postgres/)) {
...
@@ -186,7 +186,7 @@ if (dialect.match(/^postgres/)) {
it
(
'should handle native postgres timestamp format'
,
()
=>
{
it
(
'should handle native postgres timestamp format'
,
()
=>
{
// Make sure nameOidMap is loaded
// Make sure nameOidMap is loaded
Support
.
sequelize
.
connectionManager
.
getConnection
().
then
(
connection
=>
{
return
Support
.
sequelize
.
connectionManager
.
getConnection
().
then
(
connection
=>
{
Support
.
sequelize
.
connectionManager
.
releaseConnection
(
connection
);
Support
.
sequelize
.
connectionManager
.
releaseConnection
(
connection
);
const
tsName
=
DataTypes
.
postgres
.
DATE
.
types
.
postgres
[
0
],
const
tsName
=
DataTypes
.
postgres
.
DATE
.
types
.
postgres
[
0
],
...
...
test/integration/sequelize.transaction.test.js
View file @
1e7e410
...
@@ -5,19 +5,11 @@ const chai = require('chai'),
...
@@ -5,19 +5,11 @@ const chai = require('chai'),
Support
=
require
(
'./support'
),
Support
=
require
(
'./support'
),
Promise
=
require
(
'../../lib/promise'
),
Promise
=
require
(
'../../lib/promise'
),
Transaction
=
require
(
'../../lib/transaction'
),
Transaction
=
require
(
'../../lib/transaction'
),
sinon
=
require
(
'sinon'
),
current
=
Support
.
sequelize
;
current
=
Support
.
sequelize
;
if
(
current
.
dialect
.
supports
.
transactions
)
{
if
(
current
.
dialect
.
supports
.
transactions
)
{
describe
(
Support
.
getTestDialectTeaser
(
'Sequelize#transaction'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'Sequelize#transaction'
),
()
=>
{
beforeEach
(
function
()
{
this
.
sinon
=
sinon
.
createSandbox
();
});
afterEach
(
function
()
{
this
.
sinon
.
restore
();
});
describe
(
'then'
,
()
=>
{
describe
(
'then'
,
()
=>
{
it
(
'gets triggered once a transaction has been successfully committed'
,
function
()
{
it
(
'gets triggered once a transaction has been successfully committed'
,
function
()
{
...
...
test/support.js
View file @
1e7e410
'use strict'
;
'use strict'
;
const
fs
=
require
(
'fs'
),
const
fs
=
require
(
'fs'
);
path
=
require
(
'path'
),
const
path
=
require
(
'path'
);
_
=
require
(
'lodash'
),
const
_
=
require
(
'lodash'
);
Sequelize
=
require
(
'../index'
),
const
Sequelize
=
require
(
'../index'
);
DataTypes
=
require
(
'../lib/data-types'
),
const
DataTypes
=
require
(
'../lib/data-types'
);
Config
=
require
(
'./config/config'
),
const
Config
=
require
(
'./config/config'
);
chai
=
require
(
'chai'
),
const
chai
=
require
(
'chai'
);
expect
=
chai
.
expect
,
const
expect
=
chai
.
expect
;
AbstractQueryGenerator
=
require
(
'../lib/dialects/abstract/query-generator'
);
const
AbstractQueryGenerator
=
require
(
'../lib/dialects/abstract/query-generator'
);
const
sinon
=
require
(
'sinon'
);
sinon
.
usingPromise
(
require
(
'bluebird'
));
chai
.
use
(
require
(
'chai-spies'
));
chai
.
use
(
require
(
'chai-spies'
));
chai
.
use
(
require
(
'chai-datetime'
));
chai
.
use
(
require
(
'chai-datetime'
));
...
...
test/unit/associations/belongs-to-many.test.js
View file @
1e7e410
...
@@ -5,8 +5,6 @@ const sinon = require('sinon');
...
@@ -5,8 +5,6 @@ const sinon = require('sinon');
const
expect
=
chai
.
expect
;
const
expect
=
chai
.
expect
;
const
stub
=
sinon
.
stub
;
const
stub
=
sinon
.
stub
;
const
_
=
require
(
'lodash'
);
const
_
=
require
(
'lodash'
);
const
Sequelize
=
require
(
'../../../index'
);
const
Promise
=
Sequelize
.
Promise
;
const
Support
=
require
(
'../support'
);
const
Support
=
require
(
'../support'
);
const
DataTypes
=
require
(
'../../../lib/data-types'
);
const
DataTypes
=
require
(
'../../../lib/data-types'
);
const
BelongsTo
=
require
(
'../../../lib/associations/belongs-to'
);
const
BelongsTo
=
require
(
'../../../lib/associations/belongs-to'
);
...
@@ -171,9 +169,9 @@ describe(Support.getTestDialectTeaser('belongsToMany'), () => {
...
@@ -171,9 +169,9 @@ describe(Support.getTestDialectTeaser('belongsToMany'), () => {
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
findAll
=
stub
(
UserTasks
,
'findAll'
).
re
turns
(
Promise
.
resolve
([])
);
this
.
findAll
=
stub
(
UserTasks
,
'findAll'
).
re
solves
([]
);
this
.
bulkCreate
=
stub
(
UserTasks
,
'bulkCreate'
).
re
turns
(
Promise
.
resolve
([])
);
this
.
bulkCreate
=
stub
(
UserTasks
,
'bulkCreate'
).
re
solves
([]
);
this
.
destroy
=
stub
(
UserTasks
,
'destroy'
).
re
turns
(
Promise
.
resolve
([])
);
this
.
destroy
=
stub
(
UserTasks
,
'destroy'
).
re
solves
([]
);
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
...
@@ -191,11 +189,11 @@ describe(Support.getTestDialectTeaser('belongsToMany'), () => {
...
@@ -191,11 +189,11 @@ describe(Support.getTestDialectTeaser('belongsToMany'), () => {
it
(
'uses one delete from statement'
,
function
()
{
it
(
'uses one delete from statement'
,
function
()
{
this
.
findAll
this
.
findAll
.
onFirstCall
().
re
turns
(
Promise
.
resolve
([])
)
.
onFirstCall
().
re
solves
([]
)
.
onSecondCall
().
re
turns
(
Promise
.
resolve
([
.
onSecondCall
().
re
solves
([
{
userId
:
42
,
taskId
:
15
},
{
userId
:
42
,
taskId
:
15
},
{
userId
:
42
,
taskId
:
16
}
{
userId
:
42
,
taskId
:
16
}
])
)
;
]);
return
user
.
setTasks
([
task1
,
task2
]).
then
(()
=>
{
return
user
.
setTasks
([
task1
,
task2
]).
then
(()
=>
{
return
user
.
setTasks
(
null
);
return
user
.
setTasks
(
null
);
...
...
test/unit/associations/has-many.test.js
View file @
1e7e410
...
@@ -38,8 +38,8 @@ describe(Support.getTestDialectTeaser('hasMany'), () => {
...
@@ -38,8 +38,8 @@ describe(Support.getTestDialectTeaser('hasMany'), () => {
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
findAll
=
stub
(
Task
,
'findAll'
).
re
turns
(
Promise
.
resolve
([])
);
this
.
findAll
=
stub
(
Task
,
'findAll'
).
re
solves
([]
);
this
.
update
=
stub
(
Task
,
'update'
).
re
turns
(
Promise
.
resolve
([])
);
this
.
update
=
stub
(
Task
,
'update'
).
re
solves
([]
);
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
...
@@ -56,11 +56,11 @@ describe(Support.getTestDialectTeaser('hasMany'), () => {
...
@@ -56,11 +56,11 @@ describe(Support.getTestDialectTeaser('hasMany'), () => {
it
(
'uses one delete from statement'
,
function
()
{
it
(
'uses one delete from statement'
,
function
()
{
this
.
findAll
this
.
findAll
.
onFirstCall
().
re
turns
(
Promise
.
resolve
([])
)
.
onFirstCall
().
re
solves
([]
)
.
onSecondCall
().
re
turns
(
Promise
.
resolve
([
.
onSecondCall
().
re
solves
([
{
userId
:
42
,
taskId
:
15
},
{
userId
:
42
,
taskId
:
15
},
{
userId
:
42
,
taskId
:
16
}
{
userId
:
42
,
taskId
:
16
}
])
)
;
]);
return
user
.
setTasks
([
task1
,
task2
]).
then
(()
=>
{
return
user
.
setTasks
([
task1
,
task2
]).
then
(()
=>
{
this
.
update
.
resetHistory
();
this
.
update
.
resetHistory
();
...
@@ -145,10 +145,10 @@ describe(Support.getTestDialectTeaser('hasMany'), () => {
...
@@ -145,10 +145,10 @@ describe(Support.getTestDialectTeaser('hasMany'), () => {
foreignKey
=
'user_id'
;
foreignKey
=
'user_id'
;
it
(
'should fetch associations for a single instance'
,
()
=>
{
it
(
'should fetch associations for a single instance'
,
()
=>
{
const
findAll
=
stub
(
Task
,
'findAll'
).
re
turns
(
Promise
.
resolve
([
const
findAll
=
stub
(
Task
,
'findAll'
).
re
solves
([
Task
.
build
({}),
Task
.
build
({}),
Task
.
build
({})
Task
.
build
({})
])
)
;
]);
User
.
Tasks
=
User
.
hasMany
(
Task
,
{
foreignKey
});
User
.
Tasks
=
User
.
hasMany
(
Task
,
{
foreignKey
});
const
actual
=
User
.
Tasks
.
get
(
User
.
build
({
id
:
idA
}));
const
actual
=
User
.
Tasks
.
get
(
User
.
build
({
id
:
idA
}));
...
...
test/unit/connection-manager.test.js
View file @
1e7e410
...
@@ -4,32 +4,25 @@ const chai = require('chai'),
...
@@ -4,32 +4,25 @@ const chai = require('chai'),
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Support
=
require
(
'./support'
),
Support
=
require
(
'./support'
),
Sequelize
=
require
(
'../../index'
),
ConnectionManager
=
require
(
'../../lib/dialects/abstract/connection-manager'
);
ConnectionManager
=
require
(
'../../lib/dialects/abstract/connection-manager'
),
Promise
=
Sequelize
.
Promise
;
describe
(
'connection manager'
,
()
=>
{
describe
(
'connection manager'
,
()
=>
{
describe
(
'_connect'
,
()
=>
{
describe
(
'_connect'
,
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
sinon
=
sinon
.
createSandbox
();
this
.
connection
=
{};
this
.
connection
=
{};
this
.
dialect
=
{
this
.
dialect
=
{
connectionManager
:
{
connectionManager
:
{
connect
:
this
.
sinon
.
stub
().
returns
(
Promise
.
resolve
(
this
.
connection
)
)
connect
:
sinon
.
stub
().
resolves
(
this
.
connection
)
}
}
};
};
this
.
sequelize
=
Support
.
createSequelizeInstance
();
this
.
sequelize
=
Support
.
createSequelizeInstance
();
});
});
afterEach
(
function
()
{
this
.
sinon
.
restore
();
});
it
(
'should resolve connection on dialect connection manager'
,
function
()
{
it
(
'should resolve connection on dialect connection manager'
,
function
()
{
const
connection
=
{};
const
connection
=
{};
this
.
dialect
.
connectionManager
.
connect
.
re
turns
(
Promise
.
resolve
(
connection
)
);
this
.
dialect
.
connectionManager
.
connect
.
re
solves
(
connection
);
const
connectionManager
=
new
ConnectionManager
(
this
.
dialect
,
this
.
sequelize
);
const
connectionManager
=
new
ConnectionManager
(
this
.
dialect
,
this
.
sequelize
);
...
...
test/unit/dialects/mssql/query.test.js
View file @
1e7e410
...
@@ -23,9 +23,7 @@ if (dialect === 'mssql') {
...
@@ -23,9 +23,7 @@ if (dialect === 'mssql') {
isolationLevel
:
'REPEATABLE_READ'
,
isolationLevel
:
'REPEATABLE_READ'
,
logging
:
false
logging
:
false
};
};
sandbox
.
stub
(
connectionStub
,
'beginTransaction'
).
callsFake
(
cb
=>
{
sandbox
.
stub
(
connectionStub
,
'beginTransaction'
).
callsArg
(
0
);
cb
();
});
query
=
new
Query
(
connectionStub
,
sequelize
,
options
);
query
=
new
Query
(
connectionStub
,
sequelize
,
options
);
});
});
...
...
test/unit/hooks.test.js
View file @
1e7e410
...
@@ -35,10 +35,10 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
...
@@ -35,10 +35,10 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
describe
(
'proxies'
,
()
=>
{
describe
(
'proxies'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
sinon
.
stub
(
current
,
'query'
).
re
turns
(
Promise
.
resolve
([{
sinon
.
stub
(
current
,
'query'
).
re
solves
([{
_previousDataValues
:
{},
_previousDataValues
:
{},
dataValues
:
{
id
:
1
,
name
:
'abc'
}
dataValues
:
{
id
:
1
,
name
:
'abc'
}
}])
)
;
}]);
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
...
test/unit/instance-validator.test.js
View file @
1e7e410
...
@@ -5,7 +5,6 @@ const expect = chai.expect;
...
@@ -5,7 +5,6 @@ const expect = chai.expect;
const
Support
=
require
(
'./support'
);
const
Support
=
require
(
'./support'
);
const
InstanceValidator
=
require
(
'../../lib/instance-validator'
);
const
InstanceValidator
=
require
(
'../../lib/instance-validator'
);
const
sinon
=
require
(
'sinon'
);
const
sinon
=
require
(
'sinon'
);
const
Promise
=
Support
.
Sequelize
.
Promise
;
const
SequelizeValidationError
=
require
(
'../../lib/errors'
).
ValidationError
;
const
SequelizeValidationError
=
require
(
'../../lib/errors'
).
ValidationError
;
describe
(
Support
.
getTestDialectTeaser
(
'InstanceValidator'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'InstanceValidator'
),
()
=>
{
...
@@ -84,7 +83,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -84,7 +83,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
describe
(
'_validateAndRunHooks'
,
()
=>
{
describe
(
'_validateAndRunHooks'
,
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
successfulInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
this
.
successfulInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
sinon
.
stub
(
this
.
successfulInstanceValidator
,
'_validate'
).
re
turns
(
Promise
.
resolve
()
);
sinon
.
stub
(
this
.
successfulInstanceValidator
,
'_validate'
).
re
solves
(
);
});
});
it
(
'should run beforeValidate and afterValidate hooks when _validate is successful'
,
function
()
{
it
(
'should run beforeValidate and afterValidate hooks when _validate is successful'
,
function
()
{
...
@@ -101,9 +100,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -101,9 +100,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
it
(
'should run beforeValidate hook but not afterValidate hook when _validate is unsuccessful'
,
function
()
{
it
(
'should run beforeValidate hook but not afterValidate hook when _validate is unsuccessful'
,
function
()
{
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
callsFake
(()
=>
{
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
rejects
(
new
Error
());
return
Promise
.
reject
(
new
Error
());
});
const
beforeValidate
=
sinon
.
spy
();
const
beforeValidate
=
sinon
.
spy
();
const
afterValidate
=
sinon
.
spy
();
const
afterValidate
=
sinon
.
spy
();
this
.
User
.
beforeValidate
(
beforeValidate
);
this
.
User
.
beforeValidate
(
beforeValidate
);
...
@@ -126,9 +123,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -126,9 +123,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
describe
(
'validatedFailed hook'
,
()
=>
{
describe
(
'validatedFailed hook'
,
()
=>
{
it
(
'should call validationFailed hook when validation fails'
,
function
()
{
it
(
'should call validationFailed hook when validation fails'
,
function
()
{
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
callsFake
(()
=>
{
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
rejects
(
new
Error
());
return
Promise
.
reject
(
new
Error
());
});
const
validationFailedHook
=
sinon
.
spy
();
const
validationFailedHook
=
sinon
.
spy
();
this
.
User
.
validationFailed
(
validationFailedHook
);
this
.
User
.
validationFailed
(
validationFailedHook
);
...
@@ -139,10 +134,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -139,10 +134,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
it
(
'should not replace the validation error in validationFailed hook by default'
,
function
()
{
it
(
'should not replace the validation error in validationFailed hook by default'
,
function
()
{
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
callsFake
(()
=>
{
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
rejects
(
new
SequelizeValidationError
());
return
Promise
.
reject
(
new
SequelizeValidationError
());
const
validationFailedHook
=
sinon
.
stub
().
resolves
();
});
const
validationFailedHook
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
this
.
User
.
validationFailed
(
validationFailedHook
);
this
.
User
.
validationFailed
(
validationFailedHook
);
return
expect
(
failingInstanceValidator
.
_validateAndRunHooks
()).
to
.
be
.
rejected
.
then
(
err
=>
{
return
expect
(
failingInstanceValidator
.
_validateAndRunHooks
()).
to
.
be
.
rejected
.
then
(
err
=>
{
...
@@ -152,9 +145,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -152,9 +145,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
it
(
'should replace the validation error if validationFailed hook creates a new error'
,
function
()
{
it
(
'should replace the validation error if validationFailed hook creates a new error'
,
function
()
{
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
const
failingInstanceValidator
=
new
InstanceValidator
(
this
.
User
.
build
());
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
callsFake
(()
=>
{
sinon
.
stub
(
failingInstanceValidator
,
'_validate'
).
rejects
(
new
SequelizeValidationError
());
return
Promise
.
reject
(
new
SequelizeValidationError
());
});
const
validationFailedHook
=
sinon
.
stub
().
throws
(
new
Error
(
'validation failed hook error'
));
const
validationFailedHook
=
sinon
.
stub
().
throws
(
new
Error
(
'validation failed hook error'
));
this
.
User
.
validationFailed
(
validationFailedHook
);
this
.
User
.
validationFailed
(
validationFailedHook
);
...
...
test/unit/instance/decrement.test.js
View file @
1e7e410
...
@@ -20,11 +20,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -20,11 +20,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
before
(()
=>
{
before
(()
=>
{
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turn
s
(
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solve
s
(
Sequelize
.
Promise
.
resolve
(
{
{
_previousDataValues
:
{
id
:
3
},
_previousDataValues
:
{
id
:
3
},
dataValues
:
{
id
:
1
}
dataValues
:
{
id
:
1
}
}
)
}
);
);
});
});
...
...
test/unit/instance/destroy.test.js
View file @
1e7e410
...
@@ -20,11 +20,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -20,11 +20,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
before
(()
=>
{
before
(()
=>
{
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turn
s
(
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solve
s
(
Sequelize
.
Promise
.
resolve
(
{
{
_previousDataValues
:
{},
_previousDataValues
:
{},
dataValues
:
{
id
:
1
}
dataValues
:
{
id
:
1
}
}
)
}
);
);
});
});
...
...
test/unit/instance/increment.test.js
View file @
1e7e410
...
@@ -20,11 +20,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -20,11 +20,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
before
(()
=>
{
before
(()
=>
{
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turn
s
(
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solve
s
(
Sequelize
.
Promise
.
resolve
(
{
{
_previousDataValues
:
{
id
:
1
},
_previousDataValues
:
{
id
:
1
},
dataValues
:
{
id
:
3
}
dataValues
:
{
id
:
3
}
}
)
}
);
);
});
});
...
...
test/unit/instance/reload.test.js
View file @
1e7e410
...
@@ -25,11 +25,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -25,11 +25,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
before
(()
=>
{
before
(()
=>
{
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turn
s
(
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solve
s
(
Sequelize
.
Promise
.
resolve
(
{
{
_previousDataValues
:
{
id
:
1
},
_previousDataValues
:
{
id
:
1
},
dataValues
:
{
id
:
2
}
dataValues
:
{
id
:
2
}
}
)
}
);
);
});
});
...
...
test/unit/instance/restore.test.js
View file @
1e7e410
...
@@ -25,11 +25,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -25,11 +25,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
before
(()
=>
{
before
(()
=>
{
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turn
s
(
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solve
s
(
Sequelize
.
Promise
.
resolve
(
[{
[{
_previousDataValues
:
{
id
:
1
},
_previousDataValues
:
{
id
:
1
},
dataValues
:
{
id
:
2
}
dataValues
:
{
id
:
2
}
},
1
]
)
},
1
]
);
);
});
});
...
...
test/unit/instance/save.test.js
View file @
1e7e410
...
@@ -31,11 +31,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -31,11 +31,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
before
(()
=>
{
before
(()
=>
{
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turn
s
(
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solve
s
(
Sequelize
.
Promise
.
resolve
(
[{
[{
_previousDataValues
:
{},
_previousDataValues
:
{},
dataValues
:
{
id
:
1
}
dataValues
:
{
id
:
1
}
},
1
]
)
},
1
]
);
);
});
});
...
...
test/unit/model/bulkcreate.test.js
View file @
1e7e410
...
@@ -4,8 +4,6 @@ const chai = require('chai'),
...
@@ -4,8 +4,6 @@ const chai = require('chai'),
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
Sequelize
=
require
(
'../../../index'
),
Promise
=
Sequelize
.
Promise
,
DataTypes
=
require
(
'../../../lib/data-types'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
current
=
Support
.
sequelize
;
current
=
Support
.
sequelize
;
...
@@ -20,7 +18,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -20,7 +18,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}
}
},
{
timestamps
:
false
});
},
{
timestamps
:
false
});
this
.
stub
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkInsert'
).
re
turns
(
Promise
.
resolve
([])
);
this
.
stub
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkInsert'
).
re
solves
([]
);
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
...
...
test/unit/model/count.test.js
View file @
1e7e410
...
@@ -6,8 +6,7 @@ const chai = require('chai'),
...
@@ -6,8 +6,7 @@ const chai = require('chai'),
Sequelize
=
Support
.
Sequelize
,
Sequelize
=
Support
.
Sequelize
,
current
=
Support
.
sequelize
,
current
=
Support
.
sequelize
,
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
DataTypes
=
require
(
'../../../lib/data-types'
);
Promise
=
require
(
'bluebird'
);
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
'method count'
,
()
=>
{
describe
(
'method count'
,
()
=>
{
...
@@ -15,7 +14,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -15,7 +14,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this
.
oldFindAll
=
Sequelize
.
Model
.
findAll
;
this
.
oldFindAll
=
Sequelize
.
Model
.
findAll
;
this
.
oldAggregate
=
Sequelize
.
Model
.
aggregate
;
this
.
oldAggregate
=
Sequelize
.
Model
.
aggregate
;
Sequelize
.
Model
.
findAll
=
sinon
.
stub
().
re
turns
(
Promise
.
resolve
()
);
Sequelize
.
Model
.
findAll
=
sinon
.
stub
().
re
solves
(
);
this
.
User
=
current
.
define
(
'User'
,
{
this
.
User
=
current
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
...
@@ -35,7 +34,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -35,7 +34,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
stub
=
Sequelize
.
Model
.
aggregate
=
sinon
.
stub
().
re
turns
(
Promise
.
resolve
()
);
this
.
stub
=
Sequelize
.
Model
.
aggregate
=
sinon
.
stub
().
re
solves
(
);
});
});
describe
(
'should pass the same options to model.aggregate as findAndCountAll'
,
()
=>
{
describe
(
'should pass the same options to model.aggregate as findAndCountAll'
,
()
=>
{
...
...
test/unit/model/destroy.test.js
View file @
1e7e410
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
const
chai
=
require
(
'chai'
),
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Sequelize
=
require
(
'../../../index'
),
Promise
=
Sequelize
.
Promise
,
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
current
=
Support
.
sequelize
,
current
=
Support
.
sequelize
,
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
...
@@ -19,9 +17,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -19,9 +17,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
before
(
function
()
{
before
(
function
()
{
this
.
stubDelete
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkDelete'
).
callsFake
(()
=>
{
this
.
stubDelete
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkDelete'
).
resolves
([]);
return
Promise
.
resolve
([]);
});
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
...
...
test/unit/model/find-and-count-all.test.js
View file @
1e7e410
...
@@ -23,13 +23,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -23,13 +23,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
age
:
DataTypes
.
INTEGER
age
:
DataTypes
.
INTEGER
});
});
this
.
findAll
=
sinon
.
stub
(
this
.
User
,
'findAll'
).
callsFake
(()
=>
{
this
.
findAll
=
sinon
.
stub
(
this
.
User
,
'findAll'
).
rejects
(
new
Error
());
return
Promise
.
reject
(
new
Error
());
});
this
.
count
=
sinon
.
stub
(
this
.
User
,
'count'
).
callsFake
(()
=>
{
this
.
count
=
sinon
.
stub
(
this
.
User
,
'count'
).
rejects
(
new
Error
());
return
Promise
.
reject
(
new
Error
());
});
});
});
after
(
function
()
{
after
(
function
()
{
...
...
test/unit/model/find-create-find.test.js
View file @
1e7e410
...
@@ -14,6 +14,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -14,6 +14,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
sinon
=
sinon
.
createSandbox
();
this
.
sinon
=
sinon
.
createSandbox
();
this
.
sinon
.
usingPromise
(
Promise
);
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
...
@@ -23,7 +24,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -23,7 +24,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it
(
'should return the result of the first find call if not empty'
,
function
()
{
it
(
'should return the result of the first find call if not empty'
,
function
()
{
const
result
=
{},
const
result
=
{},
where
=
{
prop
:
Math
.
random
().
toString
()
},
where
=
{
prop
:
Math
.
random
().
toString
()
},
findSpy
=
this
.
sinon
.
stub
(
Model
,
'findOne'
).
re
turns
(
Promise
.
resolve
(
result
)
);
findSpy
=
this
.
sinon
.
stub
(
Model
,
'findOne'
).
re
solves
(
result
);
return
expect
(
Model
.
findCreateFind
({
return
expect
(
Model
.
findCreateFind
({
where
where
...
@@ -36,9 +37,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -36,9 +37,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
it
(
'should create if first find call is empty'
,
function
()
{
it
(
'should create if first find call is empty'
,
function
()
{
const
result
=
{},
const
result
=
{},
where
=
{
prop
:
Math
.
random
().
toString
()
},
where
=
{
prop
:
Math
.
random
().
toString
()
},
createSpy
=
this
.
sinon
.
stub
(
Model
,
'create'
).
re
turns
(
Promise
.
resolve
(
result
)
);
createSpy
=
this
.
sinon
.
stub
(
Model
,
'create'
).
re
solves
(
result
);
this
.
sinon
.
stub
(
Model
,
'findOne'
).
re
turns
(
Promise
.
resolve
(
null
)
);
this
.
sinon
.
stub
(
Model
,
'findOne'
).
re
solves
(
null
);
return
expect
(
Model
.
findCreateFind
({
return
expect
(
Model
.
findCreateFind
({
where
where
...
@@ -52,12 +53,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -52,12 +53,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
where
=
{
prop
:
Math
.
random
().
toString
()
},
where
=
{
prop
:
Math
.
random
().
toString
()
},
findSpy
=
this
.
sinon
.
stub
(
Model
,
'findOne'
);
findSpy
=
this
.
sinon
.
stub
(
Model
,
'findOne'
);
this
.
sinon
.
stub
(
Model
,
'create'
).
callsFake
(()
=>
{
this
.
sinon
.
stub
(
Model
,
'create'
).
rejects
(
new
UniqueConstraintError
());
return
Promise
.
reject
(
new
UniqueConstraintError
());
});
findSpy
.
onFirstCall
().
re
turns
(
Promise
.
resolve
(
null
)
);
findSpy
.
onFirstCall
().
re
solves
(
null
);
findSpy
.
onSecondCall
().
re
turns
(
Promise
.
resolve
(
result
)
);
findSpy
.
onSecondCall
().
re
solves
(
result
);
return
expect
(
Model
.
findCreateFind
({
return
expect
(
Model
.
findCreateFind
({
where
where
...
...
test/unit/model/find-or-create.test.js
View file @
1e7e410
...
@@ -6,8 +6,7 @@ const chai = require('chai'),
...
@@ -6,8 +6,7 @@ const chai = require('chai'),
current
=
Support
.
sequelize
,
current
=
Support
.
sequelize
,
cls
=
require
(
'continuation-local-storage'
),
cls
=
require
(
'continuation-local-storage'
),
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
stub
=
sinon
.
stub
,
stub
=
sinon
.
stub
;
Promise
=
require
(
'bluebird'
);
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
...
@@ -26,11 +25,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -26,11 +25,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
name
:
'John'
name
:
'John'
});
});
this
.
transactionStub
=
stub
(
this
.
User
.
sequelize
,
'transaction'
);
this
.
transactionStub
=
stub
(
this
.
User
.
sequelize
,
'transaction'
).
rejects
(
new
Error
(
'abort'
));
this
.
transactionStub
.
returns
(
new
Promise
(()
=>
{}));
this
.
clsStub
=
stub
(
current
.
constructor
.
_cls
,
'get'
);
this
.
clsStub
=
stub
(
current
.
constructor
.
_cls
,
'get'
).
returns
({
id
:
123
});
this
.
clsStub
.
returns
({
id
:
123
});
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
...
@@ -46,9 +43,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -46,9 +43,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}
}
};
};
this
.
User
.
findOrCreate
(
options
);
return
this
.
User
.
findOrCreate
(
options
)
.
then
(()
=>
{
expect
.
fail
(
'expected to fail'
);
})
.
catch
(
/abort/
,
()
=>
{
expect
(
this
.
clsStub
.
calledOnce
).
to
.
equal
(
true
,
'expected to ask for transaction'
);
});
expect
(
this
.
clsStub
.
calledOnce
).
to
.
equal
(
true
,
'expected to ask for transaction'
);
});
});
it
(
'should not use transaction from cls if provided as argument'
,
function
()
{
it
(
'should not use transaction from cls if provided as argument'
,
function
()
{
...
@@ -60,9 +62,13 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -60,9 +62,13 @@ describe(Support.getTestDialectTeaser('Model'), () => {
transaction
:
{
id
:
123
}
transaction
:
{
id
:
123
}
};
};
this
.
User
.
findOrCreate
(
options
);
return
this
.
User
.
findOrCreate
(
options
)
.
then
(()
=>
{
expect
(
this
.
clsStub
.
called
).
to
.
equal
(
false
);
expect
.
fail
(
'expected to fail'
);
})
.
catch
(
/abort/
,
()
=>
{
expect
(
this
.
clsStub
.
called
).
to
.
equal
(
false
);
});
});
});
});
});
});
});
test/unit/model/findall.test.js
View file @
1e7e410
...
@@ -45,9 +45,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -45,9 +45,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
{
timestamps
:
false
});
},
{
timestamps
:
false
});
before
(
function
()
{
before
(
function
()
{
this
.
stub
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'select'
).
callsFake
(()
=>
{
this
.
stub
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'select'
).
callsFake
(()
=>
Model
.
build
({}));
return
Model
.
build
({});
});
this
.
warnOnInvalidOptionsStub
=
sinon
.
stub
(
Model
,
'warnOnInvalidOptions'
);
this
.
warnOnInvalidOptionsStub
=
sinon
.
stub
(
Model
,
'warnOnInvalidOptions'
);
});
});
...
...
test/unit/model/findone.test.js
View file @
1e7e410
...
@@ -5,7 +5,6 @@ const chai = require('chai'),
...
@@ -5,7 +5,6 @@ const chai = require('chai'),
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
Sequelize
=
Support
.
Sequelize
,
Sequelize
=
Support
.
Sequelize
,
Op
=
Sequelize
.
Op
,
Op
=
Sequelize
.
Op
,
Promise
=
Sequelize
.
Promise
,
current
=
Support
.
sequelize
,
current
=
Support
.
sequelize
,
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
DataTypes
=
require
(
'../../../lib/data-types'
);
DataTypes
=
require
(
'../../../lib/data-types'
);
...
@@ -20,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -20,7 +19,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
stub
=
Sequelize
.
Model
.
findAll
=
sinon
.
stub
().
re
turns
(
Promise
.
resolve
()
);
this
.
stub
=
Sequelize
.
Model
.
findAll
=
sinon
.
stub
().
re
solves
(
);
});
});
describe
(
'should not add limit when querying on a primary key'
,
()
=>
{
describe
(
'should not add limit when querying on a primary key'
,
()
=>
{
...
...
test/unit/model/update.test.js
View file @
1e7e410
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
const
chai
=
require
(
'chai'
),
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Sequelize
=
require
(
'../../../index'
),
Promise
=
Sequelize
.
Promise
,
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
current
=
Support
.
sequelize
,
current
=
Support
.
sequelize
,
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
...
@@ -20,7 +18,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -20,7 +18,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
stubUpdate
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkUpdate'
).
re
turns
(
Promise
.
resolve
([])
);
this
.
stubUpdate
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'bulkUpdate'
).
re
solves
([]
);
this
.
updates
=
{
name
:
'Batman'
,
secretValue
:
'7'
};
this
.
updates
=
{
name
:
'Batman'
,
secretValue
:
'7'
};
this
.
cloneUpdates
=
_
.
clone
(
this
.
updates
);
this
.
cloneUpdates
=
_
.
clone
(
this
.
updates
);
});
});
...
...
test/unit/model/upsert.test.js
View file @
1e7e410
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
const
chai
=
require
(
'chai'
),
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Sequelize
=
require
(
'../../../index'
),
Sequelize
=
require
(
'../../../index'
),
Promise
=
Sequelize
.
Promise
,
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
current
=
Support
.
sequelize
,
current
=
Support
.
sequelize
,
sinon
=
require
(
'sinon'
),
sinon
=
require
(
'sinon'
),
...
@@ -43,14 +42,13 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -43,14 +42,13 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
sinon
=
sinon
.
createSandbox
();
this
.
query
=
sinon
.
stub
(
current
,
'query'
).
resolves
();
this
.
stub
=
sinon
.
stub
(
current
.
getQueryInterface
(),
'upsert'
).
resolves
([
true
,
undefined
]);
this
.
query
=
this
.
sinon
.
stub
(
current
,
'query'
).
returns
(
Promise
.
resolve
());
this
.
stub
=
this
.
sinon
.
stub
(
current
.
getQueryInterface
(),
'upsert'
).
returns
(
Promise
.
resolve
([
true
,
undefined
]));
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
this
.
sinon
.
restore
();
this
.
query
.
restore
();
this
.
stub
.
restore
();
});
});
it
(
'skip validations for missing fields'
,
function
()
{
it
(
'skip validations for missing fields'
,
function
()
{
...
...
test/unit/model/validation.test.js
View file @
1e7e410
...
@@ -273,11 +273,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -273,11 +273,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
before
(
function
()
{
before
(
function
()
{
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
callsFake
(()
=>
{
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
callsFake
(()
=>
new
Promise
.
resolve
([
User
.
build
({}),
1
]));
return
new
Promise
(
resolve
=>
{
resolve
([
User
.
build
({}),
1
]);
});
});
});
});
after
(
function
()
{
after
(
function
()
{
...
@@ -484,7 +480,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -484,7 +480,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
before
(
function
()
{
before
(
function
()
{
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turns
(
Promise
.
resolve
([
User
.
build
(),
1
])
);
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solves
([
User
.
build
(),
1
]
);
});
});
after
(
function
()
{
after
(
function
()
{
...
@@ -559,7 +555,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -559,7 +555,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
before
(
function
()
{
before
(
function
()
{
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turns
(
Promise
.
resolve
([
User
.
build
(),
1
])
);
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solves
([
User
.
build
(),
1
]
);
});
});
after
(
function
()
{
after
(
function
()
{
...
@@ -628,7 +624,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -628,7 +624,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}
}
});
});
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turns
(
Promise
.
resolve
([
this
.
User
.
build
(),
1
])
);
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solves
([
this
.
User
.
build
(),
1
]
);
});
});
after
(
function
()
{
after
(
function
()
{
...
@@ -697,7 +693,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -697,7 +693,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
}
}
});
});
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turns
(
Promise
.
resolve
([
this
.
User
.
build
(),
1
])
);
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solves
([
this
.
User
.
build
(),
1
]
);
});
});
after
(
function
()
{
after
(
function
()
{
...
...
test/unit/sql/change-column.test.js
View file @
1e7e410
'use strict'
;
'use strict'
;
const
sinon
=
require
(
'sinon'
),
const
sinon
=
require
(
'sinon'
),
Sequelize
=
require
(
'../../../index'
),
Promise
=
Sequelize
.
Promise
,
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
expectsql
=
Support
.
expectsql
,
expectsql
=
Support
.
expectsql
,
...
@@ -24,10 +22,7 @@ if (current.dialect.name !== 'sqlite') {
...
@@ -24,10 +22,7 @@ if (current.dialect.name !== 'sqlite') {
},
{
timestamps
:
false
});
},
{
timestamps
:
false
});
before
(
function
()
{
before
(
function
()
{
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
resolvesArg
(
0
);
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
callsFake
(
sql
=>
{
return
Promise
.
resolve
(
sql
);
});
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
...
...
test/unit/transaction.test.js
View file @
1e7e410
...
@@ -10,16 +10,16 @@ const current = Support.sequelize;
...
@@ -10,16 +10,16 @@ const current = Support.sequelize;
describe
(
'Transaction'
,
()
=>
{
describe
(
'Transaction'
,
()
=>
{
before
(
function
()
{
before
(
function
()
{
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
turns
(
Sequelize
.
Promise
.
resolve
({})
);
this
.
stub
=
sinon
.
stub
(
current
,
'query'
).
re
solves
({}
);
this
.
stubConnection
=
sinon
.
stub
(
current
.
connectionManager
,
'getConnection'
)
this
.
stubConnection
=
sinon
.
stub
(
current
.
connectionManager
,
'getConnection'
)
.
re
turns
(
Sequelize
.
Promise
.
resolve
({
.
re
solves
({
uuid
:
'ssfdjd-434fd-43dfg23-2d'
,
uuid
:
'ssfdjd-434fd-43dfg23-2d'
,
close
()
{}
close
()
{}
})
)
;
});
this
.
stubRelease
=
sinon
.
stub
(
current
.
connectionManager
,
'releaseConnection'
)
this
.
stubRelease
=
sinon
.
stub
(
current
.
connectionManager
,
'releaseConnection'
)
.
re
turns
(
Sequelize
.
Promise
.
resolve
()
);
.
re
solves
(
);
});
});
beforeEach
(
function
()
{
beforeEach
(
function
()
{
...
...
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