5
5
*/
6
6
7
7
var Request = require ( '../../../lib/request' ) ;
8
+ var Response = require ( '../../../lib/response' ) ;
8
9
var TokenHandler = require ( '../../../lib/handlers/token-handler' ) ;
9
10
var sinon = require ( 'sinon' ) ;
10
11
var should = require ( 'should' ) ;
@@ -14,6 +15,42 @@ var should = require('should');
14
15
*/
15
16
16
17
describe ( '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
+
17
54
describe ( 'getClient()' , function ( ) {
18
55
it ( 'should call `model.getClient()`' , function ( ) {
19
56
var model = {
0 commit comments