Skip to content

Commit

Permalink
Extended question-service test to include Timeout case
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFN2 committed Apr 24, 2024
1 parent e3ef786 commit 997a930
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion questionservice/question-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Question Service', () => {
});

//Test /imgs/answer endpoint (Incorrect answer)
it('should inform the answer is incorrect and what is the correct answer', async () => {
it('should inform the answer is incorrect and what is the correct answer if answering incorrectly', async () => {
//First I ask a question
const response = await request(app).get('/imgs/foods/question');
regex = new RegExp(`Which of the following images corresponds to (\\w+)\\?`);
Expand All @@ -137,6 +137,23 @@ describe('Question Service', () => {
expect(responseAnswer.body.correct).toBe("false")
expect(responseAnswer.body.correctImg).toBe([...imgsToAssociatesMap].find(([key, val]) => val == correctAnswerLabel)[0])
});

//Test /imgs/answer endpoint (Timeout)
it('should inform the answer is incorrect and what is the correct answer if a timeout happens', async () => {
//First I ask a question
const response = await request(app).get('/imgs/foods/question');
regex = new RegExp(`Which of the following images corresponds to (\\w+)\\?`);
const match = response.body.question.match(regex);
const correctAnswerLabel = match && match[1];

question = response.body.question
const responseAnswer = await request(app)
.post("/imgs/answer")
.set('Content-Type', 'application/json')
.send({answer:"TimeOut1234;", question:question, username:"username", category:"foods"})
expect(responseAnswer.body.correct).toBe("false")
expect(responseAnswer.body.correctImg).toBe([...imgsToAssociatesMap].find(([key, val]) => val == correctAnswerLabel)[0])
});
});

function getItemLabelsIfDifferent(images) {
Expand Down

0 comments on commit 997a930

Please sign in to comment.