Skip to content

Commit

Permalink
Add tests to POST /token
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin01 committed Oct 8, 2014
1 parent 21bb447 commit 3701b81
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/handlers/token/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require('should');
var request = require('supertest');
var async = require('async');
var rarity = require('rarity');

var AnyFetchProvider = require('../../../lib/');
var Token = require('../../../lib/models/token.js');
Expand All @@ -11,6 +13,59 @@ var connectFunctions = helpers.connectFunctions;
var updateAccount = helpers.updateAccount;
var config = helpers.config;

describe('POST /token endpoint', function() {
var token = {
access_token: 'fake_token',
data: {
foo: 'bar'
},
cursor: new Date(),
account_name: 'fake.test@anyfetch.com',
last_update: new Date(2020, 2, 2),
is_updating: true
};

before(AnyFetchProvider.debug.cleanTokens);

it("should require access_token parameter", function(done) {
var server = AnyFetchProvider.createServer(connectFunctions, updateAccount, {}, config);

request(server)
.post('/token')
.expect(409)
.expect(/access_token/i)
.end(done);
});

it("should save the new token", function(done) {
var server = AnyFetchProvider.createServer(connectFunctions, updateAccount, {}, config);

async.waterfall([
function sendToken(cb) {
request(server)
.post('/token')
.send(token)
.expect(204)
.end(rarity.slice(1, cb));
},
function findToken(cb) {
Token.findOne({anyfetchToken: token.access_token}, cb);
},
function checkToken(newToken, cb) {
newToken.should.have.property('anyfetchToken', token.access_token);
newToken.should.have.property('data', token.data);
newToken.should.have.property('cursor', token.cursor.toISOString());
newToken.should.have.property('accountName', token.account_name);
newToken.should.have.property('lastUpdate', token.last_update);
newToken.should.have.property('isUpdating', token.is_updating);

cb(null);
}
], done)
});

//Token.findOne({anyfetchToken: token.anyfetchToken}
});

describe('DELETE /token endpoint', function() {
var token;
Expand Down

0 comments on commit 3701b81

Please sign in to comment.