mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
Feature/projects (#18)
* add up to 5 attachments * multiclause function event handler * fix incorrect Cog calls * add default param as "all" so we can start differentiating the types of identifications in the future - projects / diseases * abstract message sending * overwrite global application commands * pass message from projects to message sending and id functions
This commit is contained in:
+86
-1
@@ -1,5 +1,90 @@
|
||||
defmodule PlantIdDiscordBotTest.Cog do
|
||||
use ExUnit.Case
|
||||
use ExUnit.Case, async: true
|
||||
doctest PlantIdDiscordBot.Cog.Info
|
||||
doctest PlantIdDiscordBot.Cog.PlantNetMessage
|
||||
|
||||
alias PlantIdDiscordBot.Cog.PlantNetMessage
|
||||
|
||||
@plantnet_api_base_url Application.compile_env(:plantid_discord_bot, :plantnet_api_base_url)
|
||||
@plantnet_api_key Application.compile_env(:plantid_discord_bot, :plantnet_api_key)
|
||||
@image_filenames ["image1.jpg", "image2.jpg", "image3.jpg"]
|
||||
|
||||
describe "build_query_uri/2" do
|
||||
test "all" do
|
||||
uri = PlantNetMessage.build_query_uri(@image_filenames, "all")
|
||||
|
||||
test_uri =
|
||||
@image_filenames
|
||||
|> Enum.reduce(
|
||||
URI.parse("#{@plantnet_api_base_url}/identify/all")
|
||||
|> URI.append_query("api-key=#{@plantnet_api_key}"),
|
||||
fn filename, acc ->
|
||||
URI.append_query(acc, "images=#{filename}")
|
||||
end
|
||||
)
|
||||
|> URI.append_query("nb-results=5")
|
||||
|> URI.append_query("type=kt")
|
||||
|> URI.to_string()
|
||||
|
||||
assert uri == test_uri
|
||||
end
|
||||
|
||||
test "diseases" do
|
||||
uri = PlantNetMessage.build_query_uri(@image_filenames, "diseases")
|
||||
|
||||
test_uri =
|
||||
@image_filenames
|
||||
|> Enum.reduce(
|
||||
URI.parse("#{@plantnet_api_base_url}/diseases/identify")
|
||||
|> URI.append_query("api-key=#{@plantnet_api_key}"),
|
||||
fn filename, acc ->
|
||||
URI.append_query(acc, "images=#{filename}")
|
||||
end
|
||||
)
|
||||
|> URI.append_query("nb-results=5")
|
||||
|> URI.append_query("type=kt")
|
||||
|> URI.to_string()
|
||||
|
||||
assert uri == test_uri
|
||||
end
|
||||
|
||||
test "projects" do
|
||||
uri =
|
||||
PlantNetMessage.build_query_uri(@image_filenames, %{name: "projects", id: "project-id"})
|
||||
|
||||
test_uri =
|
||||
@image_filenames
|
||||
|> Enum.reduce(
|
||||
URI.parse("#{@plantnet_api_base_url}/identify/project-id")
|
||||
|> URI.append_query("api-key=#{@plantnet_api_key}"),
|
||||
fn filename, acc ->
|
||||
URI.append_query(acc, "images=#{filename}")
|
||||
end
|
||||
)
|
||||
|> URI.append_query("nb-results=5")
|
||||
|> URI.append_query("type=kt")
|
||||
|> URI.to_string()
|
||||
|
||||
assert uri == test_uri
|
||||
end
|
||||
|
||||
test "default" do
|
||||
uri = PlantNetMessage.build_query_uri(@image_filenames, "all")
|
||||
|
||||
test_uri =
|
||||
@image_filenames
|
||||
|> Enum.reduce(
|
||||
URI.parse("#{@plantnet_api_base_url}/identify/all")
|
||||
|> URI.append_query("api-key=#{@plantnet_api_key}"),
|
||||
fn filename, acc ->
|
||||
URI.append_query(acc, "images=#{filename}")
|
||||
end
|
||||
)
|
||||
|> URI.append_query("nb-results=5")
|
||||
|> URI.append_query("type=kt")
|
||||
|> URI.to_string()
|
||||
|
||||
assert uri == test_uri
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,12 +4,12 @@ defmodule PlantIdDiscordBot.ErrorHandlingTest do
|
||||
|
||||
@guild Application.compile_env(:plantid_discord_bot, :guild)
|
||||
|
||||
test "do_identification/1 returns invokes logger on error" do
|
||||
test "do_identification/2 returns invokes logger on error" do
|
||||
message = PlantNetFixtures.Message.message()
|
||||
|
||||
log =
|
||||
capture_log(fn ->
|
||||
PlantIdDiscordBot.Cog.PlantNetMessage.do_identification(message)
|
||||
PlantIdDiscordBot.Cog.PlantNetMessage.do_identification(message, "all")
|
||||
|
||||
assert_received {:create_message, 123_456,
|
||||
content: "An error has occured. Please try again later."}
|
||||
|
||||
Reference in New Issue
Block a user