From 0cae20a390bd02dd0d7f2ba4585b2129644855c7 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 4 Dec 2024 09:56:51 +0000 Subject: [PATCH] Add LastFm.Config test It might seem redundant, but helps with refactoring down the line. --- lib/last_fm/config.ex | 4 +--- test/last_fm/config_test.exs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 test/last_fm/config_test.exs diff --git a/lib/last_fm/config.ex b/lib/last_fm/config.ex index 21675219..f69bbf2f 100644 --- a/lib/last_fm/config.ex +++ b/lib/last_fm/config.ex @@ -15,9 +15,7 @@ defmodule LastFm.Config do @spec resolve(atom) :: t def resolve(otp_app) do - app_config = - otp_app - |> Application.get_env(LastFm) + app_config = Application.get_env(otp_app, LastFm) struct(__MODULE__, app_config) end diff --git a/test/last_fm/config_test.exs b/test/last_fm/config_test.exs new file mode 100644 index 00000000..7ce88651 --- /dev/null +++ b/test/last_fm/config_test.exs @@ -0,0 +1,20 @@ +defmodule LastFm.ConfigTest do + use ExUnit.Case, async: true + + describe "resolve/1" do + test "reads data from application configuration" do + assert %LastFm.Config{ + api: LastFm.APIBehaviourMock, + api_key: api_key, + user: user, + auto_refresh: false, + refresh_interval: refresh_interval + } = + LastFm.Config.resolve(:music_library) + + assert is_binary(api_key) + assert is_binary(user) + assert is_integer(refresh_interval) + end + end +end