diff --git a/test/dolmetscher.test.js b/test/dolmetscher.test.js index 147888b..c4897e0 100644 --- a/test/dolmetscher.test.js +++ b/test/dolmetscher.test.js @@ -39,8 +39,27 @@ describe('Google translate tests', () => { const res = await google.translateText(' hallo '); expect(res.toLowerCase()).to.equal("hello"); - }); - + }); + }); + describe('translateFile', () => { + it('should translate content of file', async () => { + const res = await google.translateFile(`${__dirname}/example.txt`); + expect(res.toLowerCase()).to.equal("hello how are you"); + }); + it('fails with empty file', async () => { + try { + const res = await google.translateFile(`${__dirname}/empty.txt`); + } catch (err) { + expect(err).to.equal(`translation file error: The input text length must be of type string between ${mymemory.minChars} and ${mymemory.maxChars} characters`); + } + }); + it('fails with non existing file', async () => { + try { + const res = await google.translateFile(`${__dirname}/nonExistFile.txt`); + } catch (err) { + expect(err).to.contain(`translation file error:`); + } + }); }); }); @@ -82,6 +101,25 @@ describe('Mymemory translate tests', () => { const res = await mymemory.translateText(' welt '); expect(res.toLowerCase()).to.equal("world"); }); - }); + describe('translateFile', () => { + it('should translate content of file', async () => { + const res = await mymemory.translateFile(`${__dirname}/example.txt`); + expect(res.toLowerCase()).to.equal("hello, how are you?") + }) + it('fails with empty file', async () => { + try { + const res = await mymemory.translateFile(`${__dirname}/empty.txt`); + } catch (err) { + expect(err).to.equal(`translation file error: The input text length must be of type string between ${mymemory.minChars} and ${mymemory.maxChars} characters`) + } + }) + it('fails with non existing file', async () => { + try { + const res = await mymemory.translateFile(`${__dirname}/nonExistFile.txt`); + } catch (err) { + expect(err).to.contain(`translation file error:`) + } + }) + }) }); \ No newline at end of file diff --git a/test/empty.txt b/test/empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/example.txt b/test/example.txt new file mode 100644 index 0000000..ac40caf --- /dev/null +++ b/test/example.txt @@ -0,0 +1 @@ +Hallo, wie geht es dir \ No newline at end of file