|
| 1 | +# typed: false |
| 2 | + |
| 3 | +class Vonage::Verify2::TemplateFragmentsTest < Vonage::Test |
| 4 | + def template_fragments |
| 5 | + Vonage::Verify2::TemplateFragments.new(config) |
| 6 | + end |
| 7 | + |
| 8 | + def template_id |
| 9 | + '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9' |
| 10 | + end |
| 11 | + |
| 12 | + def template_fragment_id |
| 13 | + 'c70f446e-997a-4313-a081-60a02a31dc19' |
| 14 | + end |
| 15 | + |
| 16 | + def template_fragments_uri |
| 17 | + 'https://api.nexmo.com/v2/verify/templates/' + template_id + '/template_fragments' |
| 18 | + end |
| 19 | + |
| 20 | + def template_fragment_uri |
| 21 | + 'https://api.nexmo.com/v2/verify/templates/' + template_id + '/template_fragments/' + template_fragment_id |
| 22 | + end |
| 23 | + |
| 24 | + def template_fragments_list_response |
| 25 | + { body: '{"_embedded": {"template_fragments":[{"key":"value"}]}}', headers: response_headers } |
| 26 | + end |
| 27 | + |
| 28 | + def test_list_method |
| 29 | + stub_request(:get, template_fragments_uri).to_return(template_fragments_list_response) |
| 30 | + |
| 31 | + template_fragments_list = template_fragments.list(template_id: template_id) |
| 32 | + |
| 33 | + assert_kind_of Vonage::Verify2::TemplateFragments::ListResponse, template_fragments_list |
| 34 | + template_fragments_list.each { |template_fragment| assert_kind_of Vonage::Entity, template_fragment } |
| 35 | + end |
| 36 | + |
| 37 | + def test_list_method_with_optional_params |
| 38 | + stub_request(:get, template_fragments_uri + '?page_size=10&page=2').to_return(template_fragments_list_response) |
| 39 | + |
| 40 | + template_fragments_list = template_fragments.list(template_id: template_id, page_size: 10, page: 2) |
| 41 | + |
| 42 | + assert_kind_of Vonage::Verify2::TemplateFragments::ListResponse, template_fragments_list |
| 43 | + template_fragments_list.each { |template_fragment| assert_kind_of Vonage::Entity, template_fragment } |
| 44 | + end |
| 45 | + |
| 46 | + def test_list_method_without_template_id |
| 47 | + assert_raises(ArgumentError) { template_fragments.list } |
| 48 | + end |
| 49 | + |
| 50 | + def test_info_method |
| 51 | + stub_request(:get, template_fragment_uri).to_return(response) |
| 52 | + |
| 53 | + assert_kind_of Vonage::Response, template_fragments.info(template_id: template_id, template_fragment_id: template_fragment_id) |
| 54 | + end |
| 55 | + |
| 56 | + def test_info_method_without_template_id |
| 57 | + assert_raises(ArgumentError) { template_fragments.info(template_fragment_id: template_fragment_id) } |
| 58 | + end |
| 59 | + |
| 60 | + def test_info_method_without_template_fragment_id |
| 61 | + assert_raises(ArgumentError) { template_fragments.info(template_id: template_id) } |
| 62 | + end |
| 63 | + |
| 64 | + def test_create_method |
| 65 | + stub_request(:post, template_fragments_uri).with(body: { channel: 'sms', locale: 'en-gb', text: 'Code: ${code}' }).to_return(response) |
| 66 | + |
| 67 | + assert_kind_of Vonage::Response, template_fragments.create(template_id: template_id, channel: 'sms', locale: 'en-gb', text: 'Code: ${code}') |
| 68 | + end |
| 69 | + |
| 70 | + def test_create_method_without_template_id |
| 71 | + assert_raises(ArgumentError) { template_fragments.create(channel: 'sms', locale: 'en-gb', text: 'Code: ${code}') } |
| 72 | + end |
| 73 | + |
| 74 | + def test_create_method_without_channel |
| 75 | + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, locale: 'en-gb', text: 'Code: ${code}') } |
| 76 | + end |
| 77 | + |
| 78 | + def test_create_method_without_locale |
| 79 | + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, channel: 'sms', text: 'Code: ${code}') } |
| 80 | + end |
| 81 | + |
| 82 | + def test_create_method_without_text |
| 83 | + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, channel: 'sms', locale: 'en-gb') } |
| 84 | + end |
| 85 | + |
| 86 | + def test_create_method_with_invalid_channel |
| 87 | + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, channel: 'foo', locale: 'en-gb', text: 'Code: ${code}') } |
| 88 | + end |
| 89 | + |
| 90 | + def test_update_method |
| 91 | + stub_request(:patch, template_fragment_uri).with(body: { text: 'Your code is: ${code}' }).to_return(response) |
| 92 | + |
| 93 | + assert_kind_of Vonage::Response, template_fragments.update(template_id: template_id, template_fragment_id: template_fragment_id, text: 'Your code is: ${code}') |
| 94 | + end |
| 95 | + |
| 96 | + def test_update_method_without_template_id |
| 97 | + assert_raises(ArgumentError) { template_fragments.update(template_fragment_id: template_fragment_id, text: 'Your code is: ${code}') } |
| 98 | + end |
| 99 | + |
| 100 | + def test_update_method_without_template_fragment_id |
| 101 | + assert_raises(ArgumentError) { template_fragments.update(template_id: template_id, text: 'Your code is: ${code}') } |
| 102 | + end |
| 103 | + |
| 104 | + def test_update_method_without_text |
| 105 | + assert_raises(ArgumentError) { template_fragments.update(template_id: template_id, template_fragment_id: template_fragment_id) } |
| 106 | + end |
| 107 | + |
| 108 | + def test_delete_method |
| 109 | + stub_request(:delete, template_fragment_uri).to_return(response) |
| 110 | + |
| 111 | + assert_kind_of Vonage::Response, template_fragments.delete(template_id: template_id, template_fragment_id: template_fragment_id) |
| 112 | + end |
| 113 | + |
| 114 | + def test_delete_method_without_template_id |
| 115 | + assert_raises(ArgumentError) { template_fragments.delete(template_fragment_id: template_fragment_id) } |
| 116 | + end |
| 117 | + |
| 118 | + def test_delete_method_without_template_fragment_id |
| 119 | + assert_raises(ArgumentError) { template_fragments.delete(template_id: template_id) } |
| 120 | + end |
| 121 | +end |
0 commit comments