Skip to content

Commit

Permalink
addresses ammmir#3 started creating unit tests for emitting events. c…
Browse files Browse the repository at this point in the history
…reated test describing how provider inherits from eventemitter
  • Loading branch information
oveddan committed Sep 25, 2012
1 parent 7acc5ed commit d23debd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test:
@./node_modules/.bin/mocha -u bdd -R spec

.PHONY: test testintegration
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oauth2-provider",
"version": "1.1.0",
"version": "1.1.1",
"description": "A simple customizable OAuth 2.0 provider (server) for node.js.",
"homepage": "https://github.com/ammmir/node-oauth2-provider",
"author": {
Expand All @@ -9,7 +9,12 @@
},
"main": "index",
"dependencies": {
"serializer": ">=0.0.2 <0.1.0"
"serializer": ">=0.0.2 <0.1.0",
},
"devDependencies": {
"mocha" : "1.0.3"
,"sinon" : "1.3.4"
,"chai" : "1.0.3"
},
"licenses": [
{
Expand Down
49 changes: 49 additions & 0 deletions test/OAuth2Provider_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var sinon = require('sinon'),
should = require('chai').should,
serializer = require('serializer');

describe('OAuth2Provider', function(){
it('should inherit from EventEmitter', function(){
// rneeds to be in here since static constructor depends on creating
// secure serializer
var oAuth2Provider = createOauth2Provider();

oAuth2Provider.should.be.a('EventEmitter');
});

describe('login', function(){
beforeEach(function(){
// stub returned serializer so that can mock it

this.createSerializerStub = sinon.stub(serializer, 'createSecureSerializer');
this.emitterStub = sinon.stub('EventEmitter'),
this.oAuth2Provider = createOauth2Provider();
});
afterEach(function(){
this.createSerializerStub.restore();
this.emitterStub.restore();
});
var accessTokenKey = 'access_token';
// for backwards compatibility
it('should emit access_token if it can be parsed from request', function(done){
oAuth2Provider.login();
});
it('should write error to response if cannot parse access token', function(done){

});
});

// utility methods
var createOauth2Provider = function(crypt_key, sign_key){
var crypt_key = crypt_key || '123131',
sign_key = sign_key || 'asdfasdfas';

sinon.stub()

// requiring this needs module needs to be done repeatedly, since it depends on a static serializer
// factory in its static constructuro, which needs to be stubbed by many of the methods
var OAuth2Provider = require('../index'),
oAuth2Provider = new OAuth2Provider(crypt_key, sign_key);
return oAuth2Provider;
};
});

0 comments on commit d23debd

Please sign in to comment.