@@ -21,6 +21,8 @@ const diagnosticOrigin = {
21
21
22
22
const diagnosticLogger = {
23
23
debug ( ) {
24
+ } ,
25
+ error ( ) {
24
26
}
25
27
} ;
26
28
@@ -54,11 +56,15 @@ function prepareDiagnostic() {
54
56
mock . method ( diagnosticOrigin , 'body' ) ;
55
57
mock . method ( diagnosticOrigin , 'headers' ) ;
56
58
57
- diagnosticLogger . message = null ;
59
+ diagnosticLogger . options = { } ;
58
60
diagnosticLogger . debug = ( message ) => {
59
- diagnosticLogger . message = message ;
61
+ diagnosticLogger . options . message = message ;
62
+ } ;
63
+ diagnosticLogger . error = ( message ) => {
64
+ diagnosticLogger . options . error = message ;
60
65
} ;
61
66
mock . method ( diagnosticLogger , 'debug' ) ;
67
+ mock . method ( diagnosticLogger , 'error' ) ;
62
68
}
63
69
64
70
function resetDiagnostic ( ) {
@@ -144,18 +150,34 @@ describe('LoggedInputRequest', () => {
144
150
beforeEach ( prepareDiagnostic ) ;
145
151
afterEach ( resetDiagnostic ) ;
146
152
153
+ it ( 'should call flush of origin' , async ( ) => {
154
+ await new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ;
155
+
156
+ assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 1 ) ;
157
+ } ) ;
158
+
147
159
it ( 'should call debug of logger' , async ( ) => {
148
160
await new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ;
149
161
150
162
assert . strictEqual ( diagnosticLogger . debug . mock . calls . length , 1 ) ;
151
163
} ) ;
152
164
153
- it ( 'should call flush of origin' , async ( ) => {
165
+ it ( 'should call error of logger' , async ( ) => {
166
+ diagnosticOrigin . flush = ( ) => { throw new Error ( 'flush error' ) } ;
167
+ mock . method ( diagnosticOrigin , 'flush' ) ;
168
+
169
+ await assert . rejects ( ( ) => new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ) ;
170
+
171
+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 1 ) ;
172
+ } ) ;
173
+
174
+ it ( 'should not call error of logger' , async ( ) => {
154
175
await new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ;
155
176
156
- assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 1 ) ;
177
+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 0 ) ;
157
178
} ) ;
158
179
180
+
159
181
it ( 'should fall when call debug of logger, cause null' , async ( ) => {
160
182
await assert . rejects ( ( ) => new LoggedInputRequest ( null , null , { } ) . flush ( ) ,
161
183
{ name : 'TypeError' } ) ;
@@ -178,11 +200,15 @@ describe('LoggedInputRequest', () => {
178
200
} ) ;
179
201
180
202
it ( 'should fall when call flush of origin, cause null' , async ( ) => {
181
- await assert . rejects ( ( ) => new LoggedInputRequest ( null , diagnosticLogger , { } ) . flush ( ) ,
203
+ await assert . rejects ( ( ) => new LoggedInputRequest (
204
+ null , diagnosticLogger , { method : 'method' , url : 'url' }
205
+ ) . flush ( ) ,
182
206
{ name : 'TypeError' } ) ;
183
207
184
208
assert . strictEqual ( diagnosticLogger . debug . mock . calls . length , 1 ) ;
185
209
assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 0 ) ;
210
+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 1 ) ;
211
+ assert . strictEqual ( diagnosticLogger . options . error . includes ( 'HttpRequest: [method] url error:' ) , true )
186
212
} ) ;
187
213
188
214
it ( 'should fall when call flush of origin, cause error' , async ( ) => {
@@ -191,11 +217,15 @@ describe('LoggedInputRequest', () => {
191
217
} ;
192
218
mock . method ( diagnosticOrigin , 'flush' ) ;
193
219
194
- await assert . rejects ( ( ) => new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ,
220
+ await assert . rejects ( ( ) => new LoggedInputRequest (
221
+ diagnosticOrigin , diagnosticLogger , { method : 'method' , url : 'url' }
222
+ ) . flush ( ) ,
195
223
{ message : 'flush error' } ) ;
196
224
197
225
assert . strictEqual ( diagnosticLogger . debug . mock . calls . length , 1 ) ;
198
226
assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 1 ) ;
227
+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 1 ) ;
228
+ assert . strictEqual ( diagnosticLogger . options . error . includes ( 'HttpRequest: [method] url error: flush error' ) , true )
199
229
} ) ;
200
230
201
231
it ( 'should log correct message' , async ( ) => {
@@ -205,7 +235,7 @@ describe('LoggedInputRequest', () => {
205
235
headers : { header : 'header' }
206
236
} ) . flush ( ) ;
207
237
208
- assert . strictEqual ( diagnosticLogger . message , 'HttpRequest: [method] url {"header":"header"}' ) ;
238
+ assert . strictEqual ( diagnosticLogger . options . message , 'HttpRequest: [method] url {"header":"header"}' ) ;
209
239
} ) ;
210
240
211
241
it ( 'should return another LoggedInputRequest' , async ( ) => {
0 commit comments