Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/393171 )
Change subject: Add test for Youdao client ...................................................................... Add test for Youdao client We cannot test the MT output since it require a valid key. This test helps to spot any other kind of errors in client code, such as js errors. Change-Id: I9738d71971753f470933cb42a1efffa86f18e54b --- M lib/mt/Youdao.js A test/mt/Youdao.test.js 2 files changed, 25 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/71/393171/1 diff --git a/lib/mt/Youdao.js b/lib/mt/Youdao.js index 03120d4..8f16a82 100644 --- a/lib/mt/Youdao.js +++ b/lib/mt/Youdao.js @@ -98,14 +98,13 @@ transtype: 'translate' } }; - return preq.post( postData ).then( ( response ) => { if ( response.body.errorCode === 0 ) { return response.body.translation[ 0 ]; } else { throw new Error( 'Translation with Youdao failed. Error: ' + - this.getErrorName( response.body.errorCode ) + - ' ' + sourceLang + '>' + targetLang ); + this.getErrorName( response.body || response.body.errorCode ) + + ` for ${sourceLang} > ${targetLang}` ); } } ); } @@ -133,7 +132,7 @@ return errormap[ code ]; } - return 'Unknown error'; + return `Unknown error: ${code}`; } requiresAuthorization() { diff --git a/test/mt/Youdao.test.js b/test/mt/Youdao.test.js new file mode 100644 index 0000000..caa6eff --- /dev/null +++ b/test/mt/Youdao.test.js @@ -0,0 +1,22 @@ +'use strict'; + +const assert = require( '../utils/assert.js' ); +const server = require( '../utils/server.js' ); +const Youdao = require( '../../lib/mt' ).Youdao; + +describe( 'Youdao machine translation', function () { + it( 'Should fail because of wrong key ', () => { + const cxConfig = server.config.service; + cxConfig.conf.mt.Youdao.key = 'wrongkey'; + const youdao = new Youdao( cxConfig ); + const testSourceContent = '<p>This is a <a href="/Test">test</a></p>'; + assert.fails( + youdao.translate( 'en', 'zh', testSourceContent ), + function ( err ) { + if ( ( err instanceof Error ) && /value/.test( err ) ) { + return true; + } + } + ); + } ); +} ); -- To view, visit https://gerrit.wikimedia.org/r/393171 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9738d71971753f470933cb42a1efffa86f18e54b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits