basic error handling test

This commit is contained in:
Owen
2025-01-15 21:56:45 +01:00
committed by Owen Rees
parent 1a27b2bdb7
commit 8da0f33faa
7 changed files with 33 additions and 8 deletions
+13 -2
View File
@@ -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