Navigation Menu

Skip to content

Commit

Permalink
test: extract common code to keep only important thing in test function
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 30, 2014
1 parent 6bd5f4b commit b829fb1
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions test/adapter/api/groonga/load.test.js
Expand Up @@ -311,28 +311,37 @@ suite('adapter/api/groonga: load', function() {
});

suite('GET', function() {
test('object style', function(done) {
function get(values) {
var requestBody;
backend.reserveResponse(function(requestPacket) {
requestBody = requestPacket[2].body;
return utils.createReplyPacket(requestPacket, successMessage);
});
var values = [
{
_key: 'alice',
name: 'Alice',
age: 20
}
];

var path = {
pathname: '/d/load',
query: {
table: 'Users',
values: JSON.stringify(values)
}
};
utils.get(path)

return utils.get(path)
.next(function(response) {
return requestBody;
});
};

test('object style', function(done) {
var values = [
{
_key: 'alice',
name: 'Alice',
age: 20
}
];
get(values)
.next(function(requestBody) {
assert.deepEqual(requestBody,
{
table: 'Users',
Expand All @@ -350,11 +359,6 @@ suite('adapter/api/groonga: load', function() {
});

test('array style', function(done) {
var requestBody;
backend.reserveResponse(function(requestPacket) {
requestBody = requestPacket[2].body;
return utils.createReplyPacket(requestPacket, successMessage);
});
var values = [
[
'_key',
Expand All @@ -367,15 +371,8 @@ suite('adapter/api/groonga: load', function() {
20
]
];
var path = {
pathname: '/d/load',
query: {
table: 'Users',
values: JSON.stringify(values)
}
};
utils.get(path)
.next(function(response) {
get(values)
.next(function(requestBody) {
assert.deepEqual(requestBody,
{
table: 'Users',
Expand Down

0 comments on commit b829fb1

Please sign in to comment.