telegram-bot
telegram-bot copied to clipboard
How to rspec a incoming voice message
@printercu I am trying since a while to write a working rspec test for an incoming voice message:
it "processes the voice message" do
dispatch_message(nil, {
"voice" => { "file_id" => "file123" },
"from" => from,
"chat" => { "id" => 123 },
})
messages = bot.requests[:sendMessage].map { |req| req[:text] }
Same goes for unsupported types - basically everything which is not just a plain message:
describe "#unsupported_payload_type" do
subject {
-> {
dispatch({
"unsupported_type" => true,
"message" => {
"chat" => { "id" => 123 },
"from" => { "id" => 123, "username" => "testuser" },
},
})
}
}
before do
allow(I18n).to receive(:t).with("telegram.errors.unsupported_type").and_return("Unsupported type")
allow(I18n).to receive(:t).with("telegram.errors.general").and_return("An error occurred. Try again later.")
end
it "responds with an unsupported type message" do
subject.call
expect(bot.requests[:sendMessage].last[:text]).to eq("Unsupported type")
end
end
That doesn't seem to work correctly. Any ideas/Hints?
What issue do you have with voice message?
Regarding unsupported type: this update is invalid. Update must have only one item, but in your examples there are unsupported_type and message.
@printercu Fixed it, correct code:
subject {
-> {
dispatch({
'unknown_update_type' => {
'from' => { 'id' => 123, 'username' => 'testuser' },
'chat' => { 'id' => 123 },
# Include any other necessary fields
},
})
}
}
Thanks for the help!