@@ -5,6 +5,17 @@ def template_fragments
55 Vonage ::Verify2 ::TemplateFragments . new ( config )
66 end
77
8+ def template_fragments_with_basic_auth
9+ config = Vonage ::Config . new . merge (
10+ {
11+ api_key : api_key ,
12+ api_secret : api_secret ,
13+ authentication_preference : :basic
14+ }
15+ )
16+ Vonage ::Verify2 ::TemplateFragments . new ( config )
17+ end
18+
819 def template_id
920 '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9'
1021 end
@@ -43,6 +54,15 @@ def test_list_method_with_optional_params
4354 template_fragments_list . each { |template_fragment | assert_kind_of Vonage ::Entity , template_fragment }
4455 end
4556
57+ def test_list_method_with_basic_authentication
58+ stub_request ( :get , template_fragments_uri ) . with ( request ( auth_method : basic_authorization ) ) . to_return ( template_fragments_list_response )
59+
60+ template_fragments_list = template_fragments_with_basic_auth . list ( template_id : template_id )
61+
62+ assert_kind_of Vonage ::Verify2 ::TemplateFragments ::ListResponse , template_fragments_list
63+ template_fragments_list . each { |template_fragment | assert_kind_of Vonage ::Entity , template_fragment }
64+ end
65+
4666 def test_list_method_without_template_id
4767 assert_raises ( ArgumentError ) { template_fragments . list }
4868 end
@@ -53,6 +73,12 @@ def test_info_method
5373 assert_kind_of Vonage ::Response , template_fragments . info ( template_id : template_id , template_fragment_id : template_fragment_id )
5474 end
5575
76+ def test_info_method_with_basic_authentication
77+ stub_request ( :get , template_fragment_uri ) . with ( request ( auth_method : basic_authorization ) ) . to_return ( response )
78+
79+ assert_kind_of Vonage ::Response , template_fragments_with_basic_auth . info ( template_id : template_id , template_fragment_id : template_fragment_id )
80+ end
81+
5682 def test_info_method_without_template_id
5783 assert_raises ( ArgumentError ) { template_fragments . info ( template_fragment_id : template_fragment_id ) }
5884 end
@@ -67,6 +93,12 @@ def test_create_method
6793 assert_kind_of Vonage ::Response , template_fragments . create ( template_id : template_id , channel : 'sms' , locale : 'en-gb' , text : 'Code: ${code}' )
6894 end
6995
96+ def test_create_method_with_basic_authentication
97+ stub_request ( :post , template_fragments_uri ) . with ( request ( body : { channel : 'sms' , locale : 'en-gb' , text : 'Code: ${code}' } , auth_method : basic_authorization ) ) . to_return ( response )
98+
99+ assert_kind_of Vonage ::Response , template_fragments_with_basic_auth . create ( template_id : template_id , channel : 'sms' , locale : 'en-gb' , text : 'Code: ${code}' )
100+ end
101+
70102 def test_create_method_without_template_id
71103 assert_raises ( ArgumentError ) { template_fragments . create ( channel : 'sms' , locale : 'en-gb' , text : 'Code: ${code}' ) }
72104 end
@@ -93,6 +125,12 @@ def test_update_method
93125 assert_kind_of Vonage ::Response , template_fragments . update ( template_id : template_id , template_fragment_id : template_fragment_id , text : 'Your code is: ${code}' )
94126 end
95127
128+ def test_update_method_with_basic_authentication
129+ stub_request ( :patch , template_fragment_uri ) . with ( request ( body : { text : 'Your code is: ${code}' } , auth_method : basic_authorization ) ) . to_return ( response )
130+
131+ assert_kind_of Vonage ::Response , template_fragments_with_basic_auth . update ( template_id : template_id , template_fragment_id : template_fragment_id , text : 'Your code is: ${code}' )
132+ end
133+
96134 def test_update_method_without_template_id
97135 assert_raises ( ArgumentError ) { template_fragments . update ( template_fragment_id : template_fragment_id , text : 'Your code is: ${code}' ) }
98136 end
@@ -111,6 +149,12 @@ def test_delete_method
111149 assert_kind_of Vonage ::Response , template_fragments . delete ( template_id : template_id , template_fragment_id : template_fragment_id )
112150 end
113151
152+ def test_delete_method_with_basic_authentication
153+ stub_request ( :delete , template_fragment_uri ) . with ( request ( auth_method : basic_authorization ) ) . to_return ( response )
154+
155+ assert_kind_of Vonage ::Response , template_fragments_with_basic_auth . delete ( template_id : template_id , template_fragment_id : template_fragment_id )
156+ end
157+
114158 def test_delete_method_without_template_id
115159 assert_raises ( ArgumentError ) { template_fragments . delete ( template_fragment_id : template_fragment_id ) }
116160 end
0 commit comments