@@ -9,6 +9,8 @@ import { FtsUploadFileParameters } from "../api/file-translations/params/fts-upl
9
9
import { FileType } from "../api/files/params/file-type" ;
10
10
import { streamToString } from "./stream-to-string" ;
11
11
import { TranslateFileParameters } from "../api/file-translations/params/translate-file-parameters" ;
12
+ import { FtsCallbackMethod } from "../api/file-translations/params/fts-callback-method" ;
13
+ import { LanguageDetectionParameters } from "../api/file-translations/params/language-detection-parameters" ;
12
14
13
15
describe ( "SmartlingFileTranslationsApi class tests." , ( ) => {
14
16
const userAgent = "test_user_agent" ;
@@ -327,6 +329,78 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
327
329
) ;
328
330
} ) ;
329
331
332
+ it ( "Translate file with callback and without user data" , async ( ) => {
333
+ const params = new TranslateFileParameters ( ) ;
334
+
335
+ params
336
+ . setSourceLocaleId ( "en-US" )
337
+ . setTargetLocaleIds ( [ "de-DE" , "fr-FR" ] )
338
+ . setCallback ( {
339
+ url : "https://myhost.com" ,
340
+ httpMethod : FtsCallbackMethod . POST
341
+ } ) ;
342
+
343
+ await fileTranslationsApi . translateFile ( accountUid , fileUid , params ) ;
344
+
345
+ sinon . assert . calledOnceWithExactly (
346
+ fileTranslationsApiFetchStub ,
347
+ `https://test.com/file-translations-api/v2/accounts/${ accountUid } /files/${ fileUid } /mt` ,
348
+ {
349
+ method : "post" ,
350
+ headers : {
351
+ Authorization : "test_token_type test_access_token" ,
352
+ "Content-Type" : "application/json" ,
353
+ "User-Agent" : userAgent
354
+ } ,
355
+ body : JSON . stringify ( {
356
+ sourceLocaleId : "en-US" ,
357
+ targetLocaleIds : [ "de-DE" , "fr-FR" ] ,
358
+ callback : {
359
+ url : "https://myhost.com" ,
360
+ httpMethod : "POST"
361
+ }
362
+ } )
363
+ }
364
+ ) ;
365
+ } ) ;
366
+
367
+ it ( "Translate file with callback and user data" , async ( ) => {
368
+ const params = new TranslateFileParameters ( ) ;
369
+
370
+ params
371
+ . setSourceLocaleId ( "en-US" )
372
+ . setTargetLocaleIds ( [ "de-DE" , "fr-FR" ] )
373
+ . setCallback ( {
374
+ url : "https://myhost.com" ,
375
+ httpMethod : FtsCallbackMethod . POST ,
376
+ userData : "test user data"
377
+ } ) ;
378
+
379
+ await fileTranslationsApi . translateFile ( accountUid , fileUid , params ) ;
380
+
381
+ sinon . assert . calledOnceWithExactly (
382
+ fileTranslationsApiFetchStub ,
383
+ `https://test.com/file-translations-api/v2/accounts/${ accountUid } /files/${ fileUid } /mt` ,
384
+ {
385
+ method : "post" ,
386
+ headers : {
387
+ Authorization : "test_token_type test_access_token" ,
388
+ "Content-Type" : "application/json" ,
389
+ "User-Agent" : userAgent
390
+ } ,
391
+ body : JSON . stringify ( {
392
+ sourceLocaleId : "en-US" ,
393
+ targetLocaleIds : [ "de-DE" , "fr-FR" ] ,
394
+ callback : {
395
+ url : "https://myhost.com" ,
396
+ httpMethod : "POST" ,
397
+ userData : "test user data"
398
+ }
399
+ } )
400
+ }
401
+ ) ;
402
+ } ) ;
403
+
330
404
it ( "Get translation progress" , async ( ) => {
331
405
await fileTranslationsApi . getTranslationProgress ( accountUid , fileUid , mtUid ) ;
332
406
@@ -547,6 +621,86 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
547
621
) ;
548
622
} ) ;
549
623
624
+ it ( "Detect file language with empty parameters" , async ( ) => {
625
+ await fileTranslationsApi . detectFileLanguage (
626
+ accountUid , fileUid , new LanguageDetectionParameters ( )
627
+ ) ;
628
+
629
+ sinon . assert . calledOnceWithExactly (
630
+ fileTranslationsApiFetchStub ,
631
+ `https://test.com/file-translations-api/v2/accounts/${ accountUid } /files/${ fileUid } /language-detection` ,
632
+ {
633
+ method : "post" ,
634
+ headers : {
635
+ Authorization : "test_token_type test_access_token" ,
636
+ "Content-Type" : "application/json" ,
637
+ "User-Agent" : userAgent
638
+ } ,
639
+ body : JSON . stringify ( { } )
640
+ }
641
+ ) ;
642
+ } ) ;
643
+
644
+ it ( "Detect file language with callback and without user data" , async ( ) => {
645
+ const params = new LanguageDetectionParameters ( )
646
+ . setCallback ( {
647
+ url : "https://myhost.com" ,
648
+ httpMethod : FtsCallbackMethod . POST
649
+ } ) ;
650
+
651
+ await fileTranslationsApi . detectFileLanguage ( accountUid , fileUid , params ) ;
652
+
653
+ sinon . assert . calledOnceWithExactly (
654
+ fileTranslationsApiFetchStub ,
655
+ `https://test.com/file-translations-api/v2/accounts/${ accountUid } /files/${ fileUid } /language-detection` ,
656
+ {
657
+ method : "post" ,
658
+ headers : {
659
+ Authorization : "test_token_type test_access_token" ,
660
+ "Content-Type" : "application/json" ,
661
+ "User-Agent" : userAgent
662
+ } ,
663
+ body : JSON . stringify ( {
664
+ callback : {
665
+ url : "https://myhost.com" ,
666
+ httpMethod : "POST"
667
+ }
668
+ } )
669
+ }
670
+ ) ;
671
+ } ) ;
672
+
673
+ it ( "Detect file language with callback and with user data" , async ( ) => {
674
+ const params = new LanguageDetectionParameters ( )
675
+ . setCallback ( {
676
+ url : "https://myhost.com" ,
677
+ httpMethod : FtsCallbackMethod . POST ,
678
+ userData : "test user data"
679
+ } ) ;
680
+
681
+ await fileTranslationsApi . detectFileLanguage ( accountUid , fileUid , params ) ;
682
+
683
+ sinon . assert . calledOnceWithExactly (
684
+ fileTranslationsApiFetchStub ,
685
+ `https://test.com/file-translations-api/v2/accounts/${ accountUid } /files/${ fileUid } /language-detection` ,
686
+ {
687
+ method : "post" ,
688
+ headers : {
689
+ Authorization : "test_token_type test_access_token" ,
690
+ "Content-Type" : "application/json" ,
691
+ "User-Agent" : userAgent
692
+ } ,
693
+ body : JSON . stringify ( {
694
+ callback : {
695
+ url : "https://myhost.com" ,
696
+ httpMethod : "POST" ,
697
+ userData : "test user data"
698
+ }
699
+ } )
700
+ }
701
+ ) ;
702
+ } ) ;
703
+
550
704
it ( "Get language detection progress" , async ( ) => {
551
705
await fileTranslationsApi . getLanguageDetectionProgress (
552
706
accountUid ,
0 commit comments