jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/393172 )

Change subject: Add test for Yandex client
......................................................................


Add test for Yandex client

Similar to Changeset 393171.

Change-Id: Ie6722d22c559710b55f332dadacf40ee11e26e54
---
M lib/mt/Yandex.js
A test/mt/Yandex.test.js
2 files changed, 25 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Santhosh: Looks good to me, approved



diff --git a/lib/mt/Yandex.js b/lib/mt/Yandex.js
index 1840dfc..2b563ee 100644
--- a/lib/mt/Yandex.js
+++ b/lib/mt/Yandex.js
@@ -51,7 +51,8 @@
                        .then( ( response ) => response.body.text[ 0 ] )
                        .catch( ( response ) => {
                                throw new Error( 'Translation with Yandex 
failed. Error: ' +
-                                       this.getErrorName( response.body.code ) 
+ ' ' + sourceLang + '-' + targetLang );
+                                       this.getErrorName( response.body.code 
|| response.body ) +
+                                               ` for ${sourceLang} + '>' + 
${targetLang}` );
                        } );
        }
 
@@ -78,7 +79,7 @@
                        return errormap[ code ];
                }
 
-               return 'Unknown error';
+               return `Unknown error: ${code}`;
        }
 
        requiresAuthorization() {
diff --git a/test/mt/Yandex.test.js b/test/mt/Yandex.test.js
new file mode 100644
index 0000000..18c9059
--- /dev/null
+++ b/test/mt/Yandex.test.js
@@ -0,0 +1,22 @@
+'use strict';
+
+const assert = require( '../utils/assert.js' );
+const server = require( '../utils/server.js' );
+const Yandex = require( '../../lib/mt' ).Yandex;
+
+describe( 'Yandex machine translation', function () {
+       it( 'Should fail because of wrong key ', () => {
+               const cxConfig = server.config.service;
+               cxConfig.conf.mt.Yandex.key = 'wrongkey';
+               const yandex = new Yandex( cxConfig );
+               const testSourceContent = '<p>This is a <a 
href="/Test">test</a></p>';
+               assert.fails(
+                       yandex.translate( 'en', 'gu', testSourceContent ),
+                       function ( err ) {
+                               if ( ( err instanceof Error ) && /value/.test( 
err ) ) {
+                                       return true;
+                               }
+                       }
+               );
+       } );
+} );

-- 
To view, visit https://gerrit.wikimedia.org/r/393172
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie6722d22c559710b55f332dadacf40ee11e26e54
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: KartikMistry <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to