Skip to content

Commit b49a942

Browse files
fix some tests
1 parent 190fb82 commit b49a942

File tree

8 files changed

+82
-211
lines changed

8 files changed

+82
-211
lines changed

test/fileonchain/chunks_test.exs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
defmodule Fileonchain.ChunksTest do
2+
use Fileonchain.DataCase
3+
4+
alias Fileonchain.Chunks
5+
6+
describe "chunks" do
7+
alias Fileonchain.Chunks.Chunk
8+
9+
import Fileonchain.ChunksFixtures
10+
11+
@invalid_attrs %{data: nil, chunk: nil}
12+
13+
test "list_chunks/0 returns all chunks" do
14+
chunk = chunk_fixture()
15+
assert Chunks.list_chunks() == [chunk]
16+
end
17+
18+
test "get_chunk!/1 returns the chunk with given id" do
19+
chunk = chunk_fixture()
20+
assert Chunks.get_chunk!(chunk.id) == chunk
21+
end
22+
23+
test "create_chunk/1 with valid data creates a chunk" do
24+
valid_attrs = %{hash: "some hash", cid: "some cid", data: "some data"}
25+
26+
assert {:ok, %Chunk{} = chunk} = Chunks.create_chunk(valid_attrs)
27+
assert chunk.hash == "some hash"
28+
assert chunk.cid == "some cid"
29+
assert chunk.data == "some data"
30+
end
31+
32+
test "create_chunk/1 with invalid data returns error changeset" do
33+
assert {:error, %Ecto.Changeset{}} = Chunks.create_chunk(@invalid_attrs)
34+
end
35+
end
36+
end

test/fileonchain/cids_test.exs

Lines changed: 0 additions & 61 deletions
This file was deleted.

test/fileonchain/files_test.exs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,5 @@ defmodule Fileonchain.FilesTest do
3131
test "create_file/1 with invalid data returns error changeset" do
3232
assert {:error, %Ecto.Changeset{}} = Files.create_file(@invalid_attrs)
3333
end
34-
35-
test "update_file/2 with valid data updates the file" do
36-
file = file_fixture()
37-
update_attrs = %{data: "some updated data", filename: "some updated filename"}
38-
39-
assert {:ok, %File{} = file} = Files.update_file(file, update_attrs)
40-
assert file.data == "some updated data"
41-
assert file.filename == "some updated filename"
42-
end
43-
44-
test "update_file/2 with invalid data returns error changeset" do
45-
file = file_fixture()
46-
assert {:error, %Ecto.Changeset{}} = Files.update_file(file, @invalid_attrs)
47-
assert file == Files.get_file!(file.id)
48-
end
49-
50-
test "delete_file/1 deletes the file" do
51-
file = file_fixture()
52-
assert {:ok, %File{}} = Files.delete_file(file)
53-
assert_raise Ecto.NoResultsError, fn -> Files.get_file!(file.id) end
54-
end
55-
56-
test "change_file/1 returns a file changeset" do
57-
file = file_fixture()
58-
assert %Ecto.Changeset{} = Files.change_file(file)
59-
end
6034
end
6135
end

test/fileonchain_web/controllers/page_controller_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ defmodule FileonchainWeb.PageControllerTest do
33

44
test "GET /", %{conn: conn} do
55
conn = get(conn, ~p"/")
6-
assert html_response(conn, 200) =~ "Peace of mind from prototype to production"
6+
assert html_response(conn, 200) =~ "Allows anyone to upload small and large files to any substrate network, making them permanently available on-chain ⛓️"
77
end
88
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
defmodule FileonchainWeb.ChunkLiveTest do
2+
use FileonchainWeb.ConnCase
3+
4+
import Phoenix.LiveViewTest
5+
import Fileonchain.ChunksFixtures
6+
7+
@create_attrs %{data: "some data", chunk: "some chunk"}
8+
@update_attrs %{data: "some updated data", chunk: "some updated chunk"}
9+
@invalid_attrs %{data: nil, chunk: nil}
10+
11+
defp create_chunk(_) do
12+
chunk = chunk_fixture()
13+
%{chunk: chunk}
14+
end
15+
16+
describe "Index" do
17+
setup [:create_chunk]
18+
19+
test "lists all chunks", %{conn: conn, chunk: chunk} do
20+
{:ok, _index_live, html} = live(conn, ~p"/chunks")
21+
22+
assert html =~ "Listing Chunks"
23+
assert html =~ chunk.data
24+
end
25+
end
26+
27+
describe "Show" do
28+
setup [:create_chunk]
29+
30+
test "displays chunk", %{conn: conn, chunk: chunk} do
31+
{:ok, _show_live, html} = live(conn, ~p"/chunks/#{chunk}")
32+
33+
assert html =~ "Show Chunk"
34+
assert html =~ chunk.data
35+
end
36+
end
37+
end

test/fileonchain_web/live/cid_live_test.exs

Lines changed: 0 additions & 113 deletions
This file was deleted.

test/fileonchain_web/live/file_live_test.exs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ defmodule FileonchainWeb.FileLiveTest do
55
import Fileonchain.FilesFixtures
66

77
@create_attrs %{data: "some data", filename: "some filename"}
8-
@update_attrs %{data: "some updated data", filename: "some updated filename"}
9-
@invalid_attrs %{data: nil, filename: nil}
8+
# @invalid_attrs %{data: nil, filename: nil}
9+
10+
def fixture(:file) do
11+
{:ok, file} = Fileonchain.Files.create_file(@create_attrs)
12+
file
13+
end
1014

1115
defp create_file(_) do
1216
file = file_fixture()
@@ -68,13 +72,6 @@ defmodule FileonchainWeb.FileLiveTest do
6872
assert html =~ "File updated successfully"
6973
assert html =~ "some updated data"
7074
end
71-
72-
test "deletes file in listing", %{conn: conn, file: file} do
73-
{:ok, index_live, _html} = live(conn, ~p"/files")
74-
75-
assert index_live |> element("#files-#{file.id} a", "Delete") |> render_click()
76-
refute has_element?(index_live, "#files-#{file.id}")
77-
end
7875
end
7976

8077
describe "Show" do

test/support/fixtures/cids_fixtures.ex renamed to test/support/fixtures/chunks_fixtures.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ defmodule Fileonchain.ChunksFixtures do
1111
{:ok, chunk} =
1212
attrs
1313
|> Enum.into(%{
14-
chunk: "some chunk",
14+
hash: "some hash",
15+
cid: "some cid",
1516
data: "some data"
1617
})
1718
|> Fileonchain.Chunks.create_chunk()

0 commit comments

Comments
 (0)