@@ -30,65 +30,84 @@ class SentryFeedbackTests: XCTestCase {
3030 }
3131
3232 func testSerializeWithAllFields( ) throws {
33- let sut = SentryFeedback ( message
: " Test feedback message " , name
: " Test feedback provider " , email
: " [email protected] " , attachments
: [ Data ( ) ] ) 34-
33+ let attachment = Attachment ( data: Data ( ) , filename: " screenshot.png " , contentType: " image/png " )
34+ let sut = SentryFeedback ( message
: " Test feedback message " , name
: " Test feedback provider " , email
: " [email protected] " , attachments
: [ attachment
] ) 35+
3536 let serialization = sut. serialize ( )
3637 XCTAssertEqual ( try XCTUnwrap ( serialization [ " message " ] as? String ) , " Test feedback message " )
3738 XCTAssertEqual ( try XCTUnwrap ( serialization [ " name " ] as? String ) , " Test feedback provider " )
3839 XCTAssertEqual ( try XCTUnwrap ( serialization [ " contact_email " ] as? String ) , " [email protected] " ) 3940 XCTAssertEqual ( try XCTUnwrap ( serialization [ " source " ] as? String ) , " widget " )
40-
41+
4142 let attachments = sut. attachmentsForEnvelope ( )
4243 XCTAssertEqual ( attachments. count, 1 )
4344 XCTAssertEqual ( try XCTUnwrap ( attachments. first) . filename, " screenshot.png " )
44- XCTAssertEqual ( try XCTUnwrap ( attachments. first) . contentType, " application /png" )
45+ XCTAssertEqual ( try XCTUnwrap ( attachments. first) . contentType, " image /png" )
4546 }
4647
4748 func testSerializeCustomFeedback( ) throws {
48- let sut = SentryFeedback ( message
: " Test feedback message " , name
: " Test feedback provider " , email
: " [email protected] " , source
: . custom
, attachments
: [ Data ( ) ] ) 49-
49+ let attachment = Attachment ( data: Data ( ) , filename: " screenshot.png " , contentType: " image/png " )
50+ let sut = SentryFeedback ( message
: " Test feedback message " , name
: " Test feedback provider " , email
: " [email protected] " , source
: . custom
, attachments
: [ attachment
] ) 51+
5052 let serialization = sut. serialize ( )
5153 XCTAssertEqual ( try XCTUnwrap ( serialization [ " message " ] as? String ) , " Test feedback message " )
5254 XCTAssertEqual ( try XCTUnwrap ( serialization [ " name " ] as? String ) , " Test feedback provider " )
5355 XCTAssertEqual ( try XCTUnwrap ( serialization [ " contact_email " ] as? String ) , " [email protected] " ) 5456 XCTAssertEqual ( try XCTUnwrap ( serialization [ " source " ] as? String ) , " custom " )
55-
57+
5658 let attachments = sut. attachmentsForEnvelope ( )
5759 XCTAssertEqual ( attachments. count, 1 )
5860 XCTAssertEqual ( try XCTUnwrap ( attachments. first) . filename, " screenshot.png " )
59- XCTAssertEqual ( try XCTUnwrap ( attachments. first) . contentType, " application /png" )
61+ XCTAssertEqual ( try XCTUnwrap ( attachments. first) . contentType, " image /png" )
6062 }
6163
6264 func testSerializeWithAssociatedEventID( ) throws {
6365 let eventID = SentryId ( )
64-
65- let sut = SentryFeedback ( message
: " Test feedback message " , name
: " Test feedback provider " , email
: " [email protected] " , source
: . custom
, associatedEventId
: eventID
, attachments
: [ Data ( ) ] ) 66-
66+ let attachment = Attachment ( data : Data ( ) , filename : " screenshot.png " , contentType : " image/png " )
67+ let sut = SentryFeedback ( message
: " Test feedback message " , name
: " Test feedback provider " , email
: " [email protected] " , source
: . custom
, associatedEventId
: eventID
, attachments
: [ attachment ] ) 68+
6769 let serialization = sut. serialize ( )
6870 XCTAssertEqual ( try XCTUnwrap ( serialization [ " message " ] as? String ) , " Test feedback message " )
6971 XCTAssertEqual ( try XCTUnwrap ( serialization [ " name " ] as? String ) , " Test feedback provider " )
7072 XCTAssertEqual ( try XCTUnwrap ( serialization [ " contact_email " ] as? String ) , " [email protected] " ) 7173 XCTAssertEqual ( try XCTUnwrap ( serialization [ " source " ] as? String ) , " custom " )
7274 XCTAssertEqual ( try XCTUnwrap ( serialization [ " associated_event_id " ] as? String ) , eventID. sentryIdString)
73-
75+
7476 let attachments = sut. attachmentsForEnvelope ( )
7577 XCTAssertEqual ( attachments. count, 1 )
7678 XCTAssertEqual ( try XCTUnwrap ( attachments. first) . filename, " screenshot.png " )
77- XCTAssertEqual ( try XCTUnwrap ( attachments. first) . contentType, " application /png" )
79+ XCTAssertEqual ( try XCTUnwrap ( attachments. first) . contentType, " image /png" )
7880 }
7981
8082 func testSerializeWithNoOptionalFields( ) throws {
8183 let sut = SentryFeedback ( message: " Test feedback message " , name: nil , email: nil )
82-
84+
8385 let serialization = sut. serialize ( )
8486 XCTAssertEqual ( try XCTUnwrap ( serialization [ " message " ] as? String ) , " Test feedback message " )
8587 XCTAssertNil ( serialization [ " name " ] )
8688 XCTAssertNil ( serialization [ " contact_email " ] )
8789 XCTAssertEqual ( try XCTUnwrap ( serialization [ " source " ] as? String ) , " widget " )
88-
90+
8991 let attachments = sut. attachmentsForEnvelope ( )
9092 XCTAssertEqual ( attachments. count, 0 )
9193 }
94+
95+ func testMultipleAttachments( ) throws {
96+ let screenshot = Attachment ( data: Data ( " screenshot " . utf8) , filename: " screenshot.png " , contentType: " image/png " )
97+ let logFile = Attachment ( data: Data ( " log content " . utf8) , filename: " app.log " , contentType: " text/plain " )
98+ let videoFile = Attachment ( data: Data ( " video " . utf8) , filename: " recording.mp4 " , contentType: " video/mp4 " )
99+
100+ let sut = SentryFeedback ( message
: " Test feedback with multiple attachments " , name
: " Test User " , email
: " [email protected] " , attachments
: [ screenshot
, logFile
, videoFile
] ) 101+
102+ let attachments = sut. attachmentsForEnvelope ( )
103+ XCTAssertEqual ( attachments. count, 3 )
104+ XCTAssertEqual ( attachments [ 0 ] . filename, " screenshot.png " )
105+ XCTAssertEqual ( attachments [ 0 ] . contentType, " image/png " )
106+ XCTAssertEqual ( attachments [ 1 ] . filename, " app.log " )
107+ XCTAssertEqual ( attachments [ 1 ] . contentType, " text/plain " )
108+ XCTAssertEqual ( attachments [ 2 ] . filename, " recording.mp4 " )
109+ XCTAssertEqual ( attachments [ 2 ] . contentType, " video/mp4 " )
110+ }
92111
93112 private let inputCombinations : [ FeedbackTestCase ] = [
94113 // base case: don't require name or email, don't input a name or email, don't input a message or screenshot
0 commit comments