-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
143 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
test/screens_web/controllers/v2/screen_api_controller_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
defmodule ScreensWeb.V2.ScreenApiControllerTest do | ||
use ScreensWeb.ConnCase | ||
|
||
alias ScreensConfig.Screen | ||
alias Screens.TestSupport.CandidateGeneratorStub, as: Stub | ||
|
||
import Screens.Inject | ||
import Mox | ||
setup :verify_on_exit! | ||
|
||
@cache injected(Screens.Config.Cache) | ||
@parameters injected(Screens.V2.ScreenData.Parameters) | ||
|
||
require Stub | ||
|
||
Stub.candidate_generator(MercuryGenerator, fn _ -> [placeholder(:green)] end) | ||
Stub.candidate_generator(LgMriGenerator, fn _ -> [placeholder(:red)] end) | ||
|
||
describe "show/2" do | ||
test "only returns flex_zone for Mercury screens", %{conn: conn} do | ||
expect(@cache, :screen, fn | ||
"EIG-604" -> | ||
struct(Screen, app_id: :gl_eink_v2, vendor: :mercury) | ||
end) | ||
|
||
expect(@parameters, :variants, fn _ -> [nil] end) | ||
|
||
stub( | ||
@parameters, | ||
:candidate_generator, | ||
fn %Screen{vendor: :mercury}, nil -> MercuryGenerator end | ||
) | ||
|
||
stub(@parameters, :refresh_rate, fn _app_id -> 0 end) | ||
|
||
conn = get(conn, "/v2/api/screen/EIG-604?last_refresh=2024-12-02T00:00:00Z") | ||
|
||
assert %{ | ||
"audio_data" => "", | ||
"data" => %{ | ||
"main" => %{"color" => "green", "type" => "placeholder"}, | ||
"type" => "normal" | ||
}, | ||
"disabled" => false, | ||
"flex_zone" => [], | ||
"force_reload" => false, | ||
"last_deploy_timestamp" => nil | ||
} == json_response(conn, 200) | ||
end | ||
|
||
test "omits flex_zone from non-Mercury screens", %{conn: conn} do | ||
expect(@cache, :screen, fn | ||
"1401" -> | ||
struct(Screen, app_id: :bus_shelter_v2, vendor: :lg_mri) | ||
end) | ||
|
||
expect(@parameters, :variants, fn _ -> [nil] end) | ||
|
||
stub( | ||
@parameters, | ||
:candidate_generator, | ||
fn %Screen{vendor: :lg_mri}, nil -> LgMriGenerator end | ||
) | ||
|
||
stub(@parameters, :refresh_rate, fn _app_id -> 0 end) | ||
|
||
conn = get(conn, "/v2/api/screen/1401?last_refresh=2024-12-02T00:00:00Z") | ||
|
||
assert %{ | ||
"data" => %{ | ||
"main" => %{"color" => "red", "type" => "placeholder"}, | ||
"type" => "normal" | ||
}, | ||
"disabled" => false, | ||
"force_reload" => false | ||
} == json_response(conn, 200) | ||
end | ||
end | ||
end |