-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RTC-419] Standardise Jellyfish API test (#134)
* New component tests draft * Add custom functions for assertions * Better errors WIP * Check for missing parameters
- Loading branch information
Showing
12 changed files
with
482 additions
and
442 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
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
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
67 changes: 67 additions & 0 deletions
67
test/jellyfish_web/controllers/component/file_component_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,67 @@ | ||
defmodule JellyfishWeb.Component.FileComponentTest do | ||
use JellyfishWeb.ConnCase | ||
use JellyfishWeb.ComponentCase | ||
|
||
@file_component_directory "file_component_sources" | ||
@file_component_source "video.h264" | ||
|
||
setup _tags do | ||
media_sources_directory = | ||
Application.fetch_env!(:jellyfish, :media_files_path) | ||
|> Path.join(@file_component_directory) | ||
|> Path.expand() | ||
|
||
File.mkdir_p!(media_sources_directory) | ||
|
||
media_sources_directory | ||
|> Path.join(@file_component_source) | ||
|> File.touch!() | ||
|
||
{:ok, %{}} | ||
end | ||
|
||
describe "Create File Component" do | ||
test "renders component with required options", %{conn: conn, room_id: room_id} do | ||
conn = | ||
post(conn, ~p"/room/#{room_id}/component", | ||
type: "file", | ||
options: %{filePath: @file_component_source} | ||
) | ||
|
||
assert %{ | ||
"data" => %{ | ||
"id" => id, | ||
"type" => "file", | ||
"properties" => %{} | ||
} | ||
} = | ||
model_response(conn, :created, "ComponentDetailsResponse") | ||
|
||
assert_component_created(conn, room_id, id, "file") | ||
end | ||
|
||
test "renders error when required options are missing", %{ | ||
conn: conn, | ||
room_id: room_id | ||
} do | ||
conn = post(conn, ~p"/room/#{room_id}/component", type: "file") | ||
|
||
assert model_response(conn, :bad_request, "Error")["errors"] == | ||
"Required field \"filePath\" missing" | ||
end | ||
|
||
test "renders error when filePath is invalid", %{ | ||
conn: conn, | ||
room_id: room_id | ||
} do | ||
conn = | ||
post(conn, ~p"/room/#{room_id}/component", | ||
type: "file", | ||
options: %{filePath: "some/fake/path.h264"} | ||
) | ||
|
||
assert model_response(conn, :not_found, "Error")["errors"] == | ||
"File not found" | ||
end | ||
end | ||
end |
Oops, something went wrong.