@@ -71,9 +71,8 @@ pub struct AutomodMessageHoldV1Payload {
7171#[ cfg( test) ]
7272#[ test]
7373fn parse_payload_v1 ( ) {
74- use crate :: eventsub:: { Event , Message } ;
75-
76- let payload = r##"
74+ crate :: eventsub:: assert_eventsub_snapshot!(
75+ r##"
7776 {
7877 "subscription": {
7978 "id": "e523fda0-01b6-4b0e-9024-a5a80c5ad680",
@@ -115,22 +114,8 @@ fn parse_payload_v1() {
115114 "held_at": "2024-10-19T20:11:16.799750627Z"
116115 }
117116 }
118- "## ;
119-
120- let val = Event :: parse ( payload) . unwrap ( ) ;
121- crate :: tests:: roundtrip ( & val) ;
122-
123- let Event :: AutomodMessageHoldV1 ( val) = val else {
124- panic ! ( "invalid event type" ) ;
125- } ;
126- let Message :: Notification ( notif) = val. message else {
127- panic ! ( "invalid message type" ) ;
128- } ;
129-
130- assert_eq ! ( notif. broadcaster_user_id. as_str( ) , "129546453" ) ;
131- assert_eq ! ( notif. category, AutomodCategory :: Sexwords ) ;
132- assert_eq ! ( notif. level, 4 ) ;
133- assert_eq ! ( notif. message. fragments. len( ) , 1 ) ;
117+ "##
118+ ) ;
134119}
135120
136121/// [`automod.message.hold`](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#automodmessagehold-v2): a message was caught by automod for review.
@@ -200,9 +185,8 @@ pub struct AutomodMessageHoldV2Payload {
200185
201186#[ test]
202187fn parse_payload_v2_automod ( ) {
203- use crate :: eventsub:: { Event , Message } ;
204-
205- let payload = r##"
188+ crate :: eventsub:: assert_eventsub_snapshot!(
189+ r##"
206190 {
207191 "subscription": {
208192 "id": "85c8dcb0-7af4-4581-b684-32087d386384",
@@ -260,40 +244,14 @@ fn parse_payload_v2_automod() {
260244 "held_at": "2024-11-18T16:59:46.323937273Z"
261245 }
262246 }
263- "## ;
264-
265- let val = Event :: parse ( payload) . unwrap ( ) ;
266- crate :: tests:: roundtrip ( & val) ;
267-
268- let Event :: AutomodMessageHoldV2 ( val) = val else {
269- panic ! ( "invalid event type" ) ;
270- } ;
271- let Message :: Notification ( notif) = val. message else {
272- panic ! ( "invalid message type" ) ;
273- } ;
274-
275- assert_eq ! ( notif. broadcaster_user_id. as_str( ) , "129546453" ) ;
276- assert_eq ! ( notif. message. fragments. len( ) , 2 ) ;
277-
278- let AutomodHeldReason :: Automod ( automod) = & notif. reason else {
279- panic ! ( "invalid held reason" ) ;
280- } ;
281- assert_eq ! ( automod. category, AutomodCategory :: Swearing ) ;
282- assert_eq ! ( automod. level, 4 ) ;
283- assert_eq ! (
284- automod. boundaries,
285- & [ AutomodMessageBoundary {
286- start_pos: 2 ,
287- end_pos: 4
288- } ]
247+ "##
289248 ) ;
290249}
291250
292251#[ test]
293252fn parse_payload_v2_blocked_term ( ) {
294- use crate :: eventsub:: { Event , Message } ;
295-
296- let payload = r##"
253+ crate :: eventsub:: assert_eventsub_snapshot!(
254+ r##"
297255 {
298256 "subscription": {
299257 "id": "85c8dcb0-7af4-4581-b684-32087d386384",
@@ -398,34 +356,6 @@ fn parse_payload_v2_blocked_term() {
398356 "held_at": "2024-11-18T16:58:41.476117057Z"
399357 }
400358 }
401- "## ;
402-
403- let val = Event :: parse ( payload) . unwrap ( ) ;
404- crate :: tests:: roundtrip ( & val) ;
405-
406- let Event :: AutomodMessageHoldV2 ( val) = val else {
407- panic ! ( "invalid event type" ) ;
408- } ;
409- let Message :: Notification ( notif) = val. message else {
410- panic ! ( "invalid message type" ) ;
411- } ;
412-
413- assert_eq ! ( notif. broadcaster_user_id. as_str( ) , "129546453" ) ;
414- assert_eq ! ( notif. message. fragments. len( ) , 7 ) ;
415-
416- let AutomodHeldReason :: BlockedTerm ( blocked_term) = & notif. reason else {
417- panic ! ( "invalid held reason" ) ;
418- } ;
419- assert_eq ! ( blocked_term. terms_found. len( ) , 2 ) ;
420- assert_eq ! (
421- blocked_term. terms_found[ 0 ] . term_id. as_str( ) ,
422- "e4d4f1ba-99bf-4b19-9875-cd4eda98ead9"
423- ) ;
424- assert_eq ! (
425- blocked_term. terms_found[ 0 ] . boundary,
426- AutomodMessageBoundary {
427- start_pos: 15 ,
428- end_pos: 17
429- }
359+ "##
430360 ) ;
431361}
0 commit comments