@@ -28,50 +28,24 @@ describe('authenticators', () => {
2828 jest . clearAllMocks ( )
2929 } )
3030
31- const config = { url : 'https://api.smartthings.com' , headers : { Test : 'test' } }
31+ test ( 'NoOpAuthenticator returns no headers' , async ( ) => {
32+ const authenticator = new NoOpAuthenticator ( )
3233
33- describe ( 'NoOpAuthenticator' , ( ) => {
34- test ( 'authenticate returns config unchanged' , async ( ) => {
35- const authenticator = new NoOpAuthenticator ( )
36- const data = await authenticator . authenticate ( config )
37-
38- expect ( data ) . toBe ( config )
39- } )
40-
41- test ( 'authenticateGeneric returns empty string for token' , async ( ) => {
42- const authenticator = new NoOpAuthenticator ( )
43- const token = await authenticator . authenticateGeneric ( )
44-
45- expect ( token ) . toBe ( '' )
46- } )
34+ expect ( await authenticator . authenticate ( ) ) . toStrictEqual ( { } )
4735 } )
4836
49- describe ( 'BearerTokenAuthenticator' , ( ) => {
50- test ( 'authenticate adds header with specified token' , async ( ) => {
51- const authenticator = new BearerTokenAuthenticator ( 'a-bearer-token' )
52- const data = await authenticator . authenticate ( config )
37+ test ( 'BearerTokenAuthenticator returns header with specified token' , async ( ) => {
38+ const authenticator = new BearerTokenAuthenticator ( 'a-bearer-token' )
5339
54- expect ( data . url ) . toBe ( config . url )
55- expect ( data . headers ?. Authorization ) . toBe ( 'Bearer a-bearer-token' )
56- expect ( data . headers ?. Test ) . toBe ( 'test' )
57- } )
58-
59- test ( 'authenticateGeneric returns specified token' , async ( ) => {
60- const authenticator = new BearerTokenAuthenticator ( 'a-bearer-token' )
61- const token = await authenticator . authenticateGeneric ( )
62-
63- expect ( token ) . toBe ( 'a-bearer-token' )
64- } )
40+ expect ( await authenticator . authenticate ( ) ) . toStrictEqual ( { Authorization : 'Bearer a-bearer-token' } )
6541 } )
6642
6743 describe ( 'RefreshTokenAuthenticator' , ( ) => {
68- test ( 'authenticate adds header with specified token' , async ( ) => {
44+ test ( 'authenticate returns header with specified token' , async ( ) => {
6945 const tokenStore = new TokenStore ( )
7046 const authenticator = new RefreshTokenAuthenticator ( 'a-refreshable-bearer-token' , tokenStore )
71- const data = await authenticator . authenticate ( config )
7247
73- expect ( data . url ) . toBe ( config . url )
74- expect ( data . headers ?. Authorization ) . toBe ( 'Bearer a-refreshable-bearer-token' )
48+ expect ( await authenticator . authenticate ( ) ) . toStrictEqual ( { Authorization : 'Bearer a-refreshable-bearer-token' } )
7549 } )
7650
7751 test ( 'refresh updates token' , async ( ) => {
@@ -86,7 +60,8 @@ describe('authenticators', () => {
8660 const tokenStore = new TokenStore ( )
8761 const authenticator = new RefreshTokenAuthenticator ( 'a-refreshable-bearer-token' , tokenStore )
8862 const endpointConfig = { urlProvider : defaultSmartThingsURLProvider , authenticator }
89- await authenticator . refresh ( config , endpointConfig )
63+
64+ expect ( await authenticator . refresh ( endpointConfig ) ) . toStrictEqual ( { Authorization : 'Bearer the-access-token' } )
9065
9166 expect ( axios . request ) . toHaveBeenCalledTimes ( 1 )
9267 expect ( axios . request ) . toHaveBeenCalledWith ( {
@@ -114,7 +89,7 @@ describe('authenticators', () => {
11489 const endpointConfig = { urlProvider : defaultSmartThingsURLProvider , authenticator }
11590 let message
11691 try {
117- await authenticator . refresh ( config , endpointConfig )
92+ await authenticator . refresh ( endpointConfig )
11893 // eslint-disable-next-line @typescript-eslint/no-explicit-any
11994 } catch ( error : any ) {
12095 message = error . message
@@ -133,10 +108,7 @@ describe('authenticators', () => {
133108 const authenticator = new SequentialRefreshTokenAuthenticator ( 'a-bearer-token' , tokenStore , mutex )
134109
135110 test ( 'authenticate adds header with specified token' , async ( ) => {
136- const data = await authenticator . authenticate ( config )
137-
138- expect ( data . url ) . toBe ( config . url )
139- expect ( data . headers ?. Authorization ) . toBe ( 'Bearer a-bearer-token' )
111+ expect ( await authenticator . authenticate ( ) ) . toStrictEqual ( { Authorization : 'Bearer a-bearer-token' } )
140112 } )
141113
142114 describe ( 'refresh' , ( ) => {
@@ -151,7 +123,7 @@ describe('authenticators', () => {
151123 const endpointConfig = { urlProvider : defaultSmartThingsURLProvider , authenticator }
152124
153125 it ( 'updates token' , async ( ) => {
154- await authenticator . refresh ( config , endpointConfig )
126+ await authenticator . refresh ( endpointConfig )
155127
156128 expect ( axios . request ) . toHaveBeenCalledTimes ( 1 )
157129 expect ( axios . request ) . toHaveBeenCalledWith ( {
@@ -169,8 +141,7 @@ describe('authenticators', () => {
169141 } )
170142
171143 it ( 'works on request with no existing headers' , async ( ) => {
172- const configWithoutHeaders = { url : 'https://api.smartthings.com' }
173- await authenticator . refresh ( configWithoutHeaders , endpointConfig )
144+ expect ( await authenticator . refresh ( endpointConfig ) ) . toStrictEqual ( { Authorization : 'Bearer the-access-token' } )
174145
175146 expect ( axios . request ) . toHaveBeenCalledTimes ( 1 )
176147 expect ( axios . request ) . toHaveBeenCalledWith ( {
0 commit comments