Skip to content

Commit fb96878

Browse files
committed
Implementing Verify2 Templates methods
1 parent 31615a1 commit fb96878

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

lib/vonage/verify2/template_fragments.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
module Vonage
55
class Verify2::TemplateFragments < Namespace
6+
self.authentication = BearerToken
7+
8+
self.request_body = JSON
9+
610

711
end
812
end

lib/vonage/verify2/templates.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33

44
module Vonage
55
class Verify2::Templates < Namespace
6-
6+
self.authentication = BearerToken
7+
8+
self.request_body = JSON
9+
10+
def list(**params)
11+
request('/v2/verify/templates', params: params, response_class: ListResponse)
12+
end
13+
14+
def info(template_id:)
15+
request('/v2/verify/templates/' + template_id)
16+
end
17+
18+
def create(name:)
19+
request('/v2/verify/templates', params: { name: name }, type: Post)
20+
end
21+
22+
def update(template_id:, **params)
23+
request('/v2/verify/templates/' + template_id, params: params, type: Patch)
24+
end
25+
26+
def delete(template_id:)
27+
request('/v2/verify/templates/' + template_id, type: Delete)
28+
end
729
end
830
end

test/vonage/verify2/templates_test.rb

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# typed: false
2+
3+
class Vonage::Verify2::TemplatesTest < Vonage::Test
4+
def templates
5+
Vonage::Verify2::Templates.new(config)
6+
end
7+
8+
def template_id
9+
'8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9'
10+
end
11+
12+
def templates_uri
13+
'https://api.nexmo.com/v2/verify/templates'
14+
end
15+
16+
def template_uri
17+
'https://api.nexmo.com/v2/verify/templates/' + template_id
18+
end
19+
20+
def templates_list_response
21+
{ body: '{"_embedded": {"templates":[{"key":"value"}]}}', headers: response_headers }
22+
end
23+
24+
def test_list_method
25+
stub_request(:get, templates_uri).to_return(templates_list_response)
26+
27+
templates_list = templates.list
28+
29+
assert_kind_of Vonage::Verify2::Templates::ListResponse, templates_list
30+
templates_list.each { |template| assert_kind_of Vonage::Entity, template }
31+
end
32+
33+
def test_list_method_with_optional_params
34+
stub_request(:get, templates_uri + '?page_size=10&page=2').to_return(templates_list_response)
35+
36+
templates_list = templates.list(page_size: 10, page: 2)
37+
38+
assert_kind_of Vonage::Verify2::Templates::ListResponse, templates_list
39+
templates_list.each { |template| assert_kind_of Vonage::Entity, template }
40+
end
41+
42+
def test_info_method
43+
stub_request(:get, template_uri).to_return(response)
44+
45+
assert_kind_of Vonage::Response, templates.info(template_id: template_id)
46+
end
47+
48+
def test_info_method_without_template_id
49+
assert_raises(ArgumentError) { templates.info }
50+
end
51+
52+
def test_create_method
53+
stub_request(:post, templates_uri).with(body: { name: 'My Template' }).to_return(response)
54+
55+
assert_kind_of Vonage::Response, templates.create(name: 'My Template')
56+
end
57+
58+
def test_create_method_without_name
59+
assert_raises(ArgumentError) { templates.create }
60+
end
61+
62+
def test_update_method
63+
stub_request(:patch, template_uri).with(body: { name: 'My Updated Template', is_default: false }).to_return(response)
64+
65+
assert_kind_of Vonage::Response, templates.update(template_id: template_id, name: 'My Updated Template', is_default: false)
66+
end
67+
68+
def test_update_method_without_template_id
69+
assert_raises(ArgumentError) { templates.update(name: 'My Updated Template', is_default: false) }
70+
end
71+
72+
def test_delete_method
73+
stub_request(:delete, template_uri).to_return(response)
74+
75+
assert_kind_of Vonage::Response, templates.delete(template_id: template_id)
76+
end
77+
78+
def test_delete_method_without_template_id
79+
assert_raises(ArgumentError) { templates.delete }
80+
end
81+
end

0 commit comments

Comments
 (0)