@@ -10,25 +10,86 @@ def token_uri
10
10
"https://api-eu.vonage.com/oauth2/token"
11
11
end
12
12
13
- def test_token_method
14
- grant_type = 'authorization_code'
15
- code = '0dadaeb4-7c79-4d39-b4b0-5a6cc08bf537'
16
- redirect_uri = 'https://example.com/callback'
13
+ def example_oidc_auth_code
14
+ '0dadaeb4-7c79-4d39-b4b0-5a6cc08bf537'
15
+ end
16
+
17
+ def example_redirect_uri
18
+ 'https://example.com/callback'
19
+ end
20
+
21
+ def example_purpose
22
+ 'FraudPreventionAndDetection'
23
+ end
24
+
25
+ def example_api_scope
26
+ 'number-verification-verify-read'
27
+ end
17
28
29
+ def example_login_hint
30
+ '+447700900000'
31
+ end
32
+
33
+ def example_redirect_uri
34
+ 'https://example.com/callback'
35
+ end
36
+
37
+ def test_token_method
18
38
request_params = {
19
- grant_type : grant_type ,
20
- code : code ,
21
- redirect_uri : redirect_uri
39
+ grant_type : 'authorization_code' ,
40
+ code : example_oidc_auth_code ,
41
+ redirect_uri : example_redirect_uri
22
42
}
23
43
24
44
stub_request ( :post , token_uri ) . with ( request ( body : request_params , headers : headers ) ) . to_return ( response )
25
45
26
- response = client . token (
27
- grant_type : grant_type ,
28
- oidc_auth_code : code ,
29
- redirect_uri : redirect_uri
46
+ assert_kind_of Vonage ::Response , client . token ( oidc_auth_code : example_oidc_auth_code , redirect_uri : example_redirect_uri )
47
+ end
48
+
49
+ def test_token_method_without_oidc_auth_code
50
+ assert_raises ( ArgumentError ) { client . token ( redirect_uri : example_redirect_uri ) }
51
+ end
52
+
53
+ def test_token_method_without_redirect_uri
54
+ assert_raises ( ArgumentError ) { client . token ( oidc_auth_code : example_oidc_auth_code ) }
55
+ end
56
+
57
+ def test_generate_oidc_uri_method
58
+ uri = client . generate_oidc_uri (
59
+ purpose : example_purpose ,
60
+ api_scope : example_api_scope ,
61
+ login_hint : example_login_hint ,
62
+ redirect_uri : example_redirect_uri
63
+ )
64
+
65
+ assert_equal "https://oidc.idp.vonage.com/oauth2/auth?client_id=#{ application_id } &response_type=code&scope=openid+dpv:#{ example_purpose } ##{ example_api_scope } &login_hint=#{ example_login_hint } &redirect_uri=#{ example_redirect_uri } " , uri
66
+ end
67
+
68
+ def test_generate_oidc_uri_method_with_optional_params
69
+ uri = client . generate_oidc_uri (
70
+ purpose : example_purpose ,
71
+ api_scope : example_api_scope ,
72
+ login_hint : example_login_hint ,
73
+ redirect_uri : example_redirect_uri ,
74
+ state : '12345'
30
75
)
31
76
32
- assert_kind_of Vonage ::Response , response
77
+ assert_equal "https://oidc.idp.vonage.com/oauth2/auth?client_id=#{ application_id } &response_type=code&scope=openid+dpv:#{ example_purpose } ##{ example_api_scope } &login_hint=#{ example_login_hint } &redirect_uri=#{ example_redirect_uri } &state=12345" , uri
78
+ end
79
+
80
+ def test_generate_oidc_uri_method_without_purpose
81
+ assert_raises ( ArgumentError ) { client . generate_oidc_uri ( api_scope : example_api_scope , login_hint : example_login_hint , redirect_uri : example_redirect_uri ) }
82
+ end
83
+
84
+ def test_generate_oidc_uri_method_without_api_scope
85
+ assert_raises ( ArgumentError ) { client . generate_oidc_uri ( purpose : example_purpose , login_hint : example_login_hint , redirect_uri : example_redirect_uri ) }
86
+ end
87
+
88
+ def test_generate_oidc_uri_method_without_login_hint
89
+ assert_raises ( ArgumentError ) { client . generate_oidc_uri ( purpose : example_purpose , api_scope : example_api_scope , redirect_uri : example_redirect_uri ) }
90
+ end
91
+
92
+ def test_generate_oidc_uri_method_without_redirect_uri
93
+ assert_raises ( ArgumentError ) { client . generate_oidc_uri ( purpose : example_purpose , api_scope : example_api_scope , login_hint : example_login_hint ) }
33
94
end
34
95
end
0 commit comments