Skip to content

Commit 348e70e

Browse files
committed
Run tests reyling in superadmin guard on EE only
1 parent d308ed0 commit 348e70e

1 file changed

Lines changed: 114 additions & 111 deletions

File tree

Lines changed: 114 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,135 @@
11
defmodule PlausibleWeb.Api.StatsController.ExplorationTest do
22
use PlausibleWeb.ConnCase, async: false
3+
use Plausible
34

4-
setup [:create_user, :log_in, :create_site]
5+
on_ee do
6+
setup [:create_user, :log_in, :create_site]
57

6-
setup %{user: user, site: site} do
7-
patch_env(:super_admin_user_ids, [user.id])
8+
setup %{user: user, site: site} do
9+
patch_env(:super_admin_user_ids, [user.id])
810

9-
now = DateTime.utc_now()
11+
now = DateTime.utc_now()
1012

11-
populate_stats(site, [
12-
build(:pageview,
13-
user_id: 123,
14-
pathname: "/home",
15-
timestamp: DateTime.shift(now, minute: -300)
16-
),
17-
build(:pageview,
18-
user_id: 123,
19-
pathname: "/login",
20-
timestamp: DateTime.shift(now, minute: -270)
21-
),
22-
build(:pageview,
23-
user_id: 123,
24-
pathname: "/home",
25-
timestamp: DateTime.shift(now, minute: -30)
26-
),
27-
build(:pageview,
28-
user_id: 123,
29-
pathname: "/login",
30-
timestamp: DateTime.shift(now, minute: -25)
31-
),
32-
build(:pageview,
33-
user_id: 123,
34-
pathname: "/logout",
35-
timestamp: DateTime.shift(now, minute: -20)
36-
),
37-
build(:pageview,
38-
user_id: 124,
39-
pathname: "/home",
40-
timestamp: DateTime.shift(now, minute: -30)
41-
),
42-
build(:pageview,
43-
user_id: 124,
44-
pathname: "/login",
45-
timestamp: DateTime.shift(now, minute: -25)
46-
),
47-
build(:pageview,
48-
user_id: 124,
49-
pathname: "/docs",
50-
timestamp: DateTime.shift(now, minute: -20)
51-
),
52-
build(:pageview,
53-
user_id: 124,
54-
pathname: "/logout",
55-
timestamp: DateTime.shift(now, minute: -15)
56-
)
57-
])
13+
populate_stats(site, [
14+
build(:pageview,
15+
user_id: 123,
16+
pathname: "/home",
17+
timestamp: DateTime.shift(now, minute: -300)
18+
),
19+
build(:pageview,
20+
user_id: 123,
21+
pathname: "/login",
22+
timestamp: DateTime.shift(now, minute: -270)
23+
),
24+
build(:pageview,
25+
user_id: 123,
26+
pathname: "/home",
27+
timestamp: DateTime.shift(now, minute: -30)
28+
),
29+
build(:pageview,
30+
user_id: 123,
31+
pathname: "/login",
32+
timestamp: DateTime.shift(now, minute: -25)
33+
),
34+
build(:pageview,
35+
user_id: 123,
36+
pathname: "/logout",
37+
timestamp: DateTime.shift(now, minute: -20)
38+
),
39+
build(:pageview,
40+
user_id: 124,
41+
pathname: "/home",
42+
timestamp: DateTime.shift(now, minute: -30)
43+
),
44+
build(:pageview,
45+
user_id: 124,
46+
pathname: "/login",
47+
timestamp: DateTime.shift(now, minute: -25)
48+
),
49+
build(:pageview,
50+
user_id: 124,
51+
pathname: "/docs",
52+
timestamp: DateTime.shift(now, minute: -20)
53+
),
54+
build(:pageview,
55+
user_id: 124,
56+
pathname: "/logout",
57+
timestamp: DateTime.shift(now, minute: -15)
58+
)
59+
])
5860

59-
{:ok, site: site}
60-
end
61+
{:ok, site: site}
62+
end
6163

62-
describe "exploration_next/2" do
63-
test "it works", %{conn: conn, site: site} do
64-
journey =
65-
Jason.encode!([
66-
%{name: "pageview", pathname: "/home"},
67-
%{name: "pageview", pathname: "/login"}
68-
])
64+
describe "exploration_next/2" do
65+
test "it works", %{conn: conn, site: site} do
66+
journey =
67+
Jason.encode!([
68+
%{name: "pageview", pathname: "/home"},
69+
%{name: "pageview", pathname: "/login"}
70+
])
6971

70-
resp =
71-
conn
72-
|> get("/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&period=24h")
73-
|> json_response(200)
72+
resp =
73+
conn
74+
|> get("/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&period=24h")
75+
|> json_response(200)
7476

75-
assert [next_step1, next_step2] = resp
76-
assert next_step1["step"]["pathname"] == "/docs"
77-
assert next_step1["visitors"] == 1
78-
assert next_step2["step"]["pathname"] == "/logout"
79-
assert next_step2["visitors"] == 1
80-
end
77+
assert [next_step1, next_step2] = resp
78+
assert next_step1["step"]["pathname"] == "/docs"
79+
assert next_step1["visitors"] == 1
80+
assert next_step2["step"]["pathname"] == "/logout"
81+
assert next_step2["visitors"] == 1
82+
end
8183

82-
test "it filters", %{conn: conn, site: site} do
83-
journey =
84-
Jason.encode!([
85-
%{name: "pageview", pathname: "/home"},
86-
%{name: "pageview", pathname: "/login"}
87-
])
84+
test "it filters", %{conn: conn, site: site} do
85+
journey =
86+
Jason.encode!([
87+
%{name: "pageview", pathname: "/home"},
88+
%{name: "pageview", pathname: "/login"}
89+
])
8890

89-
resp =
90-
conn
91-
|> get(
92-
"/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&search_term=doc&period=24h"
93-
)
94-
|> json_response(200)
91+
resp =
92+
conn
93+
|> get(
94+
"/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&search_term=doc&period=24h"
95+
)
96+
|> json_response(200)
9597

96-
assert [next_step] = resp
97-
assert next_step["step"]["pathname"] == "/docs"
98-
assert next_step["visitors"] == 1
98+
assert [next_step] = resp
99+
assert next_step["step"]["pathname"] == "/docs"
100+
assert next_step["visitors"] == 1
101+
end
99102
end
100-
end
101103

102-
describe "exploration_funnel/2" do
103-
test "it works", %{conn: conn, site: site} do
104-
journey =
105-
Jason.encode!([
106-
%{name: "pageview", pathname: "/home"},
107-
%{name: "pageview", pathname: "/login"},
108-
%{name: "pageview", pathname: "/logout"}
109-
])
104+
describe "exploration_funnel/2" do
105+
test "it works", %{conn: conn, site: site} do
106+
journey =
107+
Jason.encode!([
108+
%{name: "pageview", pathname: "/home"},
109+
%{name: "pageview", pathname: "/login"},
110+
%{name: "pageview", pathname: "/logout"}
111+
])
110112

111-
resp =
112-
conn
113-
|> get("/api/stats/#{site.domain}/exploration/funnel/?journey=#{journey}&period=24h")
114-
|> json_response(200)
113+
resp =
114+
conn
115+
|> get("/api/stats/#{site.domain}/exploration/funnel/?journey=#{journey}&period=24h")
116+
|> json_response(200)
115117

116-
assert [step1, step2, step3] = resp
118+
assert [step1, step2, step3] = resp
117119

118-
assert step1["step"]["pathname"] == "/home"
119-
assert step1["visitors"] == 2
120-
assert step1["dropoff"] == 0
121-
assert step1["dropoff_percentage"] == "0"
122-
assert step2["step"]["pathname"] == "/login"
123-
assert step2["visitors"] == 2
124-
assert step2["dropoff"] == 0
125-
assert step2["dropoff_percentage"] == "0"
126-
assert step3["step"]["pathname"] == "/logout"
127-
assert step3["visitors"] == 1
128-
assert step3["dropoff"] == 1
129-
assert step3["dropoff_percentage"] == "50"
120+
assert step1["step"]["pathname"] == "/home"
121+
assert step1["visitors"] == 2
122+
assert step1["dropoff"] == 0
123+
assert step1["dropoff_percentage"] == "0"
124+
assert step2["step"]["pathname"] == "/login"
125+
assert step2["visitors"] == 2
126+
assert step2["dropoff"] == 0
127+
assert step2["dropoff_percentage"] == "0"
128+
assert step3["step"]["pathname"] == "/logout"
129+
assert step3["visitors"] == 1
130+
assert step3["dropoff"] == 1
131+
assert step3["dropoff_percentage"] == "50"
132+
end
130133
end
131134
end
132135
end

0 commit comments

Comments
 (0)