Leon4gr45 commited on
Commit
afcce48
·
verified ·
1 Parent(s): 9b1874b

Delete test/plausible_web/controllers/help_scout_controller_test.exs with huggingface_hub

Browse files
test/plausible_web/controllers/help_scout_controller_test.exs DELETED
@@ -1,258 +0,0 @@
1
- defmodule PlausibleWeb.HelpScoutControllerTest do
2
- use PlausibleWeb.ConnCase, async: true
3
-
4
- @moduletag :ee_only
5
-
6
- on_ee do
7
- alias Plausible.HelpScout
8
-
9
- describe "callback/2" do
10
- test "returns details on success", %{conn: conn} do
11
- user = insert(:user)
12
- signature_key = Application.fetch_env!(:plausible, HelpScout)[:signature_key]
13
- data = ~s|{"conversation-id":"123","customer-id":"500"}|
14
-
15
- signature =
16
- :hmac
17
- |> :crypto.mac(:sha, signature_key, data)
18
- |> Base.encode64()
19
- |> URI.encode_www_form()
20
-
21
- Req.Test.stub(HelpScout, fn
22
- %{request_path: "/v2/oauth2/token"} = conn ->
23
- Req.Test.json(conn, %{
24
- "token_type" => "bearer",
25
- "access_token" => "369dbb08be58430086d2f8bd832bc1eb",
26
- "expires_in" => 172_800
27
- })
28
-
29
- %{request_path: "/v2/customers/500"} = conn ->
30
- Req.Test.json(conn, %{
31
- "id" => 500,
32
- "_embedded" => %{
33
- "emails" => [
34
- %{
35
- "id" => 1,
36
- "value" => user.email,
37
- "type" => "home"
38
- }
39
- ]
40
- }
41
- })
42
- end)
43
-
44
- conn =
45
- get(
46
- conn,
47
- "/helpscout/callback?conversation-id=123&customer-id=500&X-HelpScout-Signature=#{signature}"
48
- )
49
-
50
- assert [] = Plug.Conn.get_resp_header(conn, "content-security-policy")
51
-
52
- html = html_response(conn, 200)
53
- assert html =~ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, user.id)
54
- assert text_of_attr("input[name=token]", "value") != ""
55
- end
56
-
57
- test "returns error on failure", %{conn: conn} do
58
- conn =
59
- get(
60
- conn,
61
- "/helpscout/callback?conversation-id=123&customer-id=500&X-HelpScout-Signature=invalid"
62
- )
63
-
64
- html = html_response(conn, 200)
65
-
66
- assert html =~ "bad_signature"
67
- refute text_of_attr("input[name=token]", "value")
68
- end
69
-
70
- test "handles invalid parameters gracefully", %{conn: conn} do
71
- conn =
72
- get(
73
- conn,
74
- "/helpscout/callback?customer-id=500&X-HelpScout-Signature=whatever"
75
- )
76
-
77
- assert html_response(conn, 200) =~ "Missing expected parameters"
78
- end
79
- end
80
-
81
- describe "search/2" do
82
- test "returns results", %{conn: conn} do
83
- insert(:user, email: "hs.match@plausible.test")
84
- insert(:user, email: "hs.nomatch@plausible.test")
85
-
86
- token = sign_conversation_token("123")
87
-
88
- conn =
89
- conn
90
- |> get(
91
- "/helpscout/search?conversation_id=123&customer_id=500&term=hs.match&token=#{token}"
92
- )
93
-
94
- html = html_response(conn, 200)
95
-
96
- assert html =~ "hs.match@plausible.test"
97
- refute html =~ "hs.nomatch@plausible.test"
98
- end
99
-
100
- test "returns error when token is invalid", %{conn: conn} do
101
- conn =
102
- get(
103
- conn,
104
- "/helpscout/search?conversation_id=123&customer_id=500&term=hs.match&token=invalid"
105
- )
106
-
107
- assert html_response(conn, 200) =~ "invalid_token"
108
- end
109
-
110
- test "returns error when token does not match", %{conn: conn} do
111
- token = sign_conversation_token("456")
112
-
113
- conn =
114
- conn
115
- |> get(
116
- "/helpscout/search?conversation_id=123&customer_id=500&term=hs.match&token=#{token}"
117
- )
118
-
119
- assert html_response(conn, 200) =~ "invalid_conversation"
120
- end
121
- end
122
-
123
- describe "show/2" do
124
- test "returns details on success", %{conn: conn} do
125
- user = insert(:user, email: "hs.match@plausible.test", notes: "Some note\nwith new line")
126
-
127
- token = sign_conversation_token("123")
128
-
129
- conn =
130
- conn
131
- |> get(
132
- "/helpscout/show?conversation_id=123&customer_id=500&email=hs.match@plausible.test&token=#{token}"
133
- )
134
-
135
- assert html = html_response(conn, 200)
136
- assert html =~ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, user.id)
137
- assert html =~ "Some note<br>\nwith new line"
138
- end
139
-
140
- test "returns teams list when the match is an owner in multiple teams", %{conn: conn} do
141
- user = new_user(email: "hs.match@plausible.test", notes: "Some user notes")
142
- other_user = new_user()
143
- _site1 = new_site(owner: user)
144
- _site2 = new_site(owner: other_user)
145
- _team1 = team_of(user)
146
- team2 = team_of(other_user)
147
-
148
- team2 =
149
- team2
150
- |> Plausible.Teams.complete_setup()
151
- |> Ecto.Changeset.change(name: "HS Integration Test Team")
152
- |> Plausible.Repo.update!()
153
-
154
- add_member(team2, user: user, role: :owner)
155
-
156
- token = sign_conversation_token("123")
157
-
158
- conn =
159
- conn
160
- |> get(
161
- "/helpscout/show?conversation_id=123&customer_id=500&email=hs.match@plausible.test&token=#{token}"
162
- )
163
-
164
- assert html = html_response(conn, 200)
165
- assert html =~ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, user.id)
166
- assert html =~ "Some user notes"
167
- assert html =~ "My personal sites"
168
- assert html =~ "HS Integration Test Team"
169
- end
170
-
171
- test "returns personal team details when identifier passed explicitly", %{conn: conn} do
172
- user = new_user(email: "hs.match@plausible.test", notes: "Some user notes")
173
- other_user = new_user()
174
- _site1 = new_site(owner: user)
175
- _site2 = new_site(owner: other_user)
176
- team1 = team_of(user)
177
- team2 = team_of(other_user)
178
-
179
- team2 =
180
- team2
181
- |> Plausible.Teams.complete_setup()
182
- |> Ecto.Changeset.change(name: "HS Integration Test Team")
183
- |> Plausible.Repo.update!()
184
-
185
- add_member(team2, user: user, role: :owner)
186
-
187
- token = sign_conversation_token("123")
188
-
189
- conn =
190
- conn
191
- |> get(
192
- "/helpscout/show?conversation_id=123&customer_id=500&email=hs.match@plausible.test&team_identifier=#{team1.identifier}&token=#{token}"
193
- )
194
-
195
- assert html = html_response(conn, 200)
196
- refute html =~ "HS Integration Test Team"
197
- refute html =~ "My personal sites"
198
- assert html =~ "Some user notes"
199
- end
200
-
201
- test "returns setup team details when identifier passed explicitly", %{conn: conn} do
202
- user = new_user(email: "hs.match@plausible.test", notes: "Some user notes")
203
- other_user = new_user()
204
- _site1 = new_site(owner: user)
205
- _site2 = new_site(owner: other_user)
206
- _team1 = team_of(user)
207
- team2 = team_of(other_user)
208
-
209
- team2 =
210
- team2
211
- |> Plausible.Teams.complete_setup()
212
- |> Ecto.Changeset.change(name: "HS Integration Test Team")
213
- |> Plausible.Repo.update!()
214
-
215
- add_member(team2, user: user, role: :owner)
216
-
217
- token = sign_conversation_token("123")
218
-
219
- conn =
220
- conn
221
- |> get(
222
- "/helpscout/show?conversation_id=123&customer_id=500&email=hs.match@plausible.test&team_identifier=#{team2.identifier}&token=#{token}"
223
- )
224
-
225
- assert html = html_response(conn, 200)
226
- assert html =~ "HS Integration Test Team"
227
- refute html =~ "My personal sites"
228
- assert html =~ "Some user notes"
229
- end
230
-
231
- test "returns error when token is invalid", %{conn: conn} do
232
- conn =
233
- get(
234
- conn,
235
- "/helpscout/show?conversation_id=123&customer_id=500&email=hs.match@plausible.test&token=invalid"
236
- )
237
-
238
- assert html_response(conn, 200) =~ "invalid_token"
239
- end
240
-
241
- test "returns error when token does not match", %{conn: conn} do
242
- token = sign_conversation_token("456")
243
-
244
- conn =
245
- conn
246
- |> get(
247
- "/helpscout/show?conversation_id=123&customer_id=500&email=hs.match@plausible.test&token=#{token}"
248
- )
249
-
250
- assert html_response(conn, 200) =~ "invalid_conversation"
251
- end
252
- end
253
-
254
- defp sign_conversation_token(conversation_id) do
255
- PlausibleWeb.HelpScoutController.sign_token(conversation_id)
256
- end
257
- end
258
- end