From c631a315037d463952573bbdf66a7d40421b104e Mon Sep 17 00:00:00 2001 From: ciaranj Date: Tue, 24 Apr 2012 21:40:24 +0100 Subject: [PATCH] Adding a test for the refresh_token grant type support --- tests/oauth2.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/oauth2.js b/tests/oauth2.js index 1799d11..4eb47cd 100644 --- a/tests/oauth2.js +++ b/tests/oauth2.js @@ -3,8 +3,9 @@ var vows = require('vows'), OAuth2= require('../lib/oauth2').OAuth2; vows.describe('OAuth2').addBatch({ - 'When handling the access token response': { - topic: new OAuth2(), + 'Given an OAuth2 instance, ': { + topic: new OAuth2(), + 'When handling the access token response': { 'we should correctly extract the token if received as form-data': function (oa) { oa._request= function( method, url, fo, bar, bleh, callback) { callback(null, "access_token=access&refresh_token=refresh"); @@ -35,5 +36,32 @@ vows.describe('OAuth2').addBatch({ assert.equal( results.extra_2, "foo"); }); } + }, + 'When no grant_type parameter is specified': { + 'we should pass the value of the code argument as the code parameter': function(oa) { + oa._request= function(method, url, headers, post_body, access_token, callback) { + assert.isTrue( post_body.indexOf("code=xsds23") != -1 ) + } + oa.getOAuthAccessToken("xsds23", {} ); + } + }, + 'When an invalid grant_type parameter is specified': { + 'we should pass the value of the code argument as the code parameter': function(oa) { + oa._request= function(method, url, headers, post_body, access_token, callback) { + assert.isTrue( post_body.indexOf("code=xsds23") != -1 ) + } + oa.getOAuthAccessToken("xsds23", {grant_type:"refresh_toucan"} ); + } + }, + 'When a grant_type parameter of value "refresh_token" is specified': { + 'we should pass the value of the code argument as the refresh_token parameter, should pass a grant_type parameter, but shouldn\'t pass a code parameter' : function(oa) { + oa._request= function(method, url, headers, post_body, access_token, callback) { + assert.isTrue( post_body.indexOf("refresh_token=sdsds2") != -1 ) + assert.isTrue( post_body.indexOf("grant_type=refresh_token") != -1 ) + assert.isTrue( post_body.indexOf("code=") == -1 ) + } + oa.getOAuthAccessToken("sdsds2", {grant_type:"refresh_token"} ); + } + } } }).export(module); \ No newline at end of file