-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathintegration_test.exs
More file actions
88 lines (65 loc) · 2.63 KB
/
Copy pathintegration_test.exs
File metadata and controls
88 lines (65 loc) · 2.63 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
defmodule DiffWeb.IntegrationTest do
use DiffWeb.ConnCase
import Phoenix.LiveViewTest
import Mox
describe "route integration tests" do
setup :verify_on_exit!
test "root route renders search page", %{conn: conn} do
{:ok, _view, html} = live(conn, "/")
assert html =~ ~s(class="search-input")
assert html =~ "Search..."
end
test "/diffs route with query parameters", %{conn: conn} do
{:ok, _view, html} = live(conn, "/diffs?diffs[]=phoenix:1.4.5:1.4.9")
assert html =~ "Package Diffs"
assert html =~ "phoenix"
assert html =~ "1.4.5 → 1.4.9"
end
test "/diff with implicit latest version resolution", %{conn: conn} do
versions = ["1.4.5", "1.4.9", "1.5.0-rc.2"]
Diff.Package.StoreMock
|> stub(:get_versions, fn "phoenix" -> {:ok, versions} end)
Diff.StorageMock
|> stub(:get_metadata, fn "phoenix", "1.4.5", "1.4.9" ->
{:error, :not_found}
end)
Diff.HexMock
|> stub(:diff, fn "phoenix", "1.4.5", "1.4.9" -> :error end)
{:ok, _view, html} = live(conn, "/diff/phoenix/1.4.5..")
# Should show generating state since we're resolving to latest version
assert html =~ "Generating diffs"
end
test "/diff with implicit latest handles packages without stable versions", %{conn: conn} do
Diff.Package.StoreMock
|> stub(:get_versions, fn "prerelease_only" ->
{:ok, ["1.0.0-alpha.1", "1.0.0-rc.1", "1.0.0-rc.2"]}
end)
Diff.StorageMock
|> stub(:get_metadata, fn "prerelease_only", "0.1.0", "1.0.0-rc.2" ->
{:error, :not_found}
end)
Diff.HexMock
|> stub(:diff, fn "prerelease_only", "0.1.0", "1.0.0-rc.2" -> :error end)
{:ok, _view, html} = live(conn, "/diff/prerelease_only/0.1.0..")
assert html =~ "Generating diffs"
end
test "/diff with implicit latest handles packages with an empty version list", %{conn: conn} do
Diff.Package.StoreMock
|> stub(:get_versions, fn "empty" -> {:ok, []} end)
{:ok, _view, html} = live(conn, "/diff/empty/0.1.0..")
assert html =~ "No versions found for package: empty"
end
test "/diff handles package not found", %{conn: conn} do
Diff.Package.StoreMock
|> stub(:get_versions, fn "nonexistent" -> {:error, :not_found} end)
Diff.StorageMock
|> stub(:get_metadata, fn "nonexistent", "1.0.0", "2.0.0" ->
{:error, :not_found}
end)
Diff.HexMock
|> stub(:diff, fn "nonexistent", "1.0.0", "2.0.0" -> :error end)
{:ok, _view, html} = live(conn, "/diff/nonexistent/1.0.0..2.0.0")
assert html =~ "Generating diffs"
end
end
end