@@ -33,6 +33,53 @@ var mocks = {
3333} ;
3434var OAuth2 = gas . require ( './src' , mocks ) ;
3535
36+ describe ( 'OAuth2' , function ( ) {
37+ describe ( '#getServiceNames()' , function ( ) {
38+ it ( 'should return the service names for stored tokens' , function ( ) {
39+ var props = new MockProperties ( {
40+ 'oauth2.foo' : '{"access_token": "abc"}' ,
41+ 'oauth2.bar' : '{"access_token": "abc"}' ,
42+ } ) ;
43+
44+ var names = OAuth2 . getServiceNames ( props ) ;
45+
46+ assert . deepEqual ( names , [ 'foo' , 'bar' ] ) ;
47+ } ) ;
48+
49+ it ( 'should return an empty array when no tokens are stored' , function ( ) {
50+ var props = new MockProperties ( ) ;
51+
52+ var names = OAuth2 . getServiceNames ( props ) ;
53+
54+ assert . deepEqual ( names , [ ] ) ;
55+ } ) ;
56+
57+ it ( 'should ignore keys without a service name' , function ( ) {
58+ var props = new MockProperties ( {
59+ 'oauth2.' : 'foo' ,
60+ 'oauth2..bar' : 'bar' ,
61+ } ) ;
62+
63+ var names = OAuth2 . getServiceNames ( props ) ;
64+
65+ assert . deepEqual ( names , [ ] ) ;
66+ } ) ;
67+
68+ it ( 'should not have duplicate names when there are custom keys' ,
69+ function ( ) {
70+ var props = new MockProperties ( {
71+ 'oauth2.foo' : '{"access_token": "abc"}' ,
72+ 'oauth2.foo.extra' : 'my extra stuff' ,
73+ 'oauth2.foo.extra2' : 'more extra stuff' ,
74+ } ) ;
75+
76+ var names = OAuth2 . getServiceNames ( props ) ;
77+
78+ assert . deepEqual ( names , [ 'foo' ] ) ;
79+ } ) ;
80+ } ) ;
81+ } ) ;
82+
3683describe ( 'Service' , function ( ) {
3784 describe ( '#getToken()' , function ( ) {
3885 it ( 'should return null when no token is stored' , function ( ) {
0 commit comments