aboutsummaryrefslogtreecommitdiff
path: root/test/controllers/audio_file_controller_test.exs
blob: 8c2b9d6c51d9bde8ef29cbcc79d66ff3413491d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
defmodule TheTranscriberBackend.AudioFileControllerTest do
  use TheTranscriberBackend.ConnCase

  alias TheTranscriberBackend.AudioFile
  @valid_attrs %{audio_duration: "some content", audio_path: "some content", audio_name: "some content"}
  @invalid_attrs %{}

  test "lists all entries on index", %{conn: conn} do
    conn = get conn, audio_file_path(conn, :index)
    assert html_response(conn, 200) =~ "Listing audio file"
  end

  test "renders form for new resources", %{conn: conn} do
    conn = get conn, audio_file_path(conn, :new)
    assert html_response(conn, 200) =~ "New audio file"
  end

  test "creates resource and redirects when data is valid", %{conn: conn} do
    conn = post conn, audio_file_path(conn, :create), audio_file: @valid_attrs
    assert redirected_to(conn) == audio_file_path(conn, :index)
    assert Repo.get_by(AudioFile, @valid_attrs)
  end

  test "does not create resource and renders errors when data is invalid", %{conn: conn} do
    conn = post conn, audio_file_path(conn, :create), audio_file: @invalid_attrs
    assert html_response(conn, 200) =~ "New audio file"
  end

  test "shows chosen resource", %{conn: conn} do
    audio_file = Repo.insert! %AudioFile{}
    conn = get conn, audio_file_path(conn, :show, audio_file)
    assert html_response(conn, 200) =~ "Show audio file"
  end

  test "renders page not found when id is nonexistent", %{conn: conn} do
    assert_error_sent 404, fn ->
      get conn, audio_file_path(conn, :show, -1)
    end
  end

  test "renders form for editing chosen resource", %{conn: conn} do
    audio_file = Repo.insert! %AudioFile{}
    conn = get conn, audio_file_path(conn, :edit, audio_file)
    assert html_response(conn, 200) =~ "Edit audio file"
  end

  test "updates chosen resource and redirects when data is valid", %{conn: conn} do
    audio_file = Repo.insert! %AudioFile{}
    conn = put conn, audio_file_path(conn, :update, audio_file), audio_file: @valid_attrs
    assert redirected_to(conn) == audio_file_path(conn, :show, audio_file)
    assert Repo.get_by(AudioFile, @valid_attrs)
  end

  test "does not update chosen resource and renders errors when data is invalid", %{conn: conn} do
    audio_file = Repo.insert! %AudioFile{}
    conn = put conn, audio_file_path(conn, :update, audio_file), audio_file: @invalid_attrs
    assert html_response(conn, 200) =~ "Edit audio file"
  end

  test "deletes chosen resource", %{conn: conn} do
    audio_file = Repo.insert! %AudioFile{}
    conn = delete conn, audio_file_path(conn, :delete, audio_file)
    assert redirected_to(conn) == audio_file_path(conn, :index)
    refute Repo.get(AudioFile, audio_file.id)
  end
end