forked from MarceloBorgesP/railsblocks-api-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.js
27 lines (24 loc) · 739 Bytes
/
hooks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var hooks = require('hooks');
var before = hooks.before;
var after = hooks.after;
var responseStash = {};
hooks.afterEach(function (transaction, done) {
if(transaction.request.method == "POST")
{
var resource = transaction.request.uri.match(/([a-z]+)/);
var id = JSON.parse(transaction.real.body)['id'];
responseStash[resource[0]] = {}
responseStash[resource[0]]['id'] = id;
}
done();
});
hooks.beforeEach(function (transaction, done) {
if(transaction.request.method != "POST")
{
var resource = transaction.request.uri.match(/([a-z]+)/);
var resourceId = responseStash[resource[0]]['id'];
var url = transaction.fullPath;
transaction.fullPath = url.replace('42', resourceId);
}
done();
});