@@ -21,6 +21,7 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
2121 let fileTranslationsApiFetchStub ;
2222 let fileTranslationsApiUaStub ;
2323 let responseMockJsonStub ;
24+ let getHeaderStub ;
2425
2526 beforeEach ( ( ) => {
2627 fileTranslationsApi = new SmartlingFileTranslationsApi (
@@ -37,12 +38,15 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
3738 responseMockJsonStub . returns ( {
3839 response : { }
3940 } ) ;
41+ getHeaderStub = sinon . stub ( responseMock . headers , "get" ) ;
42+ getHeaderStub . returns ( null ) ;
4043 } ) ;
4144
4245 afterEach ( ( ) => {
4346 fileTranslationsApiFetchStub . restore ( ) ;
4447 fileTranslationsApiUaStub . restore ( ) ;
4548 responseMockJsonStub . restore ( ) ;
49+ getHeaderStub . restore ( ) ;
4650 } ) ;
4751
4852 describe ( "Methods" , ( ) => {
@@ -362,15 +366,6 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
362366 it ( "Download translated file with metadata when no headers" , async ( ) => {
363367 const localeId = "de-DE" ;
364368
365- const downloadMock = {
366- status : 200 ,
367- arrayBuffer : async ( ) : Promise < ArrayBuffer > => new ArrayBuffer ( 1 ) ,
368- headers : {
369- get : ( ) : string | null => null
370- }
371- } ;
372- fileTranslationsApiFetchStub . returns ( downloadMock ) ;
373-
374369 const fileWithMetadata = await fileTranslationsApi . downloadTranslatedFileWithMetadata (
375370 accountUid , fileUid , mtUid , localeId
376371 ) ;
@@ -396,23 +391,9 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
396391 it ( "Download translated file with metadata" , async ( ) => {
397392 const localeId = "de-DE" ;
398393
399- const downloadMock = {
400- status : 200 ,
401- arrayBuffer : async ( ) : Promise < ArrayBuffer > => new ArrayBuffer ( 1 ) ,
402- headers : {
403- get : ( name : string ) : string | null => {
404- switch ( name ) {
405- case "content-type" :
406- return "application/xml" ;
407- case "content-disposition" :
408- return "attachment; filename=\"test.xml\"" ;
409- default :
410- return null ;
411- }
412- }
413- }
414- } ;
415- fileTranslationsApiFetchStub . returns ( downloadMock ) ;
394+ getHeaderStub . onCall ( 0 ) . returns ( "application/xml" ) ;
395+ getHeaderStub . onCall ( 1 ) . returns ( "attachment; filename=\"test.xml\"" ) ;
396+ getHeaderStub . returns ( null ) ;
416397
417398 const fileWithMetadata = await fileTranslationsApi . downloadTranslatedFileWithMetadata (
418399 accountUid , fileUid , mtUid , localeId
@@ -454,15 +435,6 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
454435 } ) ;
455436
456437 it ( "Download translated files with metadata when no headers" , async ( ) => {
457- const downloadMock = {
458- status : 200 ,
459- arrayBuffer : async ( ) : Promise < ArrayBuffer > => new ArrayBuffer ( 1 ) ,
460- headers : {
461- get : ( ) : string | null => null
462- }
463- } ;
464- fileTranslationsApiFetchStub . returns ( downloadMock ) ;
465-
466438 const fileWithMetadata = await fileTranslationsApi . downloadTranslatedFilesWithMetadata (
467439 accountUid , fileUid , mtUid
468440 ) ;
@@ -486,23 +458,9 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
486458 } ) ;
487459
488460 it ( "Download translated files with metadata" , async ( ) => {
489- const downloadMock = {
490- status : 200 ,
491- arrayBuffer : async ( ) : Promise < ArrayBuffer > => new ArrayBuffer ( 1 ) ,
492- headers : {
493- get : ( name : string ) : string | null => {
494- switch ( name ) {
495- case "content-type" :
496- return "application/zip" ;
497- case "content-disposition" :
498- return "attachment; filename=\"test.zip\"" ;
499- default :
500- return null ;
501- }
502- }
503- }
504- } ;
505- fileTranslationsApiFetchStub . returns ( downloadMock ) ;
461+ getHeaderStub . onCall ( 0 ) . returns ( "application/zip" ) ;
462+ getHeaderStub . onCall ( 1 ) . returns ( "attachment; filename=\"test.zip\"" ) ;
463+ getHeaderStub . returns ( null ) ;
506464
507465 const fileWithMetadata = await fileTranslationsApi . downloadTranslatedFilesWithMetadata (
508466 accountUid , fileUid , mtUid
0 commit comments