diff --git a/test/mindwendel_web/controllers/file_controller_test.exs b/test/mindwendel_web/controllers/file_controller_test.exs new file mode 100644 index 00000000..5945cc36 --- /dev/null +++ b/test/mindwendel_web/controllers/file_controller_test.exs @@ -0,0 +1,23 @@ +defmodule MindwendelWeb.FileControllerTest do + use MindwendelWeb.ConnCase + alias Mindwendel.Services.Vault + alias Mindwendel.Factory + + @file_dest Path.join("priv/static/uploads", "encrypted-test.jpg") + + describe "get_file" do + setup do + {:ok, encrypted_file} = Vault.encrypt("test") + File.write(@file_dest, encrypted_file) + + on_exit(fn -> File.rm(@file_dest) end) + :ok + end + + test "successfully retrieves an existing file", %{conn: conn} do + file = Factory.insert!(:file, path: "/uploads/encrypted-test.jpg", name: "test.jpg") + + assert get(conn, ~p"/files/#{file.id}").resp_body == "test" + end + end +end