|
| 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