55 */
66
77var Request = require ( '../../../lib/request' ) ;
8+ var Response = require ( '../../../lib/response' ) ;
89var TokenHandler = require ( '../../../lib/handlers/token-handler' ) ;
910var sinon = require ( 'sinon' ) ;
1011var should = require ( 'should' ) ;
@@ -14,6 +15,42 @@ var should = require('should');
1415 */
1516
1617describe ( 'TokenHandler' , function ( ) {
18+ describe ( 'handle()' , function ( ) {
19+ it ( 'should extend model object with request context' , function ( ) {
20+ var model = {
21+ getClient : sinon . stub ( ) . returns ( { grants : [ 'client_credentials' ] } ) ,
22+ getUserFromClient : sinon . stub ( ) . returns ( { } ) ,
23+ saveToken : sinon . stub ( ) . returns ( {
24+ accessToken : '123' ,
25+ client : { } ,
26+ user : { } ,
27+ accessTokenExpiresAt : new Date ( new Date ( ) . getTime ( ) + 10000 ) ,
28+ refreshTokenExpiresAt : new Date ( new Date ( ) . getTime ( ) + 10000 )
29+ } ) ,
30+ } ;
31+
32+ var handler = new TokenHandler ( {
33+ accessTokenLifetime : 123 ,
34+ refreshTokenLifetime : 123 ,
35+ model : model ,
36+ } ) ;
37+
38+ var request = new Request ( {
39+ method : 'POST' ,
40+ body : { 'grant_type' : 'client_credentials' , 'client_id' : 'abc' , 'client_secret' : 'xyz' } ,
41+ headers : { 'content-type' : 'application/x-www-form-urlencoded' , 'transfer-encoding' : 'chunked' } ,
42+ query : { }
43+ } ) ;
44+ var response = new Response ( { } ) ;
45+
46+ return handler . handle ( request , response )
47+ . then ( function ( ) {
48+ model . request . should . equal ( request ) ;
49+ } )
50+ . catch ( should . fail ) ;
51+ } ) ;
52+ } ) ;
53+
1754 describe ( 'getClient()' , function ( ) {
1855 it ( 'should call `model.getClient()`' , function ( ) {
1956 var model = {
0 commit comments