From 5f61bb233ba6b8f48029500c63cd706df481169d Mon Sep 17 00:00:00 2001 From: Pablo Salas Date: Sat, 30 Oct 2021 17:31:06 +0200 Subject: [PATCH 1/3] add some tests to translateFile --- test/dolmetscher.test.js | 44 +++++++++++++++++++++++++++++++++++++--- test/empty.txt | 0 test/example.txt | 1 + 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 test/empty.txt create mode 100644 test/example.txt diff --git a/test/dolmetscher.test.js b/test/dolmetscher.test.js index 147888b..9d2202e 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).to.equal("Hello, you are great, keep it up"); + }); + 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).to.equal("Hello, you are great, keep it up") + }) + 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..8bbf63a --- /dev/null +++ b/test/example.txt @@ -0,0 +1 @@ +Hallo, du bist großartig, mach weiter so \ No newline at end of file From 703876daf81389a4f126ffa3d23d73b4f39bf6d5 Mon Sep 17 00:00:00 2001 From: Pablo Salas Date: Sun, 31 Oct 2021 15:08:22 +0100 Subject: [PATCH 2/3] fix expected result on translateFile test --- test/dolmetscher.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dolmetscher.test.js b/test/dolmetscher.test.js index 9d2202e..69fb13e 100644 --- a/test/dolmetscher.test.js +++ b/test/dolmetscher.test.js @@ -44,7 +44,7 @@ describe('Google translate tests', () => { describe('translateFile', () => { it('should translate content of file', async () => { const res = await google.translateFile(`${__dirname}/example.txt`); - expect(res).to.equal("Hello, you are great, keep it up"); + expect(res).to.equal("Hello you are great keep up the good work"); }); it('fails with empty file', async () => { try { From 5ea384d1f4f6a4f6c6bac70cd897ce6d8a13bdd4 Mon Sep 17 00:00:00 2001 From: Pablo Salas Date: Sun, 31 Oct 2021 16:21:10 +0100 Subject: [PATCH 3/3] change text for translate and fix expected results --- test/dolmetscher.test.js | 4 ++-- test/example.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/dolmetscher.test.js b/test/dolmetscher.test.js index 69fb13e..c4897e0 100644 --- a/test/dolmetscher.test.js +++ b/test/dolmetscher.test.js @@ -44,7 +44,7 @@ describe('Google translate tests', () => { describe('translateFile', () => { it('should translate content of file', async () => { const res = await google.translateFile(`${__dirname}/example.txt`); - expect(res).to.equal("Hello you are great keep up the good work"); + expect(res.toLowerCase()).to.equal("hello how are you"); }); it('fails with empty file', async () => { try { @@ -105,7 +105,7 @@ describe('Mymemory translate tests', () => { describe('translateFile', () => { it('should translate content of file', async () => { const res = await mymemory.translateFile(`${__dirname}/example.txt`); - expect(res).to.equal("Hello, you are great, keep it up") + expect(res.toLowerCase()).to.equal("hello, how are you?") }) it('fails with empty file', async () => { try { diff --git a/test/example.txt b/test/example.txt index 8bbf63a..ac40caf 100644 --- a/test/example.txt +++ b/test/example.txt @@ -1 +1 @@ -Hallo, du bist großartig, mach weiter so \ No newline at end of file +Hallo, wie geht es dir \ No newline at end of file