Permalink
Browse files

addresses #3 started creating unit tests for emitting events. created…

… test describing how provider inherits from eventemitter
  • Loading branch information...
1 parent 7acc5ed commit d23debdd269a774f7ad5abfe1b94358029668176 @oveddan oveddan committed Sep 25, 2012
Showing with 60 additions and 2 deletions.
  1. +4 −0 makefile
  2. +7 −2 package.json
  3. +49 −0 test/OAuth2Provider_tests.js
View
@@ -0,0 +1,4 @@
+test:
+ @./node_modules/.bin/mocha -u bdd -R spec
+
+.PHONY: test testintegration
View
@@ -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": {
@@ -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": [
{
@@ -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.