forked from GoogleCloudPlatform/google-cloud-node-todos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e96715f
commit 77fd19c
Showing
6 changed files
with
105 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,54 @@ | ||
'use strict'; | ||
|
||
var request = require('request'); | ||
// imports the hooks module _injected_ by dredd. | ||
var hooks = require('hooks'); | ||
var todos = require('../todos.js'); | ||
|
||
hooks.after('Todos > Todos Collection > Archive done Todos', function(transaction, done) { | ||
todos.getAll(function(err, items) { | ||
items.forEach(function(todo) { | ||
console.assert(!todo.done); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
|
||
hooks.before('Todos > Todo > Get a Todo', function(transaction, done) { | ||
request.post({ | ||
uri: 'http://localhost:8080/todos', | ||
json: {'text': 'do that'} | ||
}, function(err, res, todo) { | ||
todos.insert({ | ||
text: 'do that' | ||
}, function(err, todo) { | ||
transaction.fullPath = '/todos/' + todo.id; | ||
return done(); | ||
done(); | ||
}); | ||
}); | ||
|
||
hooks.before('Todos > Todo > Delete a Todo', function(transaction, done) { | ||
request.post({ | ||
uri: 'http://localhost:8080/todos', | ||
json: {'text': 'delete me'} | ||
}, function(err, res, todo) { | ||
todos.insert({ | ||
text: 'delete me' | ||
}, function(err, todo) { | ||
transaction.fullPath = '/todos/' + todo.id; | ||
return done(); | ||
done(); | ||
}); | ||
}); | ||
|
||
hooks.after('Todos > Todo > Delete a Todo', function(transaction, done) { | ||
request.get({ | ||
uri: 'http://localhost:8080' + transaction.fullPath, | ||
}, function(err, res) { | ||
console.assert(res.statusCode === 404); | ||
return done(); | ||
var id = transaction.fullPath.split('/')[1]; | ||
todos.get(id, function(err) { | ||
console.assert(err.code === 404); | ||
done(); | ||
}); | ||
}); | ||
|
||
hooks.after('Todos > Todos Collection > Archive done Todos', function(transaction, done) { | ||
request.get({ | ||
uri: 'http://localhost:8080/todos' | ||
}, function(err, res, body) { | ||
JSON.parse(body).forEach(function(todo) { | ||
console.assert(!todo.done); | ||
hooks.afterAll(function(done) { | ||
todos.getAll(function(err, items) { | ||
var deleted = 0; | ||
|
||
items.forEach(function(todo) { | ||
todos.delete(todo.id, function() { | ||
if (++deleted === items.length) { | ||
done(); | ||
} | ||
}); | ||
}); | ||
return done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters