|
7 | 7 | let(:response) { Viberroo::Response.new(event: 'message', sender: { id: '01234=' }) } |
8 | 8 | let(:bot) { Viberroo::Bot.new(token: token, response: response) } |
9 | 9 |
|
| 10 | + describe '#send_message' do |
| 11 | + subject { bot.send_message(message, keyboard: keyboard) } |
| 12 | + |
| 13 | + let(:message) do |
| 14 | + { |
| 15 | + text: 'hello', |
| 16 | + event: 'message', |
| 17 | + sender: { id: '1234=' }, |
| 18 | + receiver: response.user_id |
| 19 | + } |
| 20 | + end |
| 21 | + |
| 22 | + context 'when keyboard does not contain inputs' do |
| 23 | + let(:keyboard) { {} } |
| 24 | + |
| 25 | + it 'does not contain :min_api_version attr in the params root' do |
| 26 | + expect(bot).to receive(:request).with( |
| 27 | + Viberroo::URL::MESSAGE, |
| 28 | + { receiver: response.user_id }.merge(message) |
| 29 | + ) |
| 30 | + subject |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + context 'when keyboard contain single input with api version' do |
| 35 | + let(:button) { Viberroo::Input.share_phone_button({}) } |
| 36 | + let(:keyboard) { Viberroo::Input.keyboard(Buttons: [button]) } |
| 37 | + let(:min_api_version) { button[:min_api_version] } |
| 38 | + |
| 39 | + it 'sets correct :min_api_version attr in the params root' do |
| 40 | + expect(bot).to receive(:request).with( |
| 41 | + Viberroo::URL::MESSAGE, |
| 42 | + { receiver: response.user_id }.merge(message, keyboard, min_api_version: min_api_version) |
| 43 | + ) |
| 44 | + subject |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + context 'when keyboard contain single input with api version but min_api-version was set before' do |
| 49 | + let(:min_api_version) { 7 } |
| 50 | + let(:message) { { min_api_version: min_api_version } } |
| 51 | + let(:button) { Viberroo::Input.share_phone_button({}) } |
| 52 | + let(:keyboard) { Viberroo::Input.keyboard(Buttons: [button]) } |
| 53 | + |
| 54 | + it 'sets correct :min_api_version attr in the params root' do |
| 55 | + expect(bot).to receive(:request).with( |
| 56 | + Viberroo::URL::MESSAGE, |
| 57 | + { receiver: response.user_id }.merge(message, keyboard, min_api_version: min_api_version) |
| 58 | + ) |
| 59 | + subject |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + context 'when keyboard contain multiple inputs one of which has no api versions' do |
| 64 | + let(:button_one) { Viberroo::Input.share_phone_button({}) } |
| 65 | + let(:button_two) { Viberroo::Input.reply_button({}) } |
| 66 | + let(:keyboard) { Viberroo::Input.keyboard(Buttons: [button_one, button_two]) } |
| 67 | + let(:min_api_version) { button_one[:min_api_version] } |
| 68 | + |
| 69 | + it 'sets correct :min_api_version attr in the params root' do |
| 70 | + expect(bot).to receive(:request).with( |
| 71 | + Viberroo::URL::MESSAGE, |
| 72 | + { receiver: response.user_id }.merge(message, keyboard, min_api_version: min_api_version) |
| 73 | + ) |
| 74 | + subject |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + context 'when keyboard contain multiple inputs with different api versions' do |
| 79 | + let(:button_one) { Viberroo::Input.share_phone_button({ min_api_version: 3 }) } |
| 80 | + let(:button_two) { Viberroo::Input.reply_button({ min_api_version: 7 }) } |
| 81 | + let(:keyboard) { Viberroo::Input.keyboard(Buttons: [button_one, button_two]) } |
| 82 | + let(:min_api_version) { button_two[:min_api_version] } |
| 83 | + |
| 84 | + it 'sets correct :min_api_version attr in the params root' do |
| 85 | + expect(bot).to receive(:request).with( |
| 86 | + Viberroo::URL::MESSAGE, |
| 87 | + { receiver: response.user_id }.merge(message, keyboard, min_api_version: min_api_version) |
| 88 | + ) |
| 89 | + subject |
| 90 | + end |
| 91 | + end |
| 92 | + end |
| 93 | + |
10 | 94 | describe 'setting a webhook' do |
11 | 95 | let(:bot) { Viberroo::Bot.new(token: token) } |
12 | 96 | let!(:body) do |
|
0 commit comments