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 b33ff7c7
authored
Mar 03, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert tests to promises
1 parent
793ee3f4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
122 deletions
test/integration/include/find.test.js
test/integration/include/findAndCountAll.test.js
test/integration/include/paranoid.test.js
test/integration/include/find.test.js
View file @
b33ff7c
...
...
@@ -4,6 +4,7 @@ var chai = require('chai')
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
Sequelize
=
require
(
__dirname
+
'/../../../index'
)
,
Promise
=
Sequelize
.
Promise
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
,
datetime
=
require
(
'chai-datetime'
)
,
async
=
require
(
'async'
);
...
...
@@ -13,7 +14,7 @@ chai.config.includeStack = true;
describe
(
Support
.
getTestDialectTeaser
(
'Include'
),
function
()
{
describe
(
'find'
,
function
()
{
it
(
'should include a non required model, with conditions and two includes N:M 1:M'
,
function
(
done
)
{
it
(
'should include a non required model, with conditions and two includes N:M 1:M'
,
function
(
)
{
var
A
=
this
.
sequelize
.
define
(
'A'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
})
,
B
=
this
.
sequelize
.
define
(
'B'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
})
,
C
=
this
.
sequelize
.
define
(
'C'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
})
...
...
@@ -33,19 +34,14 @@ describe(Support.getTestDialectTeaser('Include'), function() {
D
.
hasMany
(
B
);
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
A
.
find
({
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
A
.
find
({
include
:
[
{
model
:
B
,
required
:
false
,
include
:
[
{
model
:
C
,
required
:
false
},
{
model
:
D
}
]}
]
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
done
();
});
});
});
...
...
@@ -178,7 +174,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
});
});
it
(
'should support many levels of belongsTo (with a lower level having a where)'
,
function
(
done
)
{
it
(
'should support many levels of belongsTo (with a lower level having a where)'
,
function
()
{
var
A
=
this
.
sequelize
.
define
(
'a'
,
{})
,
B
=
this
.
sequelize
.
define
(
'b'
,
{})
,
C
=
this
.
sequelize
.
define
(
'c'
,
{})
...
...
@@ -200,49 +196,44 @@ describe(Support.getTestDialectTeaser('Include'), function() {
F
.
belongsTo
(
G
);
G
.
belongsTo
(
H
);
var
b
,
singles
=
[
B
,
C
,
D
,
E
,
F
,
G
,
H
];
this
.
sequelize
.
sync
().
done
(
function
()
{
async
.
auto
({
a
:
function
(
callback
)
{
A
.
create
({}).
done
(
callback
);
},
singleChain
:
function
(
callback
)
{
var
previousInstance
;
async
.
eachSeries
(
singles
,
function
(
model
,
callback
)
{
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Promise
.
join
(
A
.
create
({}),
(
function
(
singles
)
{
var
promise
=
Promise
.
resolve
()
,
previousInstance
,
b
;
singles
.
forEach
(
function
(
model
)
{
var
values
=
{};
if
(
model
.
name
===
'g'
)
{
values
.
name
=
'yolo'
;
}
model
.
create
(
values
).
done
(
function
(
err
,
instance
)
{
promise
=
promise
.
then
(
function
()
{
return
model
.
create
(
values
).
then
(
function
(
instance
)
{
if
(
previousInstance
)
{
previousInstance
[
'set'
+
Sequelize
.
Utils
.
uppercaseFirst
(
model
.
name
)](
instance
).
done
(
function
()
{
return
previousInstance
[
'set'
+
Sequelize
.
Utils
.
uppercaseFirst
(
model
.
name
)](
instance
).
then
(
function
()
{
previousInstance
=
instance
;
callback
();
});
}
else
{
previousInstance
=
b
=
instance
;
callback
();
}
});
},
callback
);
},
ab
:
[
'a'
,
'singleChain'
,
function
(
callback
,
results
)
{
results
.
a
.
setB
(
b
).
done
(
callback
);
}]
},
function
()
{
}
);
});
promise
=
promise
.
then
(
function
()
{
return
b
;
});
A
.
find
({
return
promise
;
})([
B
,
C
,
D
,
E
,
F
,
G
,
H
])
).
spread
(
function
(
a
,
b
)
{
return
a
.
setB
(
b
);
}).
then
(
function
()
{
return
A
.
find
({
include
:
[
{
model
:
B
,
include
:
[
{
model
:
C
,
include
:
[
...
...
@@ -260,10 +251,8 @@ describe(Support.getTestDialectTeaser('Include'), function() {
]}
]}
]
}).
done
(
function
(
err
,
a
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
}).
then
(
function
(
a
)
{
expect
(
a
.
b
.
c
.
d
.
e
.
f
.
g
.
h
).
to
.
be
.
ok
;
done
();
});
});
});
...
...
test/integration/include/findAndCountAll.test.js
View file @
b33ff7c
...
...
@@ -12,19 +12,16 @@ chai.config.includeStack = true;
describe
(
Support
.
getTestDialectTeaser
(
'Include'
),
function
()
{
describe
(
'findAndCountAll'
,
function
()
{
it
(
'Try to include a required model. Result rows should match count'
,
function
(
done
)
{
var
DT
=
DataTypes
,
S
=
this
.
sequelize
,
User
=
S
.
define
(
'User'
,
{
name
:
DT
.
STRING
(
40
)
},
{
paranoid
:
true
}),
SomeConnection
=
S
.
define
(
'SomeConnection'
,
{
m
:
DT
.
STRING
(
40
),
fk
:
DT
.
INTEGER
,
u
:
DT
.
INTEGER
it
(
'should be able to include a required model. Result rows should match count'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
}),
SomeConnection
=
this
.
sequelize
.
define
(
'SomeConnection'
,
{
m
:
DataTypes
.
STRING
(
40
),
fk
:
DataTypes
.
INTEGER
,
u
:
DataTypes
.
INTEGER
},
{
paranoid
:
true
}),
A
=
S
.
define
(
'A'
,
{
name
:
DT
.
STRING
(
40
)
},
{
paranoid
:
true
}),
B
=
S
.
define
(
'B'
,
{
name
:
DT
.
STRING
(
40
)
},
{
paranoid
:
true
}),
C
=
S
.
define
(
'C'
,
{
name
:
DT
.
STRING
(
40
)
},
{
paranoid
:
true
});
A
=
this
.
sequelize
.
define
(
'A'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
}),
B
=
this
.
sequelize
.
define
(
'B'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
}),
C
=
this
.
sequelize
.
define
(
'C'
,
{
name
:
DataTypes
.
STRING
(
40
)
},
{
paranoid
:
true
});
// Associate them
User
.
hasMany
(
SomeConnection
,
{
foreignKey
:
'u'
});
...
...
@@ -39,17 +36,17 @@ describe(Support.getTestDialectTeaser('Include'), function() {
C
.
hasMany
(
SomeConnection
,
{
foreignKey
:
'fk'
,
constraints
:
false
});
// Sync them
S
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
// Create an enviroment
return
Promise
.
join
(
User
.
bulkCreate
([
{
name
:
'Youtube'
},
{
name
:
'Facebook'
},
{
name
:
'Google'
},
{
name
:
'Yahoo'
},
{
name
:
'404'
}
]).
done
(
function
(
err
,
users
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
users
).
to
.
be
.
length
(
5
);
]),
SomeConnection
.
bulkCreate
([
// Lets count, m: A and u: 1
{
u
:
1
,
m
:
'A'
,
fk
:
1
},
// 1 // Will be deleted
{
u
:
2
,
m
:
'A'
,
fk
:
1
},
...
...
@@ -75,35 +72,31 @@ describe(Support.getTestDialectTeaser('Include'), function() {
{
u
:
2
,
m
:
'B'
,
fk
:
2
},
{
u
:
1
,
m
:
'A'
,
fk
:
4
},
// 4
{
u
:
4
,
m
:
'A'
,
fk
:
2
}
]).
done
(
function
(
err
,
conns
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
conns
).
to
.
be
.
length
(
24
);
]),
A
.
bulkCreate
([
{
name
:
'Just'
},
{
name
:
'for'
},
{
name
:
'testing'
},
{
name
:
'proposes'
},
{
name
:
'only'
}
]).
done
(
function
(
err
,
as
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
as
).
to
.
be
.
length
(
5
);
]),
B
.
bulkCreate
([
{
name
:
'this should not'
},
{
name
:
'be loaded'
}
]).
done
(
function
(
err
,
bs
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
bs
).
to
.
be
.
length
(
2
);
]),
C
.
bulkCreate
([
{
name
:
'because we only want A'
}
]).
done
(
function
(
err
,
cs
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
cs
).
to
.
be
.
length
(
1
);
])
).
then
(
function
()
{
// Delete some of conns to prove the concept
SomeConnection
.
destroy
({
where
:
{
return
SomeConnection
.
destroy
({
where
:
{
m
:
'A'
,
u
:
1
,
fk
:
[
1
,
2
]
}}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
}}).
then
(
function
()
{
// Last and most important queries ( we connected 4, but deleted 2, witch means we must get 2 only )
A
.
findAndCountAll
({
return
A
.
findAndCountAll
({
include
:
[{
model
:
SomeConnection
,
required
:
true
,
where
:
{
...
...
@@ -111,36 +104,15 @@ describe(Support.getTestDialectTeaser('Include'), function() {
u
:
1
}
}],
limit
:
5
})
.
done
(
function
(
err
,
result
)
{
// Test variables
expect
(
err
).
not
.
to
.
be
.
ok
;
}).
then
(
function
(
result
)
{
expect
(
result
.
count
).
to
.
be
.
equal
(
2
);
expect
(
result
.
rows
.
length
).
to
.
be
.
equal
(
2
);
done
();
// Last and most important queries - END
});
// Delete some of conns to prove the concept - END
});
// Create an enviroment - END
});
});
});
});
});
// Sync them - END
});
});
it
(
'should count on a where and not use an uneeded include'
,
function
()
{
var
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
...
...
test/integration/include/paranoid.test.js
View file @
b33ff7c
...
...
@@ -11,7 +11,7 @@ chai.config.includeStack = true;
describe
(
Support
.
getTestDialectTeaser
(
'Paranoid'
),
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
)
{
var
S
=
this
.
sequelize
,
DT
=
DataTypes
,
...
...
@@ -32,34 +32,24 @@ describe(Support.getTestDialectTeaser('Paranoid'), function() {
D
.
hasMany
(
A
);
S
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
done
();
return
S
.
sync
({
force
:
true
});
});
});
it
(
'paranoid with timestamps: false should be ignored / not crash'
,
function
(
done
)
{
var
S
=
this
.
sequelize
,
Test
=
S
.
define
(
'Test'
,
{
it
(
'paranoid with timestamps: false should be ignored / not crash'
,
function
()
{
var
S
=
this
.
sequelize
,
Test
=
S
.
define
(
'Test'
,
{
name
:
DataTypes
.
STRING
},{
timestamps
:
false
,
paranoid
:
true
});
S
.
sync
({
force
:
true
}).
done
(
function
()
{
Test
.
find
(
1
).
done
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
not
.
ok
;
done
();
});
return
S
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Test
.
find
(
1
);
});
});
it
(
'test if non required is marked as false'
,
function
(
done
)
{
it
(
'test if non required is marked as false'
,
function
(
)
{
var
A
=
this
.
A
,
B
=
this
.
B
,
options
=
{
...
...
@@ -71,17 +61,12 @@ describe(Support.getTestDialectTeaser('Paranoid'), function() {
]
};
A
.
find
(
options
).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
return
A
.
find
(
options
).
then
(
function
()
{
expect
(
options
.
include
[
0
].
required
).
to
.
be
.
equal
(
false
);
done
();
});
});
it
(
'test if required is marked as true'
,
function
(
done
)
{
it
(
'test if required is marked as true'
,
function
(
)
{
var
A
=
this
.
A
,
B
=
this
.
B
,
options
=
{
...
...
@@ -93,13 +78,9 @@ describe(Support.getTestDialectTeaser('Paranoid'), function() {
]
};
A
.
find
(
options
).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
return
A
.
find
(
options
).
then
(
function
()
{
expect
(
options
.
include
[
0
].
required
).
to
.
be
.
equal
(
true
);
done
();
});
});
it
(
'should not load paranoid, destroyed instances, with a non-paranoid parent'
,
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