Leon4gr45 commited on
Commit
3f58eaf
·
verified ·
1 Parent(s): 03f72a0

Delete test/workers/accept_traffic_until_test.exs with huggingface_hub

Browse files
test/workers/accept_traffic_until_test.exs DELETED
@@ -1,174 +0,0 @@
1
- defmodule Plausible.Workers.AcceptTrafficUntilTest do
2
- use Plausible.DataCase, async: true
3
- use Bamboo.Test
4
-
5
- alias Plausible.Workers.AcceptTrafficUntil
6
-
7
- @moduletag :ee_only
8
-
9
- test "does not send any notifications when sites have no stats" do
10
- today = Date.utc_today()
11
- next_week = today |> Date.add(+7)
12
- tomorrow = today |> Date.add(+1)
13
-
14
- user1 = new_user(team: [accept_traffic_until: next_week])
15
-
16
- user2 = new_user(team: [accept_traffic_until: tomorrow])
17
-
18
- _site1 = new_site(owner: user1)
19
-
20
- _site2 = new_site(owner: user2)
21
-
22
- {:ok, 2} = AcceptTrafficUntil.perform(nil)
23
-
24
- refute_notifications(user1.email)
25
- refute_notifications(user2.email)
26
- end
27
-
28
- test "does not send any notifications when site has stats older than 2d" do
29
- today = Date.utc_today()
30
- next_week = today |> Date.add(+7)
31
-
32
- user = new_user(team: [accept_traffic_until: next_week])
33
-
34
- new_site(owner: user)
35
- |> populate_stats([build(:pageview, timestamp: Date.add(today, -3))])
36
-
37
- {:ok, 1} = AcceptTrafficUntil.perform(nil)
38
-
39
- refute_notifications(user.email)
40
- end
41
-
42
- test "does send notification when last stat is 2d old" do
43
- today = Date.utc_today()
44
- next_week = today |> Date.add(+7)
45
-
46
- user = new_user(team: [accept_traffic_until: next_week])
47
-
48
- new_site(owner: user)
49
- |> populate_stats([build(:pageview, timestamp: Date.add(today, -2))])
50
-
51
- {:ok, 1} = AcceptTrafficUntil.perform(nil)
52
-
53
- assert_weekly_notification(user.email)
54
- end
55
-
56
- test "tomorrow: sends one e-mail" do
57
- tomorrow = Date.utc_today() |> Date.add(+1)
58
- user = new_user(team: [accept_traffic_until: tomorrow])
59
-
60
- new_site(owner: user) |> populate_stats([build(:pageview)])
61
-
62
- {:ok, 1} = AcceptTrafficUntil.perform(nil)
63
- assert_final_notification(user.email)
64
- end
65
-
66
- test "next week: sends one e-mail" do
67
- next_week = Date.utc_today() |> Date.add(+7)
68
- user = new_user(team: [accept_traffic_until: next_week])
69
-
70
- new_site(owner: user) |> populate_stats([build(:pageview)])
71
-
72
- {:ok, 1} = AcceptTrafficUntil.perform(nil)
73
- assert_weekly_notification(user.email)
74
- end
75
-
76
- test "sends combined warnings in one shot" do
77
- today = Date.utc_today()
78
- next_week = today |> Date.add(+7)
79
- tomorrow = today |> Date.add(+1)
80
- in_8_days = today |> Date.add(+8)
81
-
82
- user1 = new_user(team: [accept_traffic_until: next_week])
83
- user2 = new_user(team: [accept_traffic_until: tomorrow])
84
- user3 = new_user(team: [accept_traffic_until: in_8_days], email: "nope@example.com")
85
- user4 = new_user(team: [accept_traffic_until: today], email: "nope2@example.com")
86
-
87
- new_site(owner: user1) |> populate_stats([build(:pageview)])
88
- new_site(owner: user2) |> populate_stats([build(:pageview)])
89
- new_site(owner: user3) |> populate_stats([build(:pageview)])
90
- new_site(owner: user4) |> populate_stats([build(:pageview)])
91
-
92
- {:ok, 2} = AcceptTrafficUntil.perform(nil)
93
- assert_weekly_notification(user1.email)
94
- assert_final_notification(user2.email)
95
- refute_notifications("nope@example.com")
96
- refute_notifications("nope2@example.com")
97
- end
98
-
99
- test "sends multiple notifications per recipient as the time passes" do
100
- today = Date.utc_today()
101
- email = "cycle@example.com"
102
-
103
- user =
104
- new_user(
105
- email: email,
106
- trial_expiry_date: Plausible.Teams.Team.trial_expiry()
107
- )
108
-
109
- team = team_of(user)
110
-
111
- site = new_site(owner: user)
112
-
113
- populate_stats(site, [
114
- build(:pageview, timestamp: today),
115
- build(:pageview, timestamp: Date.add(team.trial_expiry_date, 7)),
116
- build(:pageview, timestamp: Date.add(team.trial_expiry_date, 8)),
117
- build(:pageview, timestamp: Date.add(team.trial_expiry_date, 13))
118
- ])
119
-
120
- # today's worker is no-op
121
- {:ok, 0} = AcceptTrafficUntil.perform(nil, today)
122
- refute_notifications(email)
123
-
124
- # trial_expiry + 7 days worker => we'll stop counting next week
125
- {:ok, 1} = AcceptTrafficUntil.perform(nil, Date.add(team.trial_expiry_date, 7))
126
- assert_weekly_notification(email)
127
-
128
- # another call on the same day == no-op, e-mail already sent
129
- {:ok, 0} = AcceptTrafficUntil.perform(nil, Date.add(team.trial_expiry_date, 7))
130
- refute_notifications(email)
131
-
132
- # another call on another day == no-op, no notification type applies
133
- {:ok, 0} = AcceptTrafficUntil.perform(nil, Date.add(team.trial_expiry_date, 8))
134
- refute_notifications(email)
135
-
136
- # day before accept_stats_until (trial_expiry_date + 14 - 1)
137
- {:ok, 1} = AcceptTrafficUntil.perform(nil, Date.add(team.trial_expiry_date, 13))
138
- assert_final_notification(email)
139
-
140
- # another one on the day before accept_stats_until (trial_expiry_date + 14 - 1) == no-op
141
- {:ok, 0} = AcceptTrafficUntil.perform(nil, Date.add(team.trial_expiry_date, 13))
142
- refute_notifications(email)
143
- end
144
-
145
- defp assert_weekly_notification(email) when is_binary(email) do
146
- assert_email_delivered_with(
147
- html_body: ~r/Hey Jane,/,
148
- to: [nil: email],
149
- subject:
150
- PlausibleWeb.Email.approaching_accept_traffic_until(%{
151
- name: "",
152
- email: email,
153
- team: build(:team, identifier: Ecto.UUID.generate())
154
- }).subject
155
- )
156
- end
157
-
158
- defp assert_final_notification(email) when is_binary(email) do
159
- assert_email_delivered_with(
160
- html_body: ~r/Hey Jane,/,
161
- to: [nil: email],
162
- subject:
163
- PlausibleWeb.Email.approaching_accept_traffic_until_tomorrow(%{
164
- name: "",
165
- email: email,
166
- team: build(:team, identifier: Ecto.UUID.generate())
167
- }).subject
168
- )
169
- end
170
-
171
- defp refute_notifications(email) when is_binary(email) do
172
- refute_email_delivered_with(to: [nil: email])
173
- end
174
- end