@@ -9,6 +9,7 @@ var Response = require('oauth2-server').Response;
99var express = require ( 'express' ) ;
1010var request = require ( 'supertest' ) ;
1111var sinon = require ( 'sinon' ) ;
12+ var should = require ( 'should' ) ;
1213
1314/**
1415 * Test `ExpressOAuthServer`.
@@ -33,9 +34,31 @@ describe('ExpressOAuthServer', function() {
3334 . get ( '/' )
3435 . end ( function ( ) {
3536 oauth . server . authenticate . callCount . should . equal ( 1 ) ;
36- oauth . server . authenticate . firstCall . args . should . have . length ( 2 ) ;
37+ oauth . server . authenticate . firstCall . args . should . have . length ( 3 ) ;
3738 oauth . server . authenticate . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
3839 oauth . server . authenticate . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
40+ should . not . exist ( oauth . server . authenticate . firstCall . args [ 2 ] )
41+ oauth . server . authenticate . restore ( ) ;
42+
43+ done ( ) ;
44+ } ) ;
45+ } ) ;
46+
47+ it ( 'should call `authenticate()` with options' , function ( done ) {
48+ var oauth = new ExpressOAuthServer ( { model : { } } ) ;
49+
50+ sinon . stub ( oauth . server , 'authenticate' ) . returns ( { } ) ;
51+
52+ app . use ( oauth . authenticate ( { options : true } ) ) ;
53+
54+ request ( app . listen ( ) )
55+ . get ( '/' )
56+ . end ( function ( ) {
57+ oauth . server . authenticate . callCount . should . equal ( 1 ) ;
58+ oauth . server . authenticate . firstCall . args . should . have . length ( 3 ) ;
59+ oauth . server . authenticate . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
60+ oauth . server . authenticate . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
61+ oauth . server . authenticate . firstCall . args [ 2 ] . should . eql ( { options : true } ) ;
3962 oauth . server . authenticate . restore ( ) ;
4063
4164 done ( ) ;
@@ -55,9 +78,31 @@ describe('ExpressOAuthServer', function() {
5578 . get ( '/' )
5679 . end ( function ( ) {
5780 oauth . server . authorize . callCount . should . equal ( 1 ) ;
58- oauth . server . authorize . firstCall . args . should . have . length ( 2 ) ;
81+ oauth . server . authorize . firstCall . args . should . have . length ( 3 ) ;
5982 oauth . server . authorize . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
6083 oauth . server . authorize . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
84+ should . not . exist ( oauth . server . authorize . firstCall . args [ 2 ] ) ;
85+ oauth . server . authorize . restore ( ) ;
86+
87+ done ( ) ;
88+ } ) ;
89+ } ) ;
90+
91+ it ( 'should call `authorize()` with options' , function ( done ) {
92+ var oauth = new ExpressOAuthServer ( { model : { } } ) ;
93+
94+ sinon . stub ( oauth . server , 'authorize' ) . returns ( { } ) ;
95+
96+ app . use ( oauth . authorize ( { options : true } ) ) ;
97+
98+ request ( app . listen ( ) )
99+ . get ( '/' )
100+ . end ( function ( ) {
101+ oauth . server . authorize . callCount . should . equal ( 1 ) ;
102+ oauth . server . authorize . firstCall . args . should . have . length ( 3 ) ;
103+ oauth . server . authorize . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
104+ oauth . server . authorize . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
105+ oauth . server . authorize . firstCall . args [ 2 ] . should . eql ( { options : true } ) ;
61106 oauth . server . authorize . restore ( ) ;
62107
63108 done ( ) ;
@@ -77,9 +122,31 @@ describe('ExpressOAuthServer', function() {
77122 . get ( '/' )
78123 . end ( function ( ) {
79124 oauth . server . token . callCount . should . equal ( 1 ) ;
80- oauth . server . token . firstCall . args . should . have . length ( 2 ) ;
125+ oauth . server . token . firstCall . args . should . have . length ( 3 ) ;
126+ oauth . server . token . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
127+ oauth . server . token . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
128+ should . not . exist ( oauth . server . token . firstCall . args [ 2 ] ) ;
129+ oauth . server . token . restore ( ) ;
130+
131+ done ( ) ;
132+ } ) ;
133+ } ) ;
134+
135+ it ( 'should call `token()` with options' , function ( done ) {
136+ var oauth = new ExpressOAuthServer ( { model : { } } ) ;
137+
138+ sinon . stub ( oauth . server , 'token' ) . returns ( { } ) ;
139+
140+ app . use ( oauth . token ( { options : true } ) ) ;
141+
142+ request ( app . listen ( ) )
143+ . get ( '/' )
144+ . end ( function ( ) {
145+ oauth . server . token . callCount . should . equal ( 1 ) ;
146+ oauth . server . token . firstCall . args . should . have . length ( 3 ) ;
81147 oauth . server . token . firstCall . args [ 0 ] . should . be . an . instanceOf ( Request ) ;
82148 oauth . server . token . firstCall . args [ 1 ] . should . be . an . instanceOf ( Response ) ;
149+ oauth . server . token . firstCall . args [ 2 ] . should . eql ( { options : true } ) ;
83150 oauth . server . token . restore ( ) ;
84151
85152 done ( ) ;
0 commit comments