diff options
author | neodarz <neodarz@neodarz.net> | 2017-02-06 16:52:00 +0100 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2017-02-06 16:52:00 +0100 |
commit | 120bf89930ce7e136ba0b0499bce7b0f8b95f296 (patch) | |
tree | d86d7320d75f33fac32b897277296f5a6c80e645 /test | |
parent | 663d70f2d9d917ac5f89faebc289a664b7dcc22a (diff) | |
download | the_transcriber_backend-120bf89930ce7e136ba0b0499bce7b0f8b95f296.tar.xz the_transcriber_backend-120bf89930ce7e136ba0b0499bce7b0f8b95f296.zip |
Add a not secure function for upload files with curl
Diffstat (limited to 'test')
-rw-r--r-- | test/controllers/audio_file_api_controller_test.exs | 60 | ||||
-rw-r--r-- | test/models/audio_file_api_test.exs | 18 |
2 files changed, 78 insertions, 0 deletions
diff --git a/test/controllers/audio_file_api_controller_test.exs b/test/controllers/audio_file_api_controller_test.exs new file mode 100644 index 0000000..af08cd7 --- /dev/null +++ b/test/controllers/audio_file_api_controller_test.exs @@ -0,0 +1,60 @@ +defmodule TheTranscriberBackend.AudioFileAPIControllerTest do + use TheTranscriberBackend.ConnCase + + alias TheTranscriberBackend.AudioFileAPI + @valid_attrs %{} + @invalid_attrs %{} + + setup %{conn: conn} do + {:ok, conn: put_req_header(conn, "accept", "application/json")} + end + + test "lists all entries on index", %{conn: conn} do + conn = get conn, audio_file_api_path(conn, :index) + assert json_response(conn, 200)["data"] == [] + end + + test "shows chosen resource", %{conn: conn} do + audio_file_api = Repo.insert! %AudioFileAPI{} + conn = get conn, audio_file_api_path(conn, :show, audio_file_api) + assert json_response(conn, 200)["data"] == %{"id" => audio_file_api.id, + "audio_path_id" => audio_file_api.audio_path_id} + end + + test "renders page not found when id is nonexistent", %{conn: conn} do + assert_error_sent 404, fn -> + get conn, audio_file_api_path(conn, :show, -1) + end + end + + test "creates and renders resource when data is valid", %{conn: conn} do + conn = post conn, audio_file_api_path(conn, :create), audio_file_api: @valid_attrs + assert json_response(conn, 201)["data"]["id"] + assert Repo.get_by(AudioFileAPI, @valid_attrs) + end + + test "does not create resource and renders errors when data is invalid", %{conn: conn} do + conn = post conn, audio_file_api_path(conn, :create), audio_file_api: @invalid_attrs + assert json_response(conn, 422)["errors"] != %{} + end + + test "updates and renders chosen resource when data is valid", %{conn: conn} do + audio_file_api = Repo.insert! %AudioFileAPI{} + conn = put conn, audio_file_api_path(conn, :update, audio_file_api), audio_file_api: @valid_attrs + assert json_response(conn, 200)["data"]["id"] + assert Repo.get_by(AudioFileAPI, @valid_attrs) + end + + test "does not update chosen resource and renders errors when data is invalid", %{conn: conn} do + audio_file_api = Repo.insert! %AudioFileAPI{} + conn = put conn, audio_file_api_path(conn, :update, audio_file_api), audio_file_api: @invalid_attrs + assert json_response(conn, 422)["errors"] != %{} + end + + test "deletes chosen resource", %{conn: conn} do + audio_file_api = Repo.insert! %AudioFileAPI{} + conn = delete conn, audio_file_api_path(conn, :delete, audio_file_api) + assert response(conn, 204) + refute Repo.get(AudioFileAPI, audio_file_api.id) + end +end diff --git a/test/models/audio_file_api_test.exs b/test/models/audio_file_api_test.exs new file mode 100644 index 0000000..028befa --- /dev/null +++ b/test/models/audio_file_api_test.exs @@ -0,0 +1,18 @@ +defmodule TheTranscriberBackend.AudioFileAPITest do + use TheTranscriberBackend.ModelCase + + alias TheTranscriberBackend.AudioFileAPI + + @valid_attrs %{} + @invalid_attrs %{} + + test "changeset with valid attributes" do + changeset = AudioFileAPI.changeset(%AudioFileAPI{}, @valid_attrs) + assert changeset.valid? + end + + test "changeset with invalid attributes" do + changeset = AudioFileAPI.changeset(%AudioFileAPI{}, @invalid_attrs) + refute changeset.valid? + end +end |