|
@@ -132,6 +132,16 @@ describe Agents::TelegramAgent do
|
|
|
expect(@sent_messages).to eq([{ video: { chat_id: 'xxxxxxxx', video: 'https://example.com/video.avi' } }])
|
|
|
end
|
|
|
|
|
|
+ it 'accepts group key and uses :send_media_group to send the file' do
|
|
|
+ event = event_with_payload group: [{ type: 'photo', media: 'https://example.com/photo1.jpg' }, { type: 'photo', media: 'https://example.com/photo2.jpg' }]
|
|
|
+ @checker.receive [event]
|
|
|
+
|
|
|
+ expect(@sent_messages).to eq([{ group: { chat_id: 'xxxxxxxx',
|
|
|
+ media: [{ 'type' => 'photo', 'media' => 'https://example.com/photo1.jpg' },
|
|
|
+ { 'type' => 'photo', 'media' => 'https://example.com/photo2.jpg' }]
|
|
|
+ } }])
|
|
|
+ end
|
|
|
+
|
|
|
it 'creates a log entry when no key of the received event was useable' do
|
|
|
event = event_with_payload test: '1234'
|
|
|
expect {
|
|
@@ -140,10 +150,10 @@ describe Agents::TelegramAgent do
|
|
|
end
|
|
|
end
|
|
|
|
|
|
- it 'creates and error log if the request fails' do
|
|
|
+ it 'creates an error log if the request fails' do
|
|
|
event = event_with_payload text: 'hello'
|
|
|
stub_request(:post, "https://api.telegram.org/botxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/sendMessage").
|
|
|
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
|
+ with(headers: {'Content-type'=>'application/json'}).
|
|
|
to_return(status: 200, body: '{"ok": false}', headers: {'Content-Type' => 'application/json'})
|
|
|
|
|
|
expect {
|
|
@@ -165,7 +175,7 @@ describe Agents::TelegramAgent do
|
|
|
describe '#complete_chat_id' do
|
|
|
it 'returns a list of all recents chats, groups and channels' do
|
|
|
stub_request(:post, "https://api.telegram.org/botxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getUpdates").
|
|
|
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
|
+ with(headers: {}).
|
|
|
to_return(status: 200, body: '{"ok":true,"result":[{"update_id":252965475,"message":{"message_id":15,"from":{"id":97201077,"is_bot":false,"first_name":"Dominik","last_name":"Sander","language_code":"en-US"},"chat":{"id":97201077,"first_name":"Dominik","last_name":"Sander","type":"private"},"date":1506774710,"text":"test"}},{"update_id":252965476,"channel_post":{"message_id":4,"chat":{"id":-1001144599139,"title":"Much channel","type":"channel"},"date":1506782283,"text":"channel"}},{"update_id":252965477,"message":{"message_id":18,"from":{"id":97201077,"is_bot":false,"first_name":"Dominik","last_name":"Sander","language_code":"en-US"},"chat":{"id":-217850512,"title":"Just a test","type":"group","all_members_are_administrators":true},"date":1506782504,"left_chat_participant":{"id":136508315,"is_bot":true,"first_name":"Huginn","username":"HuginnNotificationBot"},"left_chat_member":{"id":136508315,"is_bot":true,"first_name":"Huginn","username":"HuginnNotificationBot"}}}]}', headers: {'Content-Type' => 'application/json'})
|
|
|
|
|
|
expect(@checker.complete_chat_id).to eq([{:id=>97201077, :text=>"Dominik Sander"},
|
|
@@ -177,7 +187,7 @@ describe Agents::TelegramAgent do
|
|
|
describe '#validate_auth_token' do
|
|
|
it 'returns true if the token is valid' do
|
|
|
stub_request(:post, "https://api.telegram.org/botxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getMe").
|
|
|
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
|
+ with(headers: {}).
|
|
|
to_return(status: 200, body: '{"ok": true}', headers: {'Content-Type' => 'application/json'})
|
|
|
|
|
|
expect(@checker.validate_auth_token).to be_truthy
|
|
@@ -185,7 +195,7 @@ describe Agents::TelegramAgent do
|
|
|
|
|
|
it 'returns false if the token is invalid' do
|
|
|
stub_request(:post, "https://api.telegram.org/botxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getMe").
|
|
|
- with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
|
|
+ with(headers: {}).
|
|
|
to_return(status: 200, body: "{}")
|
|
|
|
|
|
expect(@checker.validate_auth_token).to be_falsy
|