Quinto y último proyecto finalizado y aprobado el cual es requisito obligatorio para obtener la Quality Assurance Certification de freecodecamp.
El proyecto consiste en realizar un traductor de inglés americano a inglés británico y viceversa. El traductor NO traduce cualquier palabra y/o frase sino un dominio acotado a 2131 palabras y frases las cuales se encuentran en los archivos ubicados en la carpeta components llamados:
-
american-only.js (183 palabras y frases)
-
american-to-british-spelling.js (1699 palabras)
-
american-to-british-titles.js (6 palabras)
-
british-only.js (243 palabras y frases)
El texto a traducir y el idioma se envían desde el cliente al servidor en el cuerpo de una petición POST en formato de objeto siendo el valor de la key text igual al texto que se desea traducir y el valor de la key locale igual a british-to-american o american-to-british. El servidor responde con diversos mensajes según corresponda:
-
Cuando el texto ingresado posee traducción, dicha traducción se muestra en el área marcada para ello. El servidor responde con un objeto siendo el valor de la key text igual al texto a traducir enviado y el valor de la key translation igual al texto traducido.
-
Si el texto esta en un idioma y se intenta traducir al mismo idioma entonces se envía lo siguiente:
Everything looks good to me!
-
Si el texto que se desea traducir esta en blanco, entonces se envía el siguiente error:
{ error: 'No text to translate' }
-
Si se pretende traducir a un idioma distinto del inglés americano o inglés británico pasando un argumento diferente de british-to-american o american-to-british, entonces se envía el siguiente error:
{ error: 'Invalid value for locale field' }.
-
Si en la petición al servidor no estan presentes las keys text o locale, entonces se envía el siguiente error:
{ error: 'Required field(s) missing' }.
- American British Translator
- Tabla de Contenidos
- Deploy
- Requisitos Aprobados
- Tests unitarios y funcionales requeridos
- Proyecto Aprobado
- Tests Requeridos Aprobados
- Código de tests unitarios y funcionales
- 1. Tests Unitarios
- 1. Translate Mangoes are my favorite fruit. to British English
- 2.Translate I ate yogurt for breakfast. to British English
- 3.Translate We had a party at my friend's condo. to British English
- 4.Translate Can you toss this in the trashcan for me? to British English
- 5.Translate The parking lot was full. to British English
- 6.Translate Like a high tech Rube Goldberg machine. to British English
- 7.Translate To play hooky means to skip class or work. to British English
- 8.Translate No Mr. Bond, I expect you to die. to British English
- 9.Translate Dr. Grosh will see you now. to British English
- 10.Translate Lunch is at 12:15 today. to British English
- 11.Translate We watched the footie match for a while. to American English
- 12.Translate Paracetamol takes up to an hour to work. to American English
- 13.Translate First, caramelise the onions. to American English
- 14.Translate I spent the bank holiday at the funfair. to American English
- 15.Translate I had a bicky then went to the chippy. to American English
- 16.Translate I've just got bits and bobs in my bum bag. to American English
- 17.Translate The car boot sale at Boxted Airfield was called off. to American English
- 18.Translate Have you met Mrs Kalyani? to American English
- 19.Translate Prof Joyner of King's College, London. to American English
- 20.Translate Tea time is usually around 4 or 4.30. to American English
- 21.Highlight translation in Mangoes are my favorite fruit.
- 22.Highlight translation in I ate yogurt for breakfast.
- 23.Highlight translation in We watched the footie match for a while.
- 24.Highlight translation in Paracetamol takes up to an hour to work.
- 2. Tests Funcionales
- 1.Translation with text and locale fields: POST request to /api/translate
- 2.Translation with text and invalid locale field: POST request to /api/translate
- 3.Translation with missing text field: POST request to /api/translate
- 4.Translation with missing locale field: POST request to /api/translate
- 5.Translation with empty text: POST request to /api/translate
- 6.Translation with text that needs no translation: POST request to /api/translate
- 1. Tests Unitarios
- Screenshots
El proyecto ha sido desplegado a la web en mi cuenta gratuita en Render.com. Como es costumbre con Render.com, cuando un servicio web no esta activo, es decir, pasa un tiempo sin uso, dicho servicio es congelado necesitando de al menos 50 segundos o más para volver a visualizar el proyecto.
Se han creado 24 tests unitarios y 6 tests funcionales requeridos:
test("Translate Mangoes are my favorite fruit. to British English", (done) => {
assert.equal(
translator.translate(
"Mangoes are my favorite fruit.",
"american-to-british",
false
),
"Mangoes are my favourite fruit."
);
done();
});
test("Translate I ate yogurt for breakfast. to British English", (done) => {
assert.equal(
translator.translate(
"I ate yogurt for breakfast.",
"american-to-british",
false
),
"I ate yoghurt for breakfast."
);
done();
});
test("Translate We had a party at my friend's condo. to British English", (done) => {
assert.equal(
translator.translate(
"We had a party at my friend's condo.",
"american-to-british",
false
),
"We had a party at my friend's flat."
);
done();
});
test("Translate Can you toss this in the trashcan for me? to British English", (done) => {
assert.equal(
translator.translate(
"Can you toss this in the trashcan for me?",
"american-to-british",
false
),
"Can you toss this in the bin for me?"
);
done();
});
test("Translate The parking lot was full. to British English", (done) => {
assert.equal(
translator.translate(
"The parking lot was full.",
"american-to-british",
false
),
"The car park was full."
);
done();
});
test("Translate Like a high tech Rube Goldberg machine. to British English", (done) => {
assert.equal(
translator.translate(
"Like a high tech Rube Goldberg machine.",
"american-to-british",
false
),
"Like a high tech Heath Robinson device."
);
done();
});
test("Translate To play hooky means to skip class or work. to British English", (done) => {
assert.equal(
translator.translate(
"To play hooky means to skip class or work.",
"american-to-british",
false
),
"To bunk off means to skip class or work."
);
done();
});
test("Translate No Mr. Bond, I expect you to die. to British English", (done) => {
assert.equal(
translator.translate(
"No Mr. Bond, I expect you to die.",
"american-to-british",
false
),
"No Mr Bond, I expect you to die."
);
done();
});
test("Translate Dr. Grosh will see you now. to British English", (done) => {
assert.equal(
translator.translate(
"Dr. Grosh will see you now.",
"american-to-british",
false
),
"Dr Grosh will see you now."
);
done();
});
test("Translate Lunch is at 12:15 today. to British English", (done) => {
assert.equal(
translator.translate(
"Lunch is at 12:15 today.",
"american-to-british",
false
),
"Lunch is at 12.15 today."
);
done();
});
test("Translate We watched the footie match for a while. to American English", (done) => {
assert.equal(
translator.translate(
"We watched the footie match for a while.",
"british-to-american",
false
),
"We watched the soccer match for a while."
);
done();
});
test("Translate Paracetamol takes up to an hour to work. to American English", (done) => {
assert.equal(
translator.translate(
"Paracetamol takes up to an hour to work.",
"british-to-american",
false
),
"Tylenol takes up to an hour to work."
);
done();
});
test("Translate First, caramelise the onions. to American English", (done) => {
assert.equal(
translator.translate(
"First, caramelise the onions.",
"british-to-american",
false
),
"First, caramelize the onions."
);
done();
});
test("Translate I spent the bank holiday at the funfair. to American English", (done) => {
assert.equal(
translator.translate(
"I spent the bank holiday at the funfair.",
"british-to-american",
false
),
"I spent the public holiday at the carnival."
);
done();
});
test("Translate I had a bicky then went to the chippy. to American English", (done) => {
assert.equal(
translator.translate(
"I had a bicky then went to the chippy.",
"british-to-american",
false
),
"I had a cookie then went to the fish-and-chip shop."
);
done();
});
test("Translate I've just got bits and bobs in my bum bag. to American English", (done) => {
assert.equal(
translator.translate(
"I've just got bits and bobs in my bum bag.",
"british-to-american",
false
),
"I've just got odds and ends in my fanny pack."
);
done();
});
test("Translate The car boot sale at Boxted Airfield was called off. to American English", (done) => {
assert.equal(
translator.translate(
"The car boot sale at Boxted Airfield was called off.",
"british-to-american",
false
),
"The swap meet at Boxted Airfield was called off."
);
done();
});
test("Translate Have you met Mrs Kalyani? to American English", (done) => {
assert.equal(
translator.translate(
"Have you met Mrs Kalyani?",
"british-to-american",
false
),
"Have you met Mrs. Kalyani?"
);
done();
});
test("Translate Prof Joyner of King's College, London. to American English", (done) => {
assert.equal(
translator.translate(
"Prof Joyner of King's College, London.",
"british-to-american",
false
),
"Prof. Joyner of King's College, London."
);
done();
});
test("Translate Tea time is usually around 4 or 4.30. to American English", (done) => {
assert.equal(
translator.translate(
"Tea time is usually around 4 or 4.30.",
"british-to-american",
false
),
"Tea time is usually around 4 or 4:30."
);
done();
});
test("Highlight translation in Mangoes are my favorite fruit.", (done) => {
assert.equal(
translator.translate(
"Mangoes are my favorite fruit.",
"american-to-british",
true
),
'Mangoes are my <span class="highlight">favourite</span> fruit.'
);
done();
});
test("Highlight translation in I ate yogurt for breakfast.", (done) => {
assert.equal(
translator.translate(
"I ate yogurt for breakfast.",
"american-to-british",
true
),
'I ate <span class="highlight">yoghurt</span> for breakfast.'
);
done();
});
test("Highlight translation in We watched the footie match for a while.", (done) => {
assert.equal(
translator.translate(
"We watched the footie match for a while.",
"british-to-american",
true
),
'We watched the <span class="highlight">soccer</span> match for a while.'
);
done();
});
test("Highlight translation in Paracetamol takes up to an hour to work.", (done) => {
assert.equal(
translator.translate(
"Paracetamol takes up to an hour to work.",
"british-to-american",
true
),
'<span class="highlight">Tylenol</span> takes up to an hour to work.'
);
done();
});
test("Translation with text and locale fields: POST request to /api/translate", (done) => {
chai
.request(server)
.keepOpen()
.post("/api/translate")
.send({
text: "Mangoes are my favorite fruit.",
locale: "american-to-british",
})
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.body.text, "Mangoes are my favorite fruit.");
assert.equal(
res.body.translation,
'Mangoes are my <span class="highlight">favourite</span> fruit.'
);
done();
});
});
test("Translation with text and invalid locale field: POST request to /api/translate", (done) => {
chai
.request(server)
.keepOpen()
.post("/api/translate")
.send({
text: "Mangoes are my favorite fruit.",
locale: "american-to-spanish",
})
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.body.error, "Invalid value for locale field");
done();
});
});
test("Translation with missing text field: POST request to /api/translate", (done) => {
chai
.request(server)
.keepOpen()
.post("/api/translate")
.send({
locale: "american-to-british",
})
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.body.error, "Required field(s) missing");
done();
});
});
test("Translation with missing locale field: POST request to /api/translate", (done) => {
chai
.request(server)
.keepOpen()
.post("/api/translate")
.send({
text: "Mangoes are my favorite fruit.",
})
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.body.error, "Required field(s) missing");
done();
});
});
test("Translation with empty text: POST request to /api/translate", (done) => {
chai
.request(server)
.keepOpen()
.post("/api/translate")
.send({
text: "",
locale: "american-to-british",
})
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.body.error, "No text to translate");
done();
});
});
test("Translation with text that needs no translation: POST request to /api/translate", (done) => {
chai
.request(server)
.keepOpen()
.post("/api/translate")
.send({
text: "Mangoes are my favorite fruit.",
locale: "british-to-american",
})
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.body.text, "Mangoes are my favorite fruit.");
assert.equal(res.body.translation, "Everything looks good to me!");
done();
});
});