Leon4gr45 commited on
Commit
d2d6dc1
·
verified ·
1 Parent(s): c0c4adf

Delete test/plausible_web/controllers/api/stats_controller/cities_test.exs with huggingface_hub

Browse files
test/plausible_web/controllers/api/stats_controller/cities_test.exs DELETED
@@ -1,224 +0,0 @@
1
- defmodule PlausibleWeb.Api.StatsController.CitiesTest do
2
- use PlausibleWeb.ConnCase
3
-
4
- defp query_cities(conn, site, opts) do
5
- always_on_filters = ["is_not", "visit:city", [0]]
6
-
7
- params = %{
8
- "dimensions" => Keyword.get(opts, :dimensions, ["visit:city", "visit:city_name"]),
9
- "date_range" => Keyword.get(opts, :date_range, "all"),
10
- "filters" => [
11
- always_on_filters
12
- | Keyword.get(opts, :filters, [])
13
- ],
14
- "metrics" => Keyword.get(opts, :metrics, ["visitors", "percentage"]),
15
- "include" => Keyword.get(opts, :include, nil),
16
- "pagination" => Keyword.get(opts, :pagination, nil),
17
- "order_by" => Keyword.get(opts, :order_by, nil)
18
- }
19
-
20
- conn
21
- |> post("/api/stats/#{site.domain}/query", params)
22
- |> json_response(200)
23
- end
24
-
25
- describe "querying for cities with POST /query" do
26
- defp seed(%{site: site}) do
27
- populate_stats(site, [
28
- build(:pageview,
29
- country_code: "EE",
30
- subdivision1_code: "EE-37",
31
- city_geoname_id: 588_409
32
- ),
33
- build(:pageview,
34
- country_code: "EE",
35
- subdivision1_code: "EE-37",
36
- city_geoname_id: 588_409
37
- ),
38
- build(:pageview,
39
- country_code: "EE",
40
- subdivision1_code: "EE-37",
41
- city_geoname_id: 588_409
42
- ),
43
- build(:pageview,
44
- country_code: "EE",
45
- subdivision1_code: "EE-39",
46
- city_geoname_id: 591_632
47
- ),
48
- build(:pageview,
49
- country_code: "EE",
50
- subdivision1_code: "EE-39",
51
- city_geoname_id: 591_632
52
- )
53
- ])
54
- end
55
-
56
- setup [:create_user, :log_in, :create_site, :create_legacy_site_import, :seed]
57
-
58
- test "returns top cities by visitors", %{conn: conn, site: site} do
59
- response = query_cities(conn, site, date_range: "day")
60
-
61
- assert response["results"] == [
62
- %{"dimensions" => [588_409, "Tallinn"], "metrics" => [3, 60.0]},
63
- %{"dimensions" => [591_632, "Kärdla"], "metrics" => [2, 40.0]}
64
- ]
65
- end
66
-
67
- test "when list is filtered returns one city only", %{conn: conn, site: site} do
68
- response =
69
- query_cities(conn, site,
70
- date_range: "day",
71
- filters: [["is", "visit:city", [591_632]]]
72
- )
73
-
74
- assert response["results"] == [
75
- %{"dimensions" => [591_632, "Kärdla"], "metrics" => [2, 100.0]}
76
- ]
77
- end
78
-
79
- test "does not return missing cities from imported data", %{conn: conn, site: site} do
80
- populate_stats(site, [
81
- build(:imported_locations, country: "EE", region: "EE-37", city: 588_409),
82
- build(:imported_locations, country: nil, region: nil, city: 0),
83
- build(:imported_locations, country: nil, region: nil, city: nil)
84
- ])
85
-
86
- response =
87
- query_cities(conn, site,
88
- date_range: "day",
89
- include: %{"imports" => true}
90
- )
91
-
92
- assert response["results"] == [
93
- %{"dimensions" => [588_409, "Tallinn"], "metrics" => [4, 66.67]},
94
- %{"dimensions" => [591_632, "Kärdla"], "metrics" => [2, 33.33]}
95
- ]
96
- end
97
-
98
- @tag :ee_only
99
- test "return revenue metrics for cities breakdown", %{conn: conn, site: site} do
100
- populate_stats(site, [
101
- build(:pageview,
102
- user_id: 1,
103
- country_code: "EE",
104
- subdivision1_code: "EE-37",
105
- city_geoname_id: 588_409
106
- ),
107
- build(:event,
108
- name: "Payment",
109
- user_id: 1,
110
- revenue_reporting_amount: Decimal.new("1000"),
111
- revenue_reporting_currency: "USD"
112
- ),
113
- build(:pageview,
114
- user_id: 2,
115
- country_code: "EE",
116
- subdivision1_code: "EE-37",
117
- city_geoname_id: 588_409
118
- ),
119
- build(:event,
120
- name: "Payment",
121
- user_id: 2,
122
- revenue_reporting_amount: Decimal.new("2000"),
123
- revenue_reporting_currency: "USD"
124
- ),
125
- build(:pageview,
126
- user_id: 3,
127
- country_code: "EE",
128
- subdivision1_code: "EE-37",
129
- city_geoname_id: 588_409
130
- ),
131
- build(:pageview,
132
- user_id: 4,
133
- country_code: "EE",
134
- subdivision1_code: "EE-39",
135
- city_geoname_id: 591_632
136
- ),
137
- build(:event,
138
- name: "Payment",
139
- user_id: 4,
140
- revenue_reporting_amount: Decimal.new("500"),
141
- revenue_reporting_currency: "USD"
142
- ),
143
- build(:pageview,
144
- user_id: 5,
145
- country_code: "EE",
146
- subdivision1_code: "EE-39",
147
- city_geoname_id: 591_632
148
- ),
149
- build(:pageview, user_id: 6),
150
- build(:event,
151
- name: "Payment",
152
- user_id: 6,
153
- revenue_reporting_amount: Decimal.new("600"),
154
- revenue_reporting_currency: "USD"
155
- ),
156
- build(:pageview, user_id: 7),
157
- build(:event,
158
- name: "Payment",
159
- user_id: 7,
160
- revenue_reporting_amount: nil
161
- )
162
- ])
163
-
164
- insert(:goal, %{site: site, event_name: "Payment", currency: :USD})
165
-
166
- response =
167
- query_cities(conn, site,
168
- date_range: "day",
169
- filters: [["is", "event:goal", ["Payment"]]],
170
- metrics: [
171
- "visitors",
172
- "total_visitors",
173
- "group_conversion_rate",
174
- "average_revenue",
175
- "total_revenue"
176
- ],
177
- order_by: [["visitors", "desc"], ["visit:city", "asc"]]
178
- )
179
-
180
- assert response["results"] == [
181
- %{
182
- "dimensions" => [588_409, "Tallinn"],
183
- "metrics" => [
184
- 2,
185
- 6,
186
- 33.33,
187
- %{
188
- "currency" => "USD",
189
- "long" => "$1,500.00",
190
- "short" => "$1.5K",
191
- "value" => 1500.0
192
- },
193
- %{
194
- "currency" => "USD",
195
- "long" => "$3,000.00",
196
- "short" => "$3.0K",
197
- "value" => 3000.0
198
- }
199
- ]
200
- },
201
- %{
202
- "dimensions" => [591_632, "Kärdla"],
203
- "metrics" => [
204
- 1,
205
- 4,
206
- 25.0,
207
- %{
208
- "currency" => "USD",
209
- "long" => "$500.00",
210
- "short" => "$500.0",
211
- "value" => 500.0
212
- },
213
- %{
214
- "currency" => "USD",
215
- "long" => "$500.00",
216
- "short" => "$500.0",
217
- "value" => 500.0
218
- }
219
- ]
220
- }
221
- ]
222
- end
223
- end
224
- end