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 bb3a6245
authored
Mar 16, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests
1 parent
ccff8989
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
153 deletions
test/integration/include/findAll.test.js
test/integration/sequelize.test.js
test/integration/sequelize.transaction.test.js
test/integration/include/findAll.test.js
View file @
bb3a624
...
...
@@ -7,7 +7,8 @@ var chai = require('chai')
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
,
datetime
=
require
(
'chai-datetime'
)
,
async
=
require
(
'async'
)
,
Promise
=
Sequelize
.
Promise
;
,
Promise
=
Sequelize
.
Promise
,
_
=
require
(
'lodash'
);
chai
.
use
(
datetime
);
chai
.
config
.
includeStack
=
true
;
...
...
@@ -122,106 +123,79 @@ describe(Support.getTestDialectTeaser('Include'), function() {
return
Tag
.
findAll
();
})
}).
then
(
function
(
results
)
{
var
count
=
4
,
i
=
-
1
,
groups
=
results
.
groups
var
groups
=
results
.
groups
,
ranks
=
results
.
ranks
,
tags
=
results
.
tags
,
companies
=
results
.
companies
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
async
.
whilst
(
function
()
{
return
i
<
count
;
},
function
(
callback
)
{
i
++
;
async
.
auto
({
user
:
function
(
callback
)
{
User
.
create
().
nodeify
(
callback
);
},
memberships
:
[
'user'
,
function
(
callback
,
results
)
{
var
groupMembers
=
[
{
AccUserId
:
results
.
user
.
id
,
GroupId
:
groups
[
0
].
id
,
RankId
:
ranks
[
0
].
id
},
{
AccUserId
:
results
.
user
.
id
,
GroupId
:
groups
[
1
].
id
,
RankId
:
ranks
[
2
].
id
}
];
if
(
i
<
3
)
{
groupMembers
.
push
({
AccUserId
:
results
.
user
.
id
,
GroupId
:
groups
[
2
].
id
,
RankId
:
ranks
[
1
].
id
});
}
GroupMember
.
bulkCreate
(
groupMembers
).
nodeify
(
callback
);
}],
products
:
function
(
callback
)
{
Product
.
bulkCreate
([
{
title
:
'Chair'
},
{
title
:
'Desk'
},
{
title
:
'Bed'
},
{
title
:
'Pen'
},
{
title
:
'Monitor'
}
]).
done
(
function
(
err
)
{
if
(
err
)
return
callback
(
err
);
Product
.
findAll
().
nodeify
(
callback
);
});
},
userProducts
:
[
'user'
,
'products'
,
function
(
callback
,
results
)
{
results
.
user
.
setProducts
([
results
.
products
[(
i
*
5
)
+
0
],
results
.
products
[(
i
*
5
)
+
1
],
results
.
products
[(
i
*
5
)
+
3
]
]).
nodeify
(
callback
);
}],
productTags
:
[
'products'
,
function
(
callback
,
results
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
();
chainer
.
add
(
results
.
products
[(
i
*
5
)
+
0
].
setTags
([
tags
[
0
],
tags
[
2
]
]));
chainer
.
add
(
results
.
products
[(
i
*
5
)
+
1
].
setTags
([
tags
[
1
]
]));
chainer
.
add
(
results
.
products
[(
i
*
5
)
+
0
].
setCategory
(
tags
[
1
]));
chainer
.
add
(
results
.
products
[(
i
*
5
)
+
2
].
setTags
([
tags
[
0
]
]));
chainer
.
add
(
results
.
products
[(
i
*
5
)
+
3
].
setTags
([
tags
[
0
]
]));
chainer
.
run
().
done
(
callback
);
}],
companies
:
[
'products'
,
function
(
callback
,
results
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
();
results
.
products
[(
i
*
5
)
+
0
].
setCompany
(
companies
[
4
]);
results
.
products
[(
i
*
5
)
+
1
].
setCompany
(
companies
[
3
]);
results
.
products
[(
i
*
5
)
+
2
].
setCompany
(
companies
[
2
]);
results
.
products
[(
i
*
5
)
+
3
].
setCompany
(
companies
[
1
]);
results
.
products
[(
i
*
5
)
+
4
].
setCompany
(
companies
[
0
]);
chainer
.
run
().
done
(
callback
);
}],
prices
:
[
'products'
,
function
(
callback
,
results
)
{
Price
.
bulkCreate
([
{
ProductId
:
results
.
products
[(
i
*
5
)
+
0
].
id
,
value
:
5
},
{
ProductId
:
results
.
products
[(
i
*
5
)
+
0
].
id
,
value
:
10
},
{
ProductId
:
results
.
products
[(
i
*
5
)
+
1
].
id
,
value
:
5
},
{
ProductId
:
results
.
products
[(
i
*
5
)
+
1
].
id
,
value
:
10
},
{
ProductId
:
results
.
products
[(
i
*
5
)
+
1
].
id
,
value
:
15
},
{
ProductId
:
results
.
products
[(
i
*
5
)
+
1
].
id
,
value
:
20
},
{
ProductId
:
results
.
products
[(
i
*
5
)
+
2
].
id
,
value
:
20
},
{
ProductId
:
results
.
products
[(
i
*
5
)
+
3
].
id
,
value
:
20
}
]).
nodeify
(
callback
);
}]
},
callback
);
},
function
(
err
)
{
if
(
err
)
return
reject
(
err
);
resolve
();
return
Promise
.
reduce
(
_
.
range
(
5
),
function
(
memo
,
i
)
{
return
Promise
.
props
({
user
:
User
.
create
(),
products
:
Product
.
bulkCreate
([
{
title
:
'Chair'
},
{
title
:
'Desk'
},
{
title
:
'Bed'
},
{
title
:
'Pen'
},
{
title
:
'Monitor'
}
]).
then
(
function
(
err
)
{
return
Product
.
findAll
();
})
}).
then
(
function
(
results
)
{
var
user
=
results
.
user
,
products
=
results
.
products
,
groupMembers
;
groupMembers
=
[
{
AccUserId
:
user
.
id
,
GroupId
:
groups
[
0
].
id
,
RankId
:
ranks
[
0
].
id
},
{
AccUserId
:
user
.
id
,
GroupId
:
groups
[
1
].
id
,
RankId
:
ranks
[
2
].
id
}
];
if
(
i
<
3
)
{
groupMembers
.
push
({
AccUserId
:
user
.
id
,
GroupId
:
groups
[
2
].
id
,
RankId
:
ranks
[
1
].
id
});
}
);
});
return
Promise
.
join
(
GroupMember
.
bulkCreate
(
groupMembers
),
user
.
setProducts
([
products
[(
i
*
5
)
+
0
],
products
[(
i
*
5
)
+
1
],
products
[(
i
*
5
)
+
3
]
]),
Promise
.
join
(
products
[(
i
*
5
)
+
0
].
setTags
([
tags
[
0
],
tags
[
2
]
]),
products
[(
i
*
5
)
+
1
].
setTags
([
tags
[
1
]
]),
products
[(
i
*
5
)
+
0
].
setCategory
(
tags
[
1
]),
products
[(
i
*
5
)
+
2
].
setTags
([
tags
[
0
]
]),
products
[(
i
*
5
)
+
3
].
setTags
([
tags
[
0
]
])
),
Promise
.
join
(
products
[(
i
*
5
)
+
0
].
setCompany
(
companies
[
4
]),
products
[(
i
*
5
)
+
1
].
setCompany
(
companies
[
3
]),
products
[(
i
*
5
)
+
2
].
setCompany
(
companies
[
2
]),
products
[(
i
*
5
)
+
3
].
setCompany
(
companies
[
1
]),
products
[(
i
*
5
)
+
4
].
setCompany
(
companies
[
0
])
),
Price
.
bulkCreate
([
{
ProductId
:
products
[(
i
*
5
)
+
0
].
id
,
value
:
5
},
{
ProductId
:
products
[(
i
*
5
)
+
0
].
id
,
value
:
10
},
{
ProductId
:
products
[(
i
*
5
)
+
1
].
id
,
value
:
5
},
{
ProductId
:
products
[(
i
*
5
)
+
1
].
id
,
value
:
10
},
{
ProductId
:
products
[(
i
*
5
)
+
1
].
id
,
value
:
15
},
{
ProductId
:
products
[(
i
*
5
)
+
1
].
id
,
value
:
20
},
{
ProductId
:
products
[(
i
*
5
)
+
2
].
id
,
value
:
20
},
{
ProductId
:
products
[(
i
*
5
)
+
3
].
id
,
value
:
20
}
])
);
});
},
[]);
});
});
};
...
...
test/integration/sequelize.test.js
View file @
bb3a624
...
...
@@ -114,6 +114,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
.
sequelizeWithInvalidConnection
.
authenticate
()
.
complete
(
function
(
err
,
result
)
{
console
.
log
(
err
.
message
);
expect
(
err
.
message
.
match
(
/connect ECONNREFUSED/
)
||
err
.
message
.
match
(
/invalid port number/
)
||
...
...
test/integration/sequelize.transaction.test.js
View file @
bb3a624
...
...
@@ -10,21 +10,33 @@ var chai = require('chai')
if
(
current
.
dialect
.
supports
.
transactions
)
{
describe
(
Support
.
getTestDialectTeaser
(
'Sequelize#transaction'
),
function
()
{
this
.
timeout
(
4000
);
describe
(
'success'
,
function
()
{
it
(
'gets triggered once a transaction has been successfully committed'
,
function
(
done
)
{
this
describe
(
'then'
,
function
()
{
it
(
'gets triggered once a transaction has been successfully committed'
,
function
()
{
var
called
=
false
;
return
this
.
sequelize
.
transaction
().
then
(
function
(
t
)
{
t
.
commit
();
})
.
success
(
function
()
{
done
();
});
.
transaction
().
then
(
function
(
t
)
{
return
t
.
commit
().
then
(
function
()
{
called
=
1
;
});
})
.
then
(
function
()
{
expect
(
called
).
to
.
be
.
ok
;
});
});
it
(
'gets triggered once a transaction has been successfully rolled back'
,
function
(
done
)
{
this
it
(
'gets triggered once a transaction has been successfully rolled back'
,
function
()
{
var
called
=
false
;
return
this
.
sequelize
.
transaction
().
then
(
function
(
t
)
{
t
.
rollback
();
})
.
success
(
function
()
{
done
();
});
.
transaction
().
then
(
function
(
t
)
{
return
t
.
rollback
().
then
(
function
()
{
called
=
1
;
});
})
.
then
(
function
()
{
expect
(
called
).
to
.
be
.
ok
;
});
});
if
(
Support
.
getTestDialect
()
!==
'sqlite'
)
{
...
...
@@ -71,65 +83,42 @@ describe(Support.getTestDialectTeaser('Sequelize#transaction'), function() {
}
});
describe
(
'error'
,
function
()
{
if
(
Support
.
getTestDialect
()
===
'sqlite'
)
{
// not sure if we can test this in sqlite ...
// how could we enforce an authentication error in sqlite?
}
else
{
it
(
'gets triggered once an error occurs'
,
function
(
done
)
{
// Supply bad config to force an error
var
sequelize
=
Support
.
getSequelizeInstance
(
'this'
,
'is'
,
'fake config'
);
sequelize
.
transaction
().
then
(
function
()
{})
.
catch
(
function
(
err
)
{
expect
(
err
).
to
.
not
.
be
.
undefined
;
done
();
});
});
}
});
describe
(
'complex long running example'
,
function
()
{
it
(
'works with promise syntax'
,
function
(
done
)
{
Support
.
prepareTransactionTest
(
this
.
sequelize
,
function
(
sequelize
)
{
it
(
'works with promise syntax'
,
function
()
{
return
Support
.
prepareTransactionTest
(
this
.
sequelize
).
then
(
function
(
sequelize
)
{
var
Test
=
sequelize
.
define
(
'Test'
,
{
id
:
{
type
:
Support
.
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
name
:
{
type
:
Support
.
Sequelize
.
STRING
}
});
sequelize
.
sync
({
force
:
true
})
.
then
(
function
()
{
sequelize
.
transaction
().
then
(
function
(
transaction
)
{
expect
(
transaction
).
to
.
be
.
instanceOf
(
Transaction
);
Test
.
create
({
name
:
'Peter'
},
{
transaction
:
transaction
})
.
then
(
function
()
{
setTimeout
(
function
()
{
transaction
.
commit
()
.
then
(
function
()
{
return
Test
.
count
();
})
.
then
(
function
(
count
)
{
expect
(
count
).
to
.
equal
(
1
);
done
();
});
},
1000
);
return
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
sequelize
.
transaction
().
then
(
function
(
transaction
)
{
expect
(
transaction
).
to
.
be
.
instanceOf
(
Transaction
);
return
Test
.
create
({
name
:
'Peter'
},
{
transaction
:
transaction
})
.
then
(
function
()
{
return
Promise
.
delay
(
1000
).
then
(
function
()
{
return
transaction
.
commit
()
.
then
(
function
()
{
return
Test
.
count
();
})
.
then
(
function
(
count
)
{
expect
(
count
).
to
.
equal
(
1
);
});
});
});
});
});
});
});
});
});
describe
(
'concurrency'
,
function
()
{
describe
(
'having tables with uniqueness constraints'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
var
self
=
this
;
Support
.
prepareTransactionTest
(
this
.
sequelize
,
function
(
sequelize
)
{
return
Support
.
prepareTransactionTest
(
this
.
sequelize
).
then
(
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
;
self
.
Model
=
sequelize
.
define
(
'Model'
,
{
...
...
@@ -138,9 +127,7 @@ describe(Support.getTestDialectTeaser('Sequelize#transaction'), function() {
timestamps
:
false
});
self
.
Model
.
sync
({
force
:
true
})
.
success
(
function
()
{
done
();
});
return
self
.
Model
.
sync
({
force
:
true
});
});
});
...
...
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