|
| 1 | +# typed: false |
| 2 | + |
| 3 | + |
| 4 | +class Vonage::Messaging::Channels::RCSTest < Vonage::Test |
| 5 | + def test_rcs_initialize |
| 6 | + message = Vonage::Messaging::Channels::RCS.new(type: 'text', message: 'Hello world!') |
| 7 | + |
| 8 | + assert_kind_of Vonage::Messaging::Channels::RCS, message |
| 9 | + end |
| 10 | + |
| 11 | + def test_rcs_text_message |
| 12 | + expected = { |
| 13 | + channel: 'rcs', |
| 14 | + message_type: 'text', |
| 15 | + text: 'Hello world!' |
| 16 | + } |
| 17 | + |
| 18 | + message = Vonage::Messaging::Channels::RCS.new( |
| 19 | + type: 'text', |
| 20 | + message: 'Hello world!' |
| 21 | + ) |
| 22 | + |
| 23 | + assert_equal expected, message.data |
| 24 | + end |
| 25 | + |
| 26 | + def test_rcs_text_message_wth_optional_parameters |
| 27 | + expected = { |
| 28 | + channel: 'rcs', |
| 29 | + message_type: 'text', |
| 30 | + text: 'Hello world!', |
| 31 | + ttl: 600, |
| 32 | + client_ref: "abc123", |
| 33 | + webhook_url: "https://example.com/status" |
| 34 | + } |
| 35 | + |
| 36 | + message = Vonage::Messaging::Channels::RCS.new( |
| 37 | + type: 'text', |
| 38 | + message: 'Hello world!', |
| 39 | + opts: { |
| 40 | + ttl: 600, |
| 41 | + client_ref: "abc123", |
| 42 | + webhook_url: "https://example.com/status" |
| 43 | + } |
| 44 | + ) |
| 45 | + |
| 46 | + assert_equal expected, message.data |
| 47 | + end |
| 48 | + |
| 49 | + def test_rcs_image_message |
| 50 | + expected = { |
| 51 | + channel: 'rcs', |
| 52 | + message_type: 'image', |
| 53 | + image: { |
| 54 | + url: 'https://example.com/image.jpg' |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + message = Vonage::Messaging::Channels::RCS.new( |
| 59 | + type: 'image', |
| 60 | + message: { |
| 61 | + url: 'https://example.com/image.jpg' |
| 62 | + } |
| 63 | + ) |
| 64 | + |
| 65 | + assert_equal expected, message.data |
| 66 | + end |
| 67 | + |
| 68 | + def test_rcs_video_message |
| 69 | + expected = { |
| 70 | + channel: 'rcs', |
| 71 | + message_type: 'image', |
| 72 | + image: { |
| 73 | + url: 'https://example.com/video.webm' |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + message = Vonage::Messaging::Channels::RCS.new( |
| 78 | + type: 'image', |
| 79 | + message: { |
| 80 | + url: 'https://example.com/video.webm' |
| 81 | + } |
| 82 | + ) |
| 83 | + |
| 84 | + assert_equal expected, message.data |
| 85 | + end |
| 86 | + |
| 87 | + def test_rcs_file_message |
| 88 | + expected = { |
| 89 | + channel: 'rcs', |
| 90 | + message_type: 'file', |
| 91 | + file: { |
| 92 | + url: 'https://example.com/file.pdf' |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + message = Vonage::Messaging::Channels::RCS.new( |
| 97 | + type: 'file', |
| 98 | + message: { |
| 99 | + url: 'https://example.com/file.pdf' |
| 100 | + } |
| 101 | + ) |
| 102 | + |
| 103 | + assert_equal expected, message.data |
| 104 | + end |
| 105 | + |
| 106 | + def test_rcs_custom_message |
| 107 | + expected = { |
| 108 | + channel: 'rcs', |
| 109 | + message_type: 'custom', |
| 110 | + custom: { |
| 111 | + contentMessage: { |
| 112 | + text: 'Which ice-cream flavour do you prefer?', |
| 113 | + suggestions: [ |
| 114 | + { |
| 115 | + reply: { |
| 116 | + text: 'Vanilla', |
| 117 | + postback: 'vanilla' |
| 118 | + } |
| 119 | + }, |
| 120 | + { |
| 121 | + reply: { |
| 122 | + text: 'Chocolate', |
| 123 | + postback: 'chocolate' |
| 124 | + } |
| 125 | + } |
| 126 | + ] |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + message = Vonage::Messaging::Channels::RCS.new( |
| 132 | + type: 'custom', |
| 133 | + message: { |
| 134 | + contentMessage: { |
| 135 | + text: 'Which ice-cream flavour do you prefer?', |
| 136 | + suggestions: [ |
| 137 | + { |
| 138 | + reply: { |
| 139 | + text: 'Vanilla', |
| 140 | + postback: 'vanilla' |
| 141 | + } |
| 142 | + }, |
| 143 | + { |
| 144 | + reply: { |
| 145 | + text: 'Chocolate', |
| 146 | + postback: 'chocolate' |
| 147 | + } |
| 148 | + } |
| 149 | + ] |
| 150 | + } |
| 151 | + } |
| 152 | + ) |
| 153 | + |
| 154 | + assert_equal expected, message.data |
| 155 | + end |
| 156 | + |
| 157 | + def test_rcs_invalid_message_type |
| 158 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'invalid', message: 'Hello world!') } |
| 159 | + |
| 160 | + assert_instance_of Vonage::ClientError, exception |
| 161 | + assert_match "Invalid message type", exception.message |
| 162 | + end |
| 163 | + |
| 164 | + def test_rcs_text_message_invalid_type |
| 165 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'text', message: 123) } |
| 166 | + |
| 167 | + assert_instance_of Vonage::ClientError, exception |
| 168 | + assert_match "Invalid parameter type. `:message` must be a String", exception.message |
| 169 | + end |
| 170 | + |
| 171 | + def test_rcs_image_message_invalid_type |
| 172 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'image', message: 'https://example.com/image.jpg') } |
| 173 | + |
| 174 | + assert_instance_of Vonage::ClientError, exception |
| 175 | + assert_match "Invalid parameter type. `:message` must be a Hash", exception.message |
| 176 | + end |
| 177 | + |
| 178 | + def test_rcs_image_message_missing_url |
| 179 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'image', message: {}) } |
| 180 | + |
| 181 | + assert_instance_of Vonage::ClientError, exception |
| 182 | + assert_match "Missing parameter. `:message` must contain a `:url` key", exception.message |
| 183 | + end |
| 184 | + |
| 185 | + def test_rcs_video_message_invalid_type |
| 186 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'video', message: 'https://example.com/video.webm') } |
| 187 | + |
| 188 | + assert_instance_of Vonage::ClientError, exception |
| 189 | + assert_match "Invalid parameter type. `:message` must be a Hash", exception.message |
| 190 | + end |
| 191 | + |
| 192 | + def test_rcs_video_message_missing_url |
| 193 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'video', message: {}) } |
| 194 | + |
| 195 | + assert_instance_of Vonage::ClientError, exception |
| 196 | + assert_match "Missing parameter. `:message` must contain a `:url` key", exception.message |
| 197 | + end |
| 198 | + |
| 199 | + def test_rcs_file_message_invalid_type |
| 200 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'file', message: 'https://example.com/file.pdf') } |
| 201 | + |
| 202 | + assert_instance_of Vonage::ClientError, exception |
| 203 | + assert_match "Invalid parameter type. `:message` must be a Hash", exception.message |
| 204 | + end |
| 205 | + |
| 206 | + def test_rcs_file_message_missing_url |
| 207 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'file', message: {}) } |
| 208 | + |
| 209 | + assert_instance_of Vonage::ClientError, exception |
| 210 | + assert_match "Missing parameter. `:message` must contain a `:url` key", exception.message |
| 211 | + end |
| 212 | + |
| 213 | + def test_rcs_custom_message_invalid_type |
| 214 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'custom', message: 'Hello world!') } |
| 215 | + |
| 216 | + assert_instance_of Vonage::ClientError, exception |
| 217 | + assert_match "Invalid parameter type. `:message` must be a Hash", exception.message |
| 218 | + end |
| 219 | + |
| 220 | + def test_rcs_custom_message_with_empty_message_hash |
| 221 | + exception = assert_raises { Vonage::Messaging::Channels::RCS.new(type: 'custom', message: {}) } |
| 222 | + |
| 223 | + assert_instance_of Vonage::ClientError, exception |
| 224 | + assert_match "Invalid parameter content. `:message` must not be empty", exception.message |
| 225 | + end |
| 226 | +end |
0 commit comments