Skip to content

Commit e9546ae

Browse files
authored
Add test about empty string and empty JSON in response (#442)
1 parent efe9eec commit e9546ae

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

spec/line/bot/v2/misc_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,49 @@
267267
end
268268
end
269269

270+
describe 'PUT /liff/v1/apps/{liffId}' do
271+
let(:client) { Line::Bot::V2::Liff::ApiClient.new(channel_access_token: 'test-channel-access-token') }
272+
let(:response_body) { "" } # not empty json, but empty string
273+
let(:response_code) { 200 }
274+
275+
it 'empty response body should not throw error' do
276+
stub_request(:put, "https://api.line.me/liff/v1/apps/test-liff-id")
277+
.with(
278+
headers: {
279+
'Authorization' => "Bearer test-channel-access-token"
280+
}
281+
)
282+
.to_return(status: response_code, body: response_body, headers: { })
283+
284+
request = Line::Bot::V2::Liff::UpdateLiffAppRequest.new(view: { url: 'https://example.com' })
285+
body, status_code, headers = client.update_liff_app_with_http_info(liff_id: 'test-liff-id', update_liff_app_request: request)
286+
287+
expect(status_code).to eq(200)
288+
expect(body).to eq("")
289+
end
290+
end
291+
292+
describe 'POST /v2/bot/message/broadcast' do
293+
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
294+
let(:response_body) { { }.to_json } # empty json
295+
let(:response_code) { 200 }
296+
297+
it 'empty json as response body should not throw error' do
298+
stub_request(:post, "https://api.line.me/v2/bot/message/broadcast")
299+
.with(
300+
headers: {
301+
'Authorization' => "Bearer test-channel-access-token"
302+
}
303+
)
304+
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
305+
306+
body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' })
307+
308+
expect(status_code).to eq(200)
309+
expect(body).to eq("{}")
310+
end
311+
end
312+
270313
describe 'GET /v2/bot/message/aggregation/list' do
271314
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
272315
let(:response_body) { { "custom_aggregation_units" => ["unit1", "unit2"], "next" => "token" }.to_json }

0 commit comments

Comments
 (0)