@@ -13,7 +13,7 @@ describe('submitContactInfo', () => {
1313 } )
1414
1515 const testContactDTO : ContactDTO = {
16- targetId : 6 ,
16+ targetId : 1 ,
1717 subject : 'Data Question' ,
1818 body : 'Please help me understand your data. Thank you!' ,
1919@@ -22,23 +22,27 @@ describe('submitContactInfo', () => {
2222 const sut : ContactRepository = new ContactRepository ( )
2323
2424 test ( 'should return ContactDTO when contact info is successfully submitted' , async ( ) => {
25- const contactInfo = await sut . submitContactInfo ( testContactDTO )
26-
27- expect ( contactInfo ) . toBeDefined ( )
28- expect ( contactInfo [ 0 ] . fromEmail ) . toEqual ( testContactDTO . fromEmail )
29- expect ( contactInfo [ 0 ] . subject ) . toBeDefined ( )
30- expect ( contactInfo [ 0 ] . body ) . toBeDefined ( )
31- expect ( contactInfo [ 0 ] . toEmail ) . toBeDefined ( )
32- } )
33-
34- test ( 'should return error if the target id is unexisted' , async ( ) => {
35- const invalidContactDTO : ContactDTO = {
36- targetId : 0 ,
37- subject : '' ,
38- body : '' ,
39- fromEmail : ''
25+ try {
26+ const contactInfo = await sut . submitContactInfo ( testContactDTO )
27+ expect ( contactInfo ) . toBeDefined ( )
28+ expect ( contactInfo [ 0 ] . fromEmail ) . toEqual ( testContactDTO . fromEmail )
29+ expect ( contactInfo [ 0 ] . subject ) . toEqual ( expect . any ( String ) )
30+ expect ( contactInfo [ 0 ] . body ) . toEqual ( expect . any ( String ) )
31+ expect ( contactInfo [ 0 ] . toEmail ) . toEqual ( expect . any ( String ) )
32+ } catch ( error ) {
33+ console . error ( 'Error during submission:' , error . message , error . response ?. data )
34+ throw error
4035 }
41- const expectedError = new WriteError ( `[400] Feedback target object not found` )
42- await expect ( sut . submitContactInfo ( invalidContactDTO ) ) . rejects . toThrow ( expectedError )
36+
37+ test ( 'should return error if the target id is unexisted' , async ( ) => {
38+ const invalidContactDTO : ContactDTO = {
39+ targetId : 0 ,
40+ subject : '' ,
41+ body : '' ,
42+ fromEmail : ''
43+ }
44+ const expectedError = new WriteError ( `[400] Feedback target object not found` )
45+ await expect ( sut . submitContactInfo ( invalidContactDTO ) ) . rejects . toThrow ( expectedError )
46+ } )
4347 } )
4448} )
0 commit comments