@@ -191,12 +191,13 @@ tap.test('createServer:', t => {
191191 }
192192 }
193193 const payload = JSON . stringify ( mock )
194+ const SERVER_URL = 'http://localhost:8001'
194195
195196 t . test ( 'it should use the default format when mime type is unknown' , t => {
196197 _boot ( [ ] , ( ) => {
197198 return request ( {
198199 method : 'POST' ,
199- url : `http://localhost:8001/` ,
200+ url : SERVER_URL + '/' ,
200201 headers : {
201202 'Accept' : 'invalid_format'
202203 } ,
@@ -209,6 +210,47 @@ tap.test('createServer:', t => {
209210 } )
210211 } )
211212
213+ t . test ( 'it should return figure in requested format' , t => {
214+ _boot ( [ ] , ( ) => {
215+ return request ( {
216+ method : 'POST' ,
217+ url : SERVER_URL + '/' ,
218+ headers : {
219+ 'Accept' : 'image/svg+xml'
220+ } ,
221+ body : payload
222+ } , ( err , res , body ) => {
223+ if ( err ) t . fail ( err )
224+
225+ t . equal ( res . statusCode , 200 , 'code' )
226+ t . equal ( res . headers [ 'content-type' ] , 'image/svg+xml' )
227+ t . end ( )
228+ } )
229+ } )
230+ } )
231+
232+ t . test ( 'it should be overriden by format provided in payload' , t => {
233+ _boot ( [ ] , ( ) => {
234+ request ( {
235+ method : 'POST' ,
236+ url : SERVER_URL + '/' ,
237+ headers : {
238+ 'Accept' : 'image/svg+xml'
239+ } ,
240+ body : JSON . stringify ( {
241+ format : 'png' ,
242+ figure : mock
243+ } )
244+ } , ( err , res , body ) => {
245+ if ( err ) t . fail ( err )
246+
247+ t . equal ( res . statusCode , 200 , 'code' )
248+ t . equal ( res . headers [ 'content-type' ] , 'image/png' )
249+ t . end ( )
250+ } )
251+ } )
252+ } )
253+
212254 t . done ( )
213255 } )
214256
0 commit comments