|
16 | 16 | }
|
17 | 17 | EOS
|
18 | 18 |
|
| 19 | +TEST_WEBHOOK_ENDPOINT = 'https://example.com/test' |
| 20 | +TEST_WEBHOOK_ENDPOINT_CONTENT = <<"EOS" |
| 21 | +{ |
| 22 | + "endpoint": "#{TEST_WEBHOOK_ENDPOINT}" |
| 23 | +} |
| 24 | +EOS |
| 25 | + |
| 26 | +TEST_WEBHOOK_ENDPOINT_RESPONSE = <<"EOS" |
| 27 | +{ |
| 28 | + "success": true, |
| 29 | + "timestamp": "2020-09-30T05:38:20.031Z", |
| 30 | + "statusCode": 200, |
| 31 | + "reason": "OK", |
| 32 | + "detail": "200" |
| 33 | +} |
| 34 | +EOS |
| 35 | + |
19 | 36 | describe Line::Bot::Client do
|
20 | 37 | let(:client) do
|
21 | 38 | dummy_config = {
|
|
47 | 64 | expect(WebMock).to have_requested(:put, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/channel/webhook/endpoint')
|
48 | 65 | .with(body: JSON.parse(UPDATE_WEBHOOK_ENDPOINT_CONTENT).to_json)
|
49 | 66 | end
|
| 67 | + |
| 68 | + it 'test webhook endpoint' do |
| 69 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/channel/webhook/test' |
| 70 | + stub_request(:post, uri_template).to_return(body: TEST_WEBHOOK_ENDPOINT_RESPONSE, status: 200) |
| 71 | + |
| 72 | + response = client.test_webhook_endpoint(TEST_WEBHOOK_ENDPOINT) |
| 73 | + expect(WebMock).to have_requested(:post, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/channel/webhook/test') |
| 74 | + .with(body: JSON.parse(TEST_WEBHOOK_ENDPOINT_CONTENT).to_json) |
| 75 | + |
| 76 | + json = JSON.parse(response.body, symbolize_names: true) |
| 77 | + expect(json).to eq( |
| 78 | + success: true, |
| 79 | + timestamp: "2020-09-30T05:38:20.031Z", |
| 80 | + statusCode: 200, |
| 81 | + reason: "OK", |
| 82 | + detail: "200" |
| 83 | + ) |
| 84 | + end |
| 85 | + |
| 86 | + it 'test webhook endpoint empty' do |
| 87 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/channel/webhook/test' |
| 88 | + stub_request(:post, uri_template).to_return(body: TEST_WEBHOOK_ENDPOINT_RESPONSE, status: 200) |
| 89 | + |
| 90 | + response = client.test_webhook_endpoint |
| 91 | + expect(WebMock).to have_requested(:post, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/channel/webhook/test') |
| 92 | + .with(body: JSON.parse('{}').to_json) |
| 93 | + |
| 94 | + json = JSON.parse(response.body, symbolize_names: true) |
| 95 | + expect(json).to eq( |
| 96 | + success: true, |
| 97 | + timestamp: "2020-09-30T05:38:20.031Z", |
| 98 | + statusCode: 200, |
| 99 | + reason: "OK", |
| 100 | + detail: "200" |
| 101 | + ) |
| 102 | + end |
50 | 103 | end
|
0 commit comments