@@ -74,30 +74,49 @@ describe("showEmailMessage", () => {
7474 } ) ;
7575
7676 it ( "should handle message without HTML content" , async ( ) => {
77+ const consoleWarnSpy = jest
78+ . spyOn ( console , "warn" )
79+ . mockImplementation ( ( ) => { } ) ;
7780 ( sandboxClient as any ) . testing . messages . getHtmlMessage . mockRejectedValue (
7881 new Error ( "No HTML" )
7982 ) ;
8083
8184 const result = await showEmailMessage ( { message_id : 1 } ) ;
8285
86+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
87+ "Could not retrieve HTML content:" ,
88+ expect . any ( Error )
89+ ) ;
8390 expect ( result . content [ 0 ] . text ) . toContain ( "Sandbox Email Message Details" ) ;
8491 expect ( result . content [ 0 ] . text ) . toContain ( "Text Content" ) ;
8592 expect ( result . content [ 0 ] . text ) . not . toContain ( "HTML Content" ) ;
93+ consoleWarnSpy . mockRestore ( ) ;
8694 } ) ;
8795
8896 it ( "should handle message without text content" , async ( ) => {
97+ const consoleWarnSpy = jest
98+ . spyOn ( console , "warn" )
99+ . mockImplementation ( ( ) => { } ) ;
89100 ( sandboxClient as any ) . testing . messages . getTextMessage . mockRejectedValue (
90101 new Error ( "No text" )
91102 ) ;
92103
93104 const result = await showEmailMessage ( { message_id : 1 } ) ;
94105
106+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
107+ "Could not retrieve text content:" ,
108+ expect . any ( Error )
109+ ) ;
95110 expect ( result . content [ 0 ] . text ) . toContain ( "Sandbox Email Message Details" ) ;
96111 expect ( result . content [ 0 ] . text ) . toContain ( "HTML Content" ) ;
97112 expect ( result . content [ 0 ] . text ) . not . toContain ( "Text Content" ) ;
113+ consoleWarnSpy . mockRestore ( ) ;
98114 } ) ;
99115
100116 it ( "should handle message without both HTML and text" , async ( ) => {
117+ const consoleWarnSpy = jest
118+ . spyOn ( console , "warn" )
119+ . mockImplementation ( ( ) => { } ) ;
101120 ( sandboxClient as any ) . testing . messages . getHtmlMessage . mockRejectedValue (
102121 new Error ( "No HTML" )
103122 ) ;
@@ -107,10 +126,19 @@ describe("showEmailMessage", () => {
107126
108127 const result = await showEmailMessage ( { message_id : 1 } ) ;
109128
129+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
130+ "Could not retrieve HTML content:" ,
131+ expect . any ( Error )
132+ ) ;
133+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
134+ "Could not retrieve text content:" ,
135+ expect . any ( Error )
136+ ) ;
110137 expect ( result . content [ 0 ] . text ) . toContain ( "Sandbox Email Message Details" ) ;
111138 expect ( result . content [ 0 ] . text ) . toContain (
112139 "Message body content could not be retrieved"
113140 ) ;
141+ consoleWarnSpy . mockRestore ( ) ;
114142 } ) ;
115143
116144 it ( "should handle null message response" , async ( ) => {
@@ -125,17 +153,28 @@ describe("showEmailMessage", () => {
125153 } ) ;
126154
127155 it ( "should handle missing MAILTRAP_TEST_INBOX_ID" , async ( ) => {
156+ const consoleErrorSpy = jest
157+ . spyOn ( console , "error" )
158+ . mockImplementation ( ( ) => { } ) ;
128159 delete process . env . MAILTRAP_TEST_INBOX_ID ;
129160
130161 const result = await showEmailMessage ( { message_id : 1 } ) ;
131162
163+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
164+ "Error showing sandbox email message:" ,
165+ expect . anything ( )
166+ ) ;
132167 expect ( result . isError ) . toBe ( true ) ;
133168 expect ( result . content [ 0 ] . text ) . toContain (
134169 "MAILTRAP_TEST_INBOX_ID environment variable is required"
135170 ) ;
171+ consoleErrorSpy . mockRestore ( ) ;
136172 } ) ;
137173
138174 it ( "should handle missing sandbox client" , async ( ) => {
175+ const consoleErrorSpy = jest
176+ . spyOn ( console , "error" )
177+ . mockImplementation ( ( ) => { } ) ;
139178 // Mock sandboxClient as null for this test
140179 jest . doMock ( "../../../client" , ( ) => ( {
141180 sandboxClient : null ,
@@ -151,22 +190,35 @@ describe("showEmailMessage", () => {
151190 jest . dontMock ( "../../../client" ) ;
152191 jest . resetModules ( ) ;
153192
193+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
194+ "Error showing sandbox email message:" ,
195+ expect . anything ( )
196+ ) ;
154197 expect ( result . isError ) . toBe ( true ) ;
155198 expect ( result . content [ 0 ] . text ) . toContain ( "Sandbox client is not available" ) ;
199+ consoleErrorSpy . mockRestore ( ) ;
156200 } ) ;
157201
158202 it ( "should handle API errors" , async ( ) => {
159203 const mockError = new Error ( "API Error" ) ;
160204 ( sandboxClient as any ) . testing . messages . showEmailMessage . mockRejectedValue (
161205 mockError
162206 ) ;
207+ const consoleErrorSpy = jest
208+ . spyOn ( console , "error" )
209+ . mockImplementation ( ( ) => { } ) ;
163210
164211 const result = await showEmailMessage ( { message_id : 1 } ) ;
165212
213+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
214+ "Error showing sandbox email message:" ,
215+ mockError
216+ ) ;
166217 expect ( result . isError ) . toBe ( true ) ;
167218 expect ( result . content [ 0 ] . text ) . toContain (
168219 "Failed to show sandbox email message"
169220 ) ;
170221 expect ( result . content [ 0 ] . text ) . toContain ( "API Error" ) ;
222+ consoleErrorSpy . mockRestore ( ) ;
171223 } ) ;
172224} ) ;
0 commit comments