Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
ADD profile unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
palmerabollo committed Oct 3, 2015
1 parent 0c78cd7 commit 5a7e6c7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"coveralls": "^2.11.2",
"istanbul": "^0.3.16",
"mocha": "^2.2.5",
"nock": "^2.13.0",
"proxyquire": "^1.5.0",
"should": "^7.0.1",
"sinon": "~1.15.3",
Expand Down
43 changes: 42 additions & 1 deletion test/unit/taccounts-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
var events = require('events'),
util = require('util'),
sinon = require('sinon'),
nock = require('nock'),
OAuth2Strategy = require('passport-oauth2'),
TAccountsStrategy = require('../../lib');

describe('TAccounts Tests', function() {
describe('TAccounts basic tests', function() {
it('should create a TAccounts object', function(done) {
expect(TAccountsStrategy.prototype instanceof OAuth2Strategy).to.be.true;
done();
Expand Down Expand Up @@ -43,3 +44,43 @@ describe('TAccounts Tests', function() {
done();
});
});

describe('TAccounts user profile', function() {
it('should request the user profile', function(done) {
var options = {
clientID: '2b8672be-5c80-ac91-96da-f4b922105431',
clientSecret: 'f5d689ac-fc2c-4e32-ac8a-321212ca1a8d'
};
function verify() {};

var strategy = new TAccountsStrategy(options, verify);

var fakeProfile = {foo: 'bar'};
nock(options.profileURL).get('').reply(200, fakeProfile);

strategy.userProfile('faketoken', function(err, profile) {
expect(err).to.not.exist;
expect(profile).to.be.deep.equal(fakeProfile);
done();
});
});

it('should throw an error if it can get the profile', function(done) {
var options = {
clientID: '2b8672be-5c80-ac91-96da-f4b922105431',
clientSecret: 'f5d689ac-fc2c-4e32-ac8a-321212ca1a8d'
};
function verify() {};

var strategy = new TAccountsStrategy(options, verify);

var fakeProfile = {foo: 'bar'};
nock(options.profileURL).get('').reply(500);

strategy.userProfile('faketoken', function(err, profile) {
expect(err).to.be.instanceof(Error);
expect(profile).to.not.exist;
done();
});
});
});

0 comments on commit 5a7e6c7

Please sign in to comment.