Skip to content

Commit

Permalink
fixing adding more gateway tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289029 committed Mar 11, 2024
1 parent c7259e2 commit a994f95
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ describe('Gateway Service', () => {
return Promise.resolve({ data: { token: 'mockedToken' } });
} else if (url.endsWith('/adduser')) {
return Promise.resolve({ data: { userId: 'mockedUserId' } });
} else if (url.endsWith('/getQuestion')) {
return Promise.resolve({
data: {
question: "¿Cuál es la capital de España?",
correctAnswerLabel: "Madrid",
answerLabelSet: ["Estocolmo", "Madrid", "Oslo", "Copenhague"]
}
});
} else if(url.endsWith('/saveHistorial')){
return Promise.resolve({ data: { message: 'Historial saved' } });
} else if(url.endsWith('/getHistorial')){
return Promise.resolve({
data: [
{
games: [
{
correctAnswer: "Madrid",
answers: ["Estocolmo", "Madrid", "Oslo", "Copenhague"],
title: "¿Cuál es la capital de España?",
answeredRight: true,
selectedAnswer: "Madrid"
}
]
}
],
});
}
});

Expand All @@ -37,4 +63,37 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});

// Test /getQuestion endpoint
it('should forward get question reques to question service', async () => {
const response = await request(app)
.get('/getQuestion');

expect(response.statusCode).toBe(200);
expect(response.body.question).toBe("¿Cuál es la capital de España?");
expect(response.body.correctAnswerLabel).toBe("Madrid");
});

// Test /getQuestion endpoint
it('should forward save historial request to historial service', async () => {
const response = await request(app)
.get('/saveHistorial')
.send({ question: '¿Cuál es la capital de España?', answersArray: ['Madrid', 'Barcelona', 'Valencia', 'Sevilla'],correctAnswer: 'Madrid', selectedAnswer: 'Madrid', correct: true, username2: 'testuser'});

expect(response.statusCode).toBe(200);
expect(response.body.message).toBe('Historial saved');
});

it('should forward get historial request to historial service', async () => {
const response = await request(app)
.get('/getHistorial')
.send({ username2: 'testuser'});

expect(response.statusCode).toBe(200);
expect(response.body[0].games[0].correctAnswer).toBe('Madrid');
expect(response.body[0].games[0].answers).toEqual(["Estocolmo", "Madrid", "Oslo", "Copenhague"]);
expect(response.body[0].games[0].title).toBe("¿Cuál es la capital de España?");
expect(response.body[0].games[0].answeredRight).toBe(true);
expect(response.body[0].games[0].selectedAnswer).toBe("Madrid");
});
});

0 comments on commit a994f95

Please sign in to comment.