Leon4gr45 commited on
Commit
3e10add
·
verified ·
1 Parent(s): 419ee27

Delete test/support/factory.ex with huggingface_hub

Browse files
Files changed (1) hide show
  1. test/support/factory.ex +0 -415
test/support/factory.ex DELETED
@@ -1,415 +0,0 @@
1
- defmodule Plausible.Factory do
2
- @moduledoc """
3
- See https://ecto.hexdocs.pm/test-factories.html
4
- """
5
- use ExMachina.Ecto, repo: Plausible.Repo
6
- require Plausible.Billing.Subscription.Status
7
- alias Plausible.Billing.Subscription
8
-
9
- def team_factory do
10
- %Plausible.Teams.Team{
11
- name: Plausible.Teams.default_name(),
12
- trial_expiry_date: Date.utc_today() |> Date.shift(day: 30),
13
- setup_complete: true,
14
- setup_at: NaiveDateTime.utc_now()
15
- }
16
- end
17
-
18
- def team_membership_factory do
19
- %Plausible.Teams.Membership{
20
- user: build(:user),
21
- role: :viewer
22
- }
23
- end
24
-
25
- def guest_membership_factory do
26
- %Plausible.Teams.GuestMembership{
27
- team_membership: build(:team_membership, role: :guest)
28
- }
29
- end
30
-
31
- def team_invitation_factory do
32
- %Plausible.Teams.Invitation{
33
- invitation_id: Nanoid.generate(),
34
- email: sequence(:email, &"email-#{&1}@example.com"),
35
- role: :admin
36
- }
37
- end
38
-
39
- def guest_invitation_factory do
40
- %Plausible.Teams.GuestInvitation{
41
- invitation_id: Nanoid.generate(),
42
- role: :editor,
43
- team_invitation: build(:team_invitation, role: :guest)
44
- }
45
- end
46
-
47
- def site_transfer_factory do
48
- %Plausible.Teams.SiteTransfer{
49
- transfer_id: Nanoid.generate(),
50
- email: sequence(:email, &"email-#{&1}@example.com")
51
- }
52
- end
53
-
54
- def user_factory(attrs) do
55
- pw = Map.get(attrs, :password, "password")
56
-
57
- user = %Plausible.Auth.User{
58
- name: "Jane Smith",
59
- email: sequence(:email, &"email-#{&1}@example.com"),
60
- password_hash: Plausible.Auth.Password.hash(pw),
61
- email_verified: true
62
- }
63
-
64
- merge_attributes(user, attrs)
65
- end
66
-
67
- def spike_notification_factory do
68
- %Plausible.Site.TrafficChangeNotification{
69
- threshold: 10,
70
- type: :spike
71
- }
72
- end
73
-
74
- def drop_notification_factory do
75
- %Plausible.Site.TrafficChangeNotification{
76
- threshold: 1,
77
- type: :drop
78
- }
79
- end
80
-
81
- def site_factory(attrs) do
82
- # The é exercises unicode support in domain names
83
- domain = sequence(:domain, &"é-#{&1}.example.com")
84
-
85
- site = %Plausible.Site{
86
- native_stats_start_at: ~N[2000-01-01 00:00:00],
87
- domain: domain,
88
- timezone: "Etc/UTC"
89
- }
90
-
91
- merge_attributes(site, attrs)
92
- end
93
-
94
- def site_import_factory do
95
- today = Date.utc_today()
96
-
97
- %Plausible.Imported.SiteImport{
98
- site: build(:site),
99
- imported_by: build(:user),
100
- start_date: ~D[2005-01-01],
101
- end_date: today,
102
- source: :universal_analytics,
103
- status: :completed,
104
- legacy: false
105
- }
106
- end
107
-
108
- def ch_session_factory do
109
- hostname = sequence(:domain, &"example-#{&1}.com")
110
-
111
- %Plausible.ClickhouseSessionV2{
112
- sign: 1,
113
- session_id: SipHash.hash!(hash_key(), Ecto.UUID.generate()),
114
- user_id: SipHash.hash!(hash_key(), Ecto.UUID.generate()),
115
- hostname: hostname,
116
- site_id: Enum.random(1_000_000_000..2_000_000_000),
117
- entry_page: "/",
118
- pageviews: 1,
119
- events: 1,
120
- start: DateTime.utc_now(),
121
- timestamp: DateTime.utc_now(),
122
- is_bounce: false
123
- }
124
- end
125
-
126
- def pageview_factory(attrs) do
127
- Map.put(event_factory(attrs), :name, "pageview")
128
- end
129
-
130
- def engagement_factory(attrs) do
131
- Map.put(event_factory(attrs), :name, "engagement")
132
- end
133
-
134
- def event_factory(attrs) do
135
- if Map.get(attrs, :acquisition_channel) do
136
- raise "Acquisition channel cannot be written directly since it's a materialized column."
137
- end
138
-
139
- hostname = sequence(:domain, &"example-#{&1}.com")
140
-
141
- event = %Plausible.ClickhouseEventV2{
142
- hostname: hostname,
143
- site_id: Enum.random(1_000_000_000..2_000_000_000),
144
- pathname: "/",
145
- timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second),
146
- user_id: SipHash.hash!(hash_key(), Ecto.UUID.generate()),
147
- session_id: SipHash.hash!(hash_key(), Ecto.UUID.generate())
148
- }
149
-
150
- event
151
- |> merge_attributes(attrs)
152
- |> evaluate_lazy_attributes()
153
- end
154
-
155
- def goal_factory(attrs) do
156
- display_name_provided? = Map.has_key?(attrs, :display_name)
157
-
158
- attrs =
159
- case {attrs, display_name_provided?} do
160
- {%{page_path: path}, false} when is_binary(path) ->
161
- Map.put(attrs, :display_name, "Visit " <> path)
162
-
163
- {%{page_path: path}, false} when is_function(path, 0) ->
164
- attrs
165
- |> Map.put(:display_name, "Visit " <> path.())
166
- |> Map.put(:page_path, path.())
167
-
168
- {%{event_name: event_name}, false} when is_binary(event_name) ->
169
- Map.put(attrs, :display_name, event_name)
170
-
171
- {%{event_name: event_name}, false} when is_function(event_name, 0) ->
172
- attrs
173
- |> Map.put(:display_name, event_name.())
174
- |> Map.put(:event_name, event_name.())
175
-
176
- _ ->
177
- attrs
178
- end
179
-
180
- merge_attributes(%Plausible.Goal{}, attrs)
181
- end
182
-
183
- def subscription_factory do
184
- %Plausible.Billing.Subscription{
185
- paddle_subscription_id: sequence(:paddle_subscription_id, &"subscription-#{&1}"),
186
- paddle_plan_id: sequence(:paddle_plan_id, &"plan-#{&1}"),
187
- cancel_url: "cancel.com",
188
- update_url: "cancel.com",
189
- status: Subscription.Status.active(),
190
- next_bill_amount: "6.00",
191
- next_bill_date: Date.utc_today(),
192
- last_bill_date: Date.utc_today(),
193
- currency_code: "USD"
194
- }
195
- end
196
-
197
- def starter_subscription_factory do
198
- build(:subscription, paddle_plan_id: "910413")
199
- end
200
-
201
- def growth_subscription_factory do
202
- build(:subscription, paddle_plan_id: "857097")
203
- end
204
-
205
- def business_subscription_factory do
206
- build(:subscription, paddle_plan_id: "857087")
207
- end
208
-
209
- def enterprise_plan_factory do
210
- %Plausible.Billing.EnterprisePlan{
211
- paddle_plan_id: sequence(:paddle_plan_id, &"plan-#{&1}"),
212
- billing_interval: :monthly,
213
- monthly_pageview_limit: 1_000_000,
214
- hourly_api_request_limit: 3000,
215
- site_limit: 100,
216
- team_member_limit: 10
217
- }
218
- end
219
-
220
- def google_auth_factory do
221
- %Plausible.Site.GoogleAuth{
222
- email: sequence(:google_auth_email, &"email-#{&1}@example.com"),
223
- refresh_token: "123",
224
- access_token: "123",
225
- expires: DateTime.utc_now() |> DateTime.shift(day: 1)
226
- }
227
- end
228
-
229
- def weekly_report_factory do
230
- %Plausible.Site.WeeklyReport{}
231
- end
232
-
233
- def monthly_report_factory do
234
- %Plausible.Site.MonthlyReport{}
235
- end
236
-
237
- def shared_link_factory do
238
- slug = Nanoid.generate()
239
- name = "Link - #{slug}"
240
-
241
- %Plausible.Site.SharedLink{
242
- name: name,
243
- slug: slug
244
- }
245
- end
246
-
247
- def api_key_factory do
248
- key = :crypto.strong_rand_bytes(64) |> Base.url_encode64() |> binary_part(0, 64)
249
-
250
- %Plausible.Auth.ApiKey{
251
- name: "api-key-name",
252
- key: key,
253
- key_hash: Plausible.Auth.ApiKey.do_hash(key),
254
- key_prefix: binary_part(key, 0, 6)
255
- }
256
- end
257
-
258
- def imported_visitors_factory do
259
- %{
260
- table: "imported_visitors",
261
- date: Date.utc_today(),
262
- visitors: 1,
263
- pageviews: 1,
264
- bounces: 0,
265
- visits: 1,
266
- visit_duration: 10
267
- }
268
- end
269
-
270
- def imported_sources_factory do
271
- %{
272
- table: "imported_sources",
273
- date: Date.utc_today(),
274
- source: "",
275
- visitors: 1,
276
- visits: 1,
277
- bounces: 0,
278
- visit_duration: 10
279
- }
280
- end
281
-
282
- def imported_pages_factory do
283
- %{
284
- table: "imported_pages",
285
- date: Date.utc_today(),
286
- page: "",
287
- visitors: 1,
288
- pageviews: 1,
289
- exits: 0,
290
- total_time_on_page: 10,
291
- total_time_on_page_visits: 1
292
- }
293
- end
294
-
295
- def imported_entry_pages_factory do
296
- %{
297
- table: "imported_entry_pages",
298
- date: Date.utc_today(),
299
- entry_page: "",
300
- visitors: 1,
301
- entrances: 1,
302
- bounces: 0,
303
- visit_duration: 10
304
- }
305
- end
306
-
307
- def imported_exit_pages_factory do
308
- %{
309
- table: "imported_exit_pages",
310
- date: Date.utc_today(),
311
- exit_page: "",
312
- visitors: 1,
313
- exits: 1
314
- }
315
- end
316
-
317
- def imported_custom_events_factory do
318
- %{
319
- table: "imported_custom_events",
320
- date: Date.utc_today(),
321
- name: "",
322
- link_url: "",
323
- visitors: 1,
324
- events: 1
325
- }
326
- end
327
-
328
- def imported_locations_factory do
329
- %{
330
- table: "imported_locations",
331
- date: Date.utc_today(),
332
- country: "",
333
- region: "",
334
- city: 0,
335
- visitors: 1,
336
- visits: 1,
337
- bounces: 0,
338
- visit_duration: 10
339
- }
340
- end
341
-
342
- def imported_devices_factory do
343
- %{
344
- table: "imported_devices",
345
- date: Date.utc_today(),
346
- device: "",
347
- visitors: 1,
348
- visits: 1,
349
- bounces: 0,
350
- visit_duration: 10
351
- }
352
- end
353
-
354
- def imported_browsers_factory do
355
- %{
356
- table: "imported_browsers",
357
- date: Date.utc_today(),
358
- browser: "",
359
- visitors: 1,
360
- visits: 1,
361
- bounces: 0,
362
- visit_duration: 10
363
- }
364
- end
365
-
366
- def imported_operating_systems_factory do
367
- %{
368
- table: "imported_operating_systems",
369
- date: Date.utc_today(),
370
- operating_system: "",
371
- visitors: 1,
372
- visits: 1,
373
- bounces: 0,
374
- visit_duration: 10
375
- }
376
- end
377
-
378
- def ip_rule_factory do
379
- %Plausible.Shield.IPRule{
380
- inet: Plausible.TestUtils.random_ip(),
381
- description: "Test IP Rule",
382
- added_by: "Mr Seed <user@plausible.test>"
383
- }
384
- end
385
-
386
- def country_rule_factory do
387
- %Plausible.Shield.CountryRule{
388
- added_by: "Mr Seed <user@plausible.test>"
389
- }
390
- end
391
-
392
- def segment_factory do
393
- %Plausible.Segments.Segment{
394
- segment_data: %{"filters" => [["is", "visit:entry_page", ["/blog"]]]}
395
- }
396
- end
397
-
398
- def annotation_factory do
399
- %Plausible.Annotations.Annotation{
400
- note: "a test annotation",
401
- type: :site,
402
- datetime: ~U[2026-01-04 00:00:00Z],
403
- date: ~D[2026-01-04],
404
- granularity: :date
405
- }
406
- end
407
-
408
- defp hash_key() do
409
- Keyword.fetch!(
410
- Application.get_env(:plausible, PlausibleWeb.Endpoint),
411
- :secret_key_base
412
- )
413
- |> binary_part(0, 16)
414
- end
415
- end