Leon4gr45 commited on
Commit
561e0fd
·
verified ·
1 Parent(s): 30d6412

Delete test/plausible_web/plugins/api/controllers/custom_props_test.exs with huggingface_hub

Browse files
test/plausible_web/plugins/api/controllers/custom_props_test.exs DELETED
@@ -1,304 +0,0 @@
1
- defmodule PlausibleWeb.Plugins.API.Controllers.CustomPropsTest do
2
- use PlausibleWeb.PluginsAPICase, async: true
3
- alias PlausibleWeb.Plugins.API.Schemas
4
-
5
- describe "examples" do
6
- test "CustomProp" do
7
- assert_schema(
8
- Schemas.CustomProp.schema().example,
9
- "CustomProp",
10
- spec()
11
- )
12
- end
13
-
14
- test "CustomProp.CreateRequest" do
15
- assert_schema(
16
- Schemas.CustomProp.EnableRequest.schema().example,
17
- "CustomProp.EnableRequest",
18
- spec()
19
- )
20
- end
21
- end
22
-
23
- describe "unauthorized calls" do
24
- for {method, url} <- [
25
- {:put, Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)},
26
- {:delete, Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :disable)}
27
- ] do
28
- test "unauthorized call: #{method} #{url}", %{conn: conn} do
29
- conn
30
- |> unquote(method)(unquote(url))
31
- |> json_response(401)
32
- |> assert_schema("UnauthorizedError", spec())
33
- end
34
- end
35
- end
36
-
37
- describe "business tier" do
38
- @describetag :ee_only
39
-
40
- test "allows prop enable for special key", %{
41
- site: site,
42
- token: token,
43
- conn: conn
44
- } do
45
- [owner | _] = Plausible.Repo.preload(site, :owners).owners
46
- subscribe_to_growth_plan(owner)
47
-
48
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
49
-
50
- payload = %{
51
- custom_prop: %{key: "search_query"}
52
- }
53
-
54
- assert_request_schema(payload, "CustomProp.EnableRequest", spec())
55
-
56
- conn
57
- |> authenticate(site.domain, token)
58
- |> put_req_header("content-type", "application/json")
59
- |> put(url, payload)
60
- |> json_response(201)
61
- |> assert_schema("CustomProp.ListResponse", spec())
62
- end
63
-
64
- test "allows bulk prop enable for special keys", %{
65
- site: site,
66
- token: token,
67
- conn: conn
68
- } do
69
- [owner | _] = Plausible.Repo.preload(site, :owners).owners
70
- subscribe_to_growth_plan(owner)
71
-
72
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
73
-
74
- payload = %{
75
- custom_props: [
76
- %{
77
- custom_prop: %{key: "search_query"}
78
- },
79
- %{
80
- custom_prop: %{key: "url"}
81
- }
82
- ]
83
- }
84
-
85
- conn
86
- |> authenticate(site.domain, token)
87
- |> put_req_header("content-type", "application/json")
88
- |> put(url, payload)
89
- |> json_response(201)
90
- |> assert_schema("CustomProp.ListResponse", spec())
91
- end
92
-
93
- test "fails on custom prop enable attempt with insufficient plan", %{
94
- site: site,
95
- token: token,
96
- conn: conn
97
- } do
98
- [owner | _] = Plausible.Repo.preload(site, :owners).owners
99
- subscribe_to_growth_plan(owner)
100
-
101
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
102
-
103
- payload = %{
104
- custom_prop: %{key: "author"}
105
- }
106
-
107
- assert_request_schema(payload, "CustomProp.EnableRequest", spec())
108
-
109
- conn
110
- |> authenticate(site.domain, token)
111
- |> put_req_header("content-type", "application/json")
112
- |> put(url, payload)
113
- |> json_response(402)
114
- |> assert_schema("PaymentRequiredError", spec())
115
- end
116
-
117
- test "fails on bulk prop enable attempt with insufficient plan", %{
118
- site: site,
119
- token: token,
120
- conn: conn
121
- } do
122
- [owner | _] = Plausible.Repo.preload(site, :owners).owners
123
- subscribe_to_growth_plan(owner)
124
-
125
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
126
-
127
- payload = %{
128
- custom_props: [
129
- %{
130
- custom_prop: %{key: "author"}
131
- },
132
- %{
133
- custom_prop: %{key: "search_query"}
134
- },
135
- %{
136
- custom_prop: %{key: "category"}
137
- }
138
- ]
139
- }
140
-
141
- conn
142
- |> authenticate(site.domain, token)
143
- |> put_req_header("content-type", "application/json")
144
- |> put(url, payload)
145
- |> json_response(402)
146
- |> assert_schema("PaymentRequiredError", spec())
147
- end
148
- end
149
-
150
- describe "put /custom_prop - enable single prop" do
151
- test "validates input according to the schema", %{conn: conn, token: token, site: site} do
152
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
153
-
154
- conn
155
- |> authenticate(site.domain, token)
156
- |> put_req_header("content-type", "application/json")
157
- |> put(url, %{custom_prop: %{typo: "author"}})
158
- |> json_response(422)
159
- |> assert_schema("UnprocessableEntityError", spec())
160
- end
161
-
162
- test "enables single custom prop", %{conn: conn, token: token, site: site} do
163
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
164
-
165
- payload = %{
166
- custom_prop: %{key: "author"}
167
- }
168
-
169
- assert_request_schema(payload, "CustomProp.EnableRequest", spec())
170
-
171
- conn =
172
- conn
173
- |> authenticate(site.domain, token)
174
- |> put_req_header("content-type", "application/json")
175
- |> put(url, payload)
176
-
177
- resp =
178
- conn
179
- |> json_response(201)
180
- |> assert_schema("CustomProp.ListResponse", spec())
181
-
182
- resp.custom_props
183
- |> List.first()
184
- |> assert_schema("CustomProp", spec())
185
-
186
- assert "author" in Plausible.Repo.reload!(site).allowed_event_props
187
- end
188
-
189
- test "is idempotent", %{conn: conn, token: token, site: site} do
190
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
191
-
192
- initial_conn =
193
- conn
194
- |> authenticate(site.domain, token)
195
- |> put_req_header("content-type", "application/json")
196
-
197
- resp1 =
198
- initial_conn
199
- |> put(
200
- url,
201
- %{
202
- custom_prop: %{key: "author"}
203
- }
204
- )
205
- |> json_response(201)
206
- |> assert_schema("CustomProp.ListResponse", spec())
207
-
208
- resp1.custom_props
209
- |> List.first()
210
- |> assert_schema("CustomProp", spec())
211
-
212
- assert initial_conn
213
- |> put(
214
- url,
215
- %{
216
- custom_prop: %{key: "author"}
217
- }
218
- )
219
- |> json_response(201)
220
- |> assert_schema("CustomProp.ListResponse", spec()) == resp1
221
- end
222
- end
223
-
224
- describe "put /custom_props - bulk creation" do
225
- test "creates many custom props", %{conn: conn, token: token, site: site} do
226
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
227
-
228
- payload = %{
229
- custom_props: [
230
- %{
231
- custom_prop: %{key: "author"}
232
- },
233
- %{
234
- custom_prop: %{key: "rating"}
235
- },
236
- %{
237
- custom_prop: %{key: "category"}
238
- }
239
- ]
240
- }
241
-
242
- assert_request_schema(payload, "CustomProp.EnableRequest.BulkEnable", spec())
243
-
244
- conn =
245
- conn
246
- |> authenticate(site.domain, token)
247
- |> put_req_header("content-type", "application/json")
248
- |> put(url, payload)
249
-
250
- resp =
251
- conn
252
- |> json_response(201)
253
- |> assert_schema("CustomProp.ListResponse", spec())
254
-
255
- assert Enum.count(resp.custom_props) == 3
256
-
257
- assert [
258
- "author",
259
- "rating",
260
- "category"
261
- ] = Plausible.Repo.reload!(site).allowed_event_props
262
- end
263
- end
264
-
265
- describe "delete /custom_props" do
266
- test "disable one prop", %{conn: conn, site: site, token: token} do
267
- {:ok, ["author"]} = Plausible.Plugins.API.CustomProps.enable(site, "author")
268
-
269
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
270
-
271
- payload = %{custom_prop: %{key: "author"}}
272
-
273
- conn
274
- |> authenticate(site.domain, token)
275
- |> put_req_header("content-type", "application/json")
276
- |> delete(url, payload)
277
- |> response(204)
278
-
279
- assert Plausible.Repo.reload!(site).allowed_event_props == []
280
- end
281
-
282
- test "disable many props", %{conn: conn, site: site, token: token} do
283
- {:ok, [_, _, _]} =
284
- Plausible.Plugins.API.CustomProps.enable(site, ["author", "category", "third"])
285
-
286
- url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
287
-
288
- payload = %{
289
- custom_props: [
290
- %{custom_prop: %{key: "author"}},
291
- %{custom_prop: %{key: "category"}}
292
- ]
293
- }
294
-
295
- conn
296
- |> authenticate(site.domain, token)
297
- |> put_req_header("content-type", "application/json")
298
- |> delete(url, payload)
299
- |> response(204)
300
-
301
- assert Plausible.Repo.reload!(site).allowed_event_props == ["third"]
302
- end
303
- end
304
- end