So superagent's .expect
is great and convenient for basic cases with expected values, but don't be afraid to write your own expectation code for more advanced cases such as this.
var before = new Date().valueOf();
request.post('/v1/authorizations')
//all your existing .expect() calls can remain here
.end(function(error, res) {
var createdTimestamp = new Date(res.body.data[0].createdTimestamp).valueOf();
var delta = createdTimestamp - before;
assert(delta > 0 && delta < 5000);
done()
});
For the token, just assert that it exists, and it a string that matches a regex.