Skip to content

Commit 47e7925

Browse files
♻️ add more tests
1 parent 7dae80b commit 47e7925

File tree

1 file changed

+84
-101
lines changed

1 file changed

+84
-101
lines changed

tests/sentry/replays/lib/test_summarize.py

Lines changed: 84 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ def _faker() -> Generator[tuple[int, memoryview]]:
110110
def test_as_log_message() -> None:
111111
"""Basic coverage for events that do not have dedicated test cases yet."""
112112

113-
event = {
114-
"type": 5,
115-
"timestamp": 0.0,
116-
"data": {"tag": "breadcrumb", "payload": {"category": "ui.click", "message": "div"}},
117-
}
118-
assert as_log_message(event) is not None
119-
120113
event = {
121114
"type": 5,
122115
"timestamp": 0.0,
@@ -155,100 +148,6 @@ def test_as_log_message() -> None:
155148
}
156149
assert as_log_message(event) is not None
157150

158-
event = {
159-
"type": 5,
160-
"timestamp": 0.0,
161-
"data": {
162-
"tag": "performanceSpan",
163-
"payload": {
164-
"op": "navigation.push",
165-
"description": "url",
166-
},
167-
},
168-
}
169-
assert as_log_message(event) is not None
170-
171-
event = {
172-
"type": 5,
173-
"timestamp": 0.0,
174-
"data": {
175-
"tag": "breadcrumb",
176-
"payload": {"category": "navigation", "data": {"to": "/"}},
177-
},
178-
}
179-
assert as_log_message(event) is None
180-
181-
event = {
182-
"type": 5,
183-
"timestamp": 0.0,
184-
"data": {"tag": "breadcrumb", "payload": {"category": "ui.blur"}},
185-
}
186-
assert as_log_message(event) is None
187-
188-
event = {
189-
"type": 5,
190-
"timestamp": 0.0,
191-
"data": {"tag": "breadcrumb", "payload": {"category": "ui.focus"}},
192-
}
193-
assert as_log_message(event) is None
194-
195-
event = {
196-
"type": 5,
197-
"timestamp": 0.0,
198-
"data": {
199-
"tag": "performanceSpan",
200-
"payload": {
201-
"op": "resource.fetch",
202-
"description": "https://www.z.com/path?q=true",
203-
"endTimestamp": 0.0,
204-
"startTimestamp": 0.0,
205-
"data": {
206-
"method": "GET",
207-
"statusCode": 404,
208-
"response": {"size": 0},
209-
},
210-
},
211-
},
212-
}
213-
assert as_log_message(event) is not None
214-
215-
event = {
216-
"type": 5,
217-
"timestamp": 0.0,
218-
"data": {
219-
"tag": "performanceSpan",
220-
"payload": {
221-
"op": "resource.fetch",
222-
"description": "https://www.z.com/path?q=true",
223-
"endTimestamp": 0.0,
224-
"startTimestamp": 0.0,
225-
"data": {
226-
"method": "GET",
227-
"statusCode": 404,
228-
"response": {"wrong": "wrong"},
229-
},
230-
},
231-
},
232-
}
233-
234-
result = as_log_message(event)
235-
assert result is not None
236-
assert "unknown" not in result
237-
238-
event = {
239-
"type": 5,
240-
"timestamp": 0.0,
241-
"data": {
242-
"tag": "performanceSpan",
243-
"payload": {
244-
"op": "web-vital",
245-
"description": "largest-contentful-paint",
246-
"data": {"size": 0, "rating": "good"},
247-
},
248-
},
249-
}
250-
assert as_log_message(event) is not None
251-
252151
event = {
253152
"type": 5,
254153
"timestamp": 0.0,
@@ -298,6 +197,70 @@ def test_as_log_message_click() -> None:
298197
)
299198

300199

200+
def test_as_log_message_lcp() -> None:
201+
event = (
202+
{
203+
"type": 5,
204+
"timestamp": 1756400489.048,
205+
"data": {
206+
"tag": "performanceSpan",
207+
"payload": {
208+
"op": "web-vital",
209+
"description": "largest-contentful-paint",
210+
"startTimestamp": 1756400489.048,
211+
"endTimestamp": 1756400489.048,
212+
"data": {"value": 623, "size": 623, "rating": "good"},
213+
},
214+
},
215+
},
216+
)
217+
assert (
218+
as_log_message(event)
219+
== "Application largest contentful paint: 623 ms and has a good rating at 1756400489048"
220+
)
221+
222+
223+
def test_as_log_message_navigation() -> None:
224+
event = (
225+
{
226+
"type": 5,
227+
"timestamp": 1756400579304,
228+
"data": {
229+
"tag": "breadcrumb",
230+
"payload": {
231+
"timestamp": 1756400579.304,
232+
"type": "default",
233+
"category": "navigation",
234+
"data": {
235+
"from": "https://url-example-previous.com",
236+
"to": "https://url-example.com",
237+
},
238+
},
239+
},
240+
},
241+
)
242+
assert as_log_message(event) is None
243+
244+
245+
def test_as_log_message_feedback() -> None:
246+
event = (
247+
{
248+
"type": 5,
249+
"timestamp": 1756400970768,
250+
"data": {
251+
"tag": "breadcrumb",
252+
"payload": {
253+
"timestamp": 1756400970.768,
254+
"type": "default",
255+
"category": "sentry.feedback",
256+
"data": {"feedbackId": "332f05068b2d43e6b5c5557ffecfcd0f"},
257+
},
258+
},
259+
},
260+
)
261+
assert as_log_message(event) is None
262+
263+
301264
def test_as_log_message_invalid_input() -> None:
302265
assert as_log_message({}) is None
303266
assert as_log_message({"blah": "wrong"}) is None
@@ -363,6 +326,26 @@ def test_as_log_message_resource_script() -> None:
363326
assert as_log_message(event) is None
364327

365328

329+
def test_as_log_message_navigation_span() -> None:
330+
event = (
331+
{
332+
"type": 5,
333+
"timestamp": 1756400579.304,
334+
"data": {
335+
"tag": "performanceSpan",
336+
"payload": {
337+
"op": "navigation.push",
338+
"description": "https://url-example.com",
339+
"startTimestamp": 1756400579.304,
340+
"endTimestamp": 1756400579.304,
341+
"data": {"previous": "https://url-example-prev.com"},
342+
},
343+
},
344+
},
345+
)
346+
assert as_log_message(event) == "User navigated to: https://url-example.com at 1756400579304"
347+
348+
366349
def test_as_log_message_long_console_message() -> None:
367350
event = {
368351
"type": 5,

0 commit comments

Comments
 (0)