mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-22 20:16:57 +00:00
basic error handling test
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
defmodule PlantIdDiscordBot.ErrorHandlingTest do
|
||||
use ExUnit.Case
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
test "do_identification/1 returns nil when an error occurs" do
|
||||
@guild Application.compile_env(:plantid_discord_bot, :guild)
|
||||
|
||||
test "do_identification/1 returns invokes logger on error" do
|
||||
message = PlantNetFixtures.Message.message()
|
||||
PlantIdDiscordBot.Cog.PlantNetMessage.do_identification(message)
|
||||
|
||||
log = capture_log(fn ->
|
||||
PlantIdDiscordBot.Cog.PlantNetMessage.do_identification(message)
|
||||
|
||||
assert_received {:create_message, 123456, content: "An error has occured. Please try again later."}
|
||||
end)
|
||||
|
||||
assert log =~ "guild_id=#{message.guild_id}"
|
||||
assert log =~ "guild_name=#{@guild.get_guild_name!(message.guild_id)}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,9 @@ ExUnit.start()
|
||||
|
||||
defmodule PlantNetFixtures.Message do
|
||||
@message %{
|
||||
guild_id: 1_002_507_312_159_797_318
|
||||
channel_id: 1178600825380155412,
|
||||
guild_id: 1_002_507_312_159_797_318,
|
||||
attachments: [%{url: "http://invalid-url.com/image.jpg"}],
|
||||
}
|
||||
|
||||
def message(), do: @message
|
||||
|
||||
Reference in New Issue
Block a user