@@ -24,24 +24,39 @@ test('test retrieve from good source', async () => {
2424 expect ( result . xml ) . toBe ( '<div>this is content</div>' )
2525} )
2626
27- test ( 'test retrieve with invalid content type' , async ( ) => {
27+ test ( 'test retrieve from good source, but having \\r\\n before/after root xml' , async ( ) => {
28+ const url = 'https://some.where/good/page'
29+ const { baseUrl, path } = parseUrl ( url )
30+ nock ( baseUrl ) . head ( path ) . reply ( 200 )
31+ nock ( baseUrl ) . get ( path ) . reply ( 200 , '\n\r\r\n\n<div>this is content</div>\n\r\r\n\n' , {
32+ 'Content-Type' : 'application/xml'
33+ } )
34+ const result = await retrieve ( url )
35+ expect ( result . xml ) . toBe ( '<div>this is content</div>' )
36+ } )
37+
38+ test ( 'test retrieve with invalid response content type' , async ( ) => {
2839 const url = 'https://some.where/bad/page'
2940 const { baseUrl, path } = parseUrl ( url )
3041 nock ( baseUrl ) . head ( path ) . reply ( 200 )
3142 nock ( baseUrl ) . get ( path ) . reply ( 200 , '' , {
3243 'Content-Type' : 'something/strange'
3344 } )
3445 const result = await retrieve ( url )
35- expect ( result ) . toBe ( null )
46+ expect ( typeof result ) . toBe ( 'object' )
47+ expect ( typeof result . error ) . toBe ( 'object' )
48+ expect ( typeof result . error . message ) . toBe ( 'string' )
3649} )
3750
38- test ( 'test retrieve with invalid status' , async ( ) => {
51+ test ( 'test retrieve with invalid response status code ' , async ( ) => {
3952 const url = 'https://some.where/bad/page'
4053 const { baseUrl, path } = parseUrl ( url )
4154 nock ( baseUrl ) . head ( path ) . reply ( 500 )
4255 nock ( baseUrl ) . get ( path ) . reply ( 500 , '<xml><message>Error 500</message></xml>' , {
4356 'Content-Type' : 'application/xml'
4457 } )
4558 const result = await retrieve ( url )
46- expect ( result ) . toBe ( null )
59+ expect ( typeof result ) . toBe ( 'object' )
60+ expect ( typeof result . error ) . toBe ( 'object' , result . error )
61+ expect ( typeof result . error . message ) . toBe ( 'string' )
4762} )
0 commit comments