Leon4gr45 commited on
Commit
7f57f39
·
verified ·
1 Parent(s): 857650d

Delete test/plausible_web/plugins/api/errors_test.exs with huggingface_hub

Browse files
test/plausible_web/plugins/api/errors_test.exs DELETED
@@ -1,75 +0,0 @@
1
- defmodule PlausibleWeb.Plugins.API.ErrorsTest do
2
- use ExUnit.Case, async: true
3
-
4
- import Phoenix.ConnTest, only: [json_response: 2]
5
-
6
- alias PlausibleWeb.Plugins.API.Errors
7
-
8
- describe "unauthorized/1" do
9
- test "sends an 401 response with the `www-authenticate` header set" do
10
- conn =
11
- Plug.Test.conn(:get, "/")
12
- |> Errors.unauthorized()
13
-
14
- assert conn.halted
15
-
16
- assert json_response(conn, 401) == %{
17
- "errors" => [%{"detail" => "Plugins API: unauthorized"}]
18
- }
19
-
20
- assert Plug.Conn.get_resp_header(conn, "www-authenticate") == [
21
- ~s[Basic realm="Plugins API Access"]
22
- ]
23
- end
24
- end
25
-
26
- describe "error/3" do
27
- test "formats the given error message" do
28
- message = "Some message"
29
-
30
- conn =
31
- Plug.Test.conn(:get, "/")
32
- |> Errors.error(:forbidden, message)
33
-
34
- assert conn.halted
35
-
36
- assert json_response(conn, 403) == %{
37
- "errors" => [%{"detail" => "Some message"}]
38
- }
39
- end
40
-
41
- defmodule Example do
42
- use Ecto.Schema
43
- import Ecto.Changeset
44
-
45
- schema "" do
46
- field(:name)
47
- field(:email)
48
- field(:age, :integer)
49
- end
50
-
51
- def changeset(example, params \\ %{}) do
52
- example
53
- |> cast(params, [:name, :email, :age])
54
- |> validate_required([:name, :email])
55
- |> validate_format(:email, ~r/@/)
56
- |> validate_inclusion(:age, 18..100)
57
- end
58
- end
59
-
60
- test "formats changeset errors" do
61
- changeset = Example.changeset(%Example{}, %{email: "foo", age: 101})
62
-
63
- errors =
64
- Plug.Test.conn(:get, "/")
65
- |> Errors.error(:bad_request, changeset)
66
- |> json_response(400)
67
- |> Map.fetch!("errors")
68
-
69
- assert Enum.count(errors) == 3
70
- assert %{"detail" => "age: is invalid"} in errors
71
- assert %{"detail" => "email: has invalid format"} in errors
72
- assert %{"detail" => "name: can't be blank"} in errors
73
- end
74
- end
75
- end