|
2 | 2 | require 'webmock/rspec'
|
3 | 3 | require 'json'
|
4 | 4 | require 'tempfile'
|
| 5 | +require 'open-uri' |
5 | 6 |
|
6 | 7 | RICH_MENU_CONTENT = <<"EOS"
|
7 | 8 | {
|
|
177 | 178 | .with(body: File.open(RICH_MENU_IMAGE_FILE_PATH).read)
|
178 | 179 | end
|
179 | 180 |
|
| 181 | + it 'uploads and attaches an image to a rich menu from uri' do |
| 182 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_BLOB_ENDPOINT + '/bot/richmenu/1234567/content' |
| 183 | + |
| 184 | + stub_request(:post, uri_template).to_return(body: '{}', status: 200).with do |request| |
| 185 | + expect(request.headers["Content-Type"]).to eq('image/png') |
| 186 | + end |
| 187 | + |
| 188 | + image_url = 'https://line.example.org/rich_menu.png' |
| 189 | + image_content = File.open(RICH_MENU_IMAGE_FILE_PATH).read |
| 190 | + image_content.force_encoding('ASCII-8BIT') |
| 191 | + stub_request(:get, image_url).to_return(body: image_content, status: 200, headers: { 'Content-Type' => 'image/png' }) |
| 192 | + |
| 193 | + client.create_rich_menu_image('1234567', URI.parse(image_url).open) |
| 194 | + |
| 195 | + expect(WebMock).to have_requested(:post, Line::Bot::API::DEFAULT_BLOB_ENDPOINT + '/bot/richmenu/1234567/content') |
| 196 | + .with(body: image_content) |
| 197 | + end |
| 198 | + |
180 | 199 | it "uploads invalid extension's file" do
|
181 | 200 | uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/1234567/content'
|
182 | 201 | stub_request(:post, uri_template).to_return(body: '{}', status: 200)
|
|
186 | 205 | end
|
187 | 206 | end.to raise_error(ArgumentError)
|
188 | 207 | end
|
| 208 | + |
| 209 | + it 'uploads invalid content type uri' do |
| 210 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/1234567/content' |
| 211 | + stub_request(:post, uri_template).to_return(body: '{}', status: 200) |
| 212 | + |
| 213 | + text_url = 'https://line.example.org/rich_menu.txt' |
| 214 | + text_content = File.open(RICH_MENU_INVALID_FILE_EXTENSION_PATH).read |
| 215 | + stub_request(:get, text_url).to_return(body: text_content, status: 200, headers: { 'Content-Type' => 'plain/text' }) |
| 216 | + |
| 217 | + expect do |
| 218 | + client.create_rich_menu_image('1234567', URI.parse(text_url).open) |
| 219 | + end.to raise_error(ArgumentError) |
| 220 | + end |
189 | 221 | end
|
0 commit comments