1- /* global describe, it */
1+ /* global describe, it, context */
22var expect = require ( 'chai' ) . expect
33var config = require ( './support/config' )
44var ClientOAuth2 = require ( '../' )
@@ -9,7 +9,7 @@ describe('owner', function () {
99 clientSecret : config . clientSecret ,
1010 accessTokenUri : config . accessTokenUri ,
1111 authorizationGrants : [ 'owner' ] ,
12- scope : 'notifications'
12+ scopes : 'notifications'
1313 } )
1414
1515 describe ( '#getToken' , function ( ) {
@@ -19,8 +19,62 @@ describe('owner', function () {
1919 expect ( user ) . to . an . instanceOf ( ClientOAuth2 . Token )
2020 expect ( user . accessToken ) . to . equal ( config . accessToken )
2121 expect ( user . tokenType ) . to . equal ( 'bearer' )
22+ expect ( user . data . scope ) . to . equal ( 'notifications' )
2223 } )
2324 } )
25+ context ( 'when scopes are undefined' , function ( ) {
26+ it ( 'should not send scope to an auth server' , function ( ) {
27+ var scopelessAuth = new ClientOAuth2 ( {
28+ clientId : config . clientId ,
29+ clientSecret : config . clientSecret ,
30+ accessTokenUri : config . accessTokenUri ,
31+ authorizationGrants : [ 'owner' ]
32+ } )
33+ return scopelessAuth . owner . getToken ( config . username , config . password )
34+ . then ( function ( user ) {
35+ expect ( user ) . to . an . instanceOf ( ClientOAuth2 . Token )
36+ expect ( user . accessToken ) . to . equal ( config . accessToken )
37+ expect ( user . tokenType ) . to . equal ( 'bearer' )
38+ expect ( user . data . scope ) . to . equal ( undefined )
39+ } )
40+ } )
41+ } )
42+ context ( 'when scopes are an empty array' , function ( ) {
43+ it ( 'should send empty scope string to an auth server' , function ( ) {
44+ var scopelessAuth = new ClientOAuth2 ( {
45+ clientId : config . clientId ,
46+ clientSecret : config . clientSecret ,
47+ accessTokenUri : config . accessTokenUri ,
48+ authorizationGrants : [ 'owner' ] ,
49+ scopes : [ ]
50+ } )
51+ return scopelessAuth . owner . getToken ( config . username , config . password )
52+ . then ( function ( user ) {
53+ expect ( user ) . to . an . instanceOf ( ClientOAuth2 . Token )
54+ expect ( user . accessToken ) . to . equal ( config . accessToken )
55+ expect ( user . tokenType ) . to . equal ( 'bearer' )
56+ expect ( user . data . scope ) . to . equal ( '' )
57+ } )
58+ } )
59+ } )
60+ context ( 'when scopes are an empty string' , function ( ) {
61+ it ( 'should send empty scope string to an auth server' , function ( ) {
62+ var scopelessAuth = new ClientOAuth2 ( {
63+ clientId : config . clientId ,
64+ clientSecret : config . clientSecret ,
65+ accessTokenUri : config . accessTokenUri ,
66+ authorizationGrants : [ 'owner' ] ,
67+ scopes : ''
68+ } )
69+ return scopelessAuth . owner . getToken ( config . username , config . password )
70+ . then ( function ( user ) {
71+ expect ( user ) . to . an . instanceOf ( ClientOAuth2 . Token )
72+ expect ( user . accessToken ) . to . equal ( config . accessToken )
73+ expect ( user . tokenType ) . to . equal ( 'bearer' )
74+ expect ( user . data . scope ) . to . equal ( '' )
75+ } )
76+ } )
77+ } )
2478
2579 describe ( '#sign' , function ( ) {
2680 it ( 'should be able to sign a standard request object' , function ( ) {
0 commit comments