mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
02372f2076
* added list of tasks to achieve * update deps * update elixir version in CI/CD pipeline * update todo with branch push checks * underscores separation of large numbers * update elixir version and deps * add basic module docs * remove IO.inspect call * check if list is empty rather than traversing list for length * revert empty list code * duration tests * add mime type tests * use logger instread of inspect, remove todos * replace list length check with Enum.empty * replace list length check with !Enum.empty? * numbers readability fix by using underscores on large numbers * iucn parser replaced case with multiclause function and added test * replace map and join with map_join * fix multiple spec issues where map() must be inside a list
82 lines
3.5 KiB
Elixir
82 lines
3.5 KiB
Elixir
defmodule PlantIdDiscordBotTest.PlantNet.Parser do
|
||
alias PlantIdDiscordBot.PlantNet.Parser
|
||
use ExUnit.Case
|
||
|
||
doctest PlantIdDiscordBot.PlantNet.Parser
|
||
|
||
test "to_map" do
|
||
result =
|
||
PlantNetFixtures.raw_response()
|
||
|> Parser.to_map!()
|
||
|
||
assert result == PlantNetFixtures.parsed_response()
|
||
end
|
||
|
||
test "filter by score" do
|
||
result =
|
||
PlantNetFixtures.parsed_response() |> Parser.filter_by_score()
|
||
|
||
assert result == PlantNetFixtures.parsed_response_filtered_by_score()
|
||
end
|
||
|
||
test "add_external_urls" do
|
||
result =
|
||
PlantNetFixtures.parsed_response_filtered_by_score()
|
||
|> Parser.add_external_urls()
|
||
|
||
assert result == PlantNetFixtures.parsed_response_with_urls()
|
||
end
|
||
|
||
test "no iucn data prevents 'Conservation Status' from being shown in response message" do
|
||
message =
|
||
PlantNetFixtures.parsed_response_with_urls_no_iucn()
|
||
|> Parser.generate_response_message()
|
||
|
||
refute String.contains?(message, "Conservation status: ")
|
||
end
|
||
|
||
describe "message paragraph spacing" do
|
||
test "iucn data plus alternatives" do
|
||
message =
|
||
PlantNetFixtures.parsed_response_with_urls()
|
||
|> Parser.generate_response_message()
|
||
|
||
assert message ==
|
||
"My best guess is **Prunus cerasifera** with a confidence of **88%**. Common names include **Cherry plum, myrobalan, Cherry Plum, Purple-leaf Plum**.\n\nSpecies info from plant databases:\n[GBIF](<https://www.gbif.org/species/3021730>) | [PFAF](<https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera>) | [POWO](<https://powo.science.kew.org/taxon/729568-1>)\n\nConservation status: Data Deficient\n\nAlternatives include **Prunus × cistena**."
|
||
end
|
||
|
||
test "no iucn data" do
|
||
message =
|
||
PlantNetFixtures.parsed_response_with_urls_no_iucn()
|
||
|> Parser.generate_response_message()
|
||
|
||
assert message ==
|
||
"My best guess is **Prunus cerasifera** with a confidence of **88%**. Common names include **Cherry plum, myrobalan, Cherry Plum, Purple-leaf Plum**.\n\nSpecies info from plant databases:\n[GBIF](<https://www.gbif.org/species/3021730>) | [PFAF](<https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera>) | [POWO](<https://powo.science.kew.org/taxon/729568-1>)\n\nAlternatives include **Prunus × cistena**."
|
||
end
|
||
|
||
test "no common names" do
|
||
message =
|
||
PlantNetFixtures.parsed_response_with_urls_no_alternatives()
|
||
|> Parser.generate_response_message()
|
||
|
||
assert message ==
|
||
"My best guess is **Prunus cerasifera** with a confidence of **88%**.\n\nSpecies info from plant databases:\n[GBIF](<https://www.gbif.org/species/3021730>) | [PFAF](<https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera>) | [POWO](<https://powo.science.kew.org/taxon/729568-1>)\n\nConservation status: Data Deficient\n\nAlternatives include **Prunus × cistena**."
|
||
end
|
||
end
|
||
|
||
describe "iucn_parser/1" do
|
||
test "return correct string for abbreviation" do
|
||
assert Parser.iucn_parser("DD") == "Data Deficient"
|
||
assert Parser.iucn_parser("LC") == "Least Concern"
|
||
assert Parser.iucn_parser("NT") == "Near Threatened"
|
||
assert Parser.iucn_parser("VU") == "Vulnerable"
|
||
assert Parser.iucn_parser("EN") == "Endangered"
|
||
assert Parser.iucn_parser("CR") == "Critically Endangered"
|
||
assert Parser.iucn_parser("EW") == "Extinct in the Wild"
|
||
assert Parser.iucn_parser("EX") == "Extinct"
|
||
assert Parser.iucn_parser("NE") == "Not Evaluated"
|
||
assert Parser.iucn_parser("ABC") == "Unknown"
|
||
end
|
||
end
|
||
end
|