1
+ import { BasicAuth , OAuth2Auth } from '../../src' ;
2
+
3
+ describe ( 'Auth Classes' , ( ) => {
4
+ describe ( 'BasicAuth' , ( ) => {
5
+ test ( 'should create BasicAuth with username only' , ( ) => {
6
+ const auth = new BasicAuth ( 'testuser' ) ;
7
+ expect ( auth . username ) . toBe ( 'testuser' ) ;
8
+ expect ( auth . password ) . toBeUndefined ( ) ;
9
+ expect ( auth . type ) . toBe ( 'basic' ) ;
10
+ } ) ;
11
+
12
+ test ( 'should create BasicAuth with username and password' , ( ) => {
13
+ const auth = new BasicAuth ( 'testuser' , 'testpass' ) ;
14
+ expect ( auth . username ) . toBe ( 'testuser' ) ;
15
+ expect ( auth . password ) . toBe ( 'testpass' ) ;
16
+ expect ( auth . type ) . toBe ( 'basic' ) ;
17
+ } ) ;
18
+ } ) ;
19
+
20
+ describe ( 'OAuth2Auth' , ( ) => {
21
+ test ( 'should create OAuth2Auth with token only' , ( ) => {
22
+ const auth = new OAuth2Auth ( 'test-token' ) ;
23
+ expect ( auth . token ) . toBe ( 'test-token' ) ;
24
+ expect ( auth . type ) . toBe ( 'oauth2' ) ;
25
+ expect ( auth . clientId ) . toBeUndefined ( ) ;
26
+ expect ( auth . clientSecret ) . toBeUndefined ( ) ;
27
+ expect ( auth . refreshToken ) . toBeUndefined ( ) ;
28
+ expect ( auth . tokenEndpoint ) . toBeUndefined ( ) ;
29
+ expect ( auth . scopes ) . toBeUndefined ( ) ;
30
+ expect ( auth . tokenType ) . toBeUndefined ( ) ;
31
+ expect ( auth . expiresIn ) . toBeUndefined ( ) ;
32
+ expect ( auth . redirectUri ) . toBeUndefined ( ) ;
33
+ expect ( auth . grantType ) . toBeUndefined ( ) ;
34
+ } ) ;
35
+
36
+ test ( 'should create OAuth2Auth with all optional parameters' , ( ) => {
37
+ const auth = new OAuth2Auth (
38
+ 'test-token' ,
39
+ 'client-id' ,
40
+ 'client-secret' ,
41
+ 'refresh-token' ,
42
+ 'https://example.com/oauth2/token' ,
43
+ [ 'read' , 'write' ] ,
44
+ 'Bearer' ,
45
+ 3600 ,
46
+ 'https://example.com/callback' ,
47
+ 'authorization_code'
48
+ ) ;
49
+
50
+ expect ( auth . token ) . toBe ( 'test-token' ) ;
51
+ expect ( auth . clientId ) . toBe ( 'client-id' ) ;
52
+ expect ( auth . clientSecret ) . toBe ( 'client-secret' ) ;
53
+ expect ( auth . refreshToken ) . toBe ( 'refresh-token' ) ;
54
+ expect ( auth . tokenEndpoint ) . toBe ( 'https://example.com/oauth2/token' ) ;
55
+ expect ( auth . scopes ) . toEqual ( [ 'read' , 'write' ] ) ;
56
+ expect ( auth . tokenType ) . toBe ( 'Bearer' ) ;
57
+ expect ( auth . expiresIn ) . toBe ( 3600 ) ;
58
+ expect ( auth . redirectUri ) . toBe ( 'https://example.com/callback' ) ;
59
+ expect ( auth . grantType ) . toBe ( 'authorization_code' ) ;
60
+ expect ( auth . type ) . toBe ( 'oauth2' ) ;
61
+ } ) ;
62
+
63
+ test ( 'should create OAuth2Auth with some optional parameters' , ( ) => {
64
+ const auth = new OAuth2Auth (
65
+ 'test-token' ,
66
+ 'client-id' ,
67
+ undefined ,
68
+ 'refresh-token' ,
69
+ undefined ,
70
+ [ 'read' ]
71
+ ) ;
72
+
73
+ expect ( auth . token ) . toBe ( 'test-token' ) ;
74
+ expect ( auth . clientId ) . toBe ( 'client-id' ) ;
75
+ expect ( auth . clientSecret ) . toBeUndefined ( ) ;
76
+ expect ( auth . refreshToken ) . toBe ( 'refresh-token' ) ;
77
+ expect ( auth . tokenEndpoint ) . toBeUndefined ( ) ;
78
+ expect ( auth . scopes ) . toEqual ( [ 'read' ] ) ;
79
+ } ) ;
80
+ } ) ;
81
+ } ) ;
0 commit comments