forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_es6c
- Loading branch information
Showing
4 changed files
with
7,901 additions
and
1,634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const request = require('supertest'); | ||
const axios = require('axios'); | ||
const app = require('./game-service'); | ||
|
||
afterAll(async () => { | ||
app.close(); | ||
}); | ||
|
||
jest.mock('axios'); | ||
|
||
describe('Game Service', () => { | ||
axios.post.mockImplementation((url, data) => { | ||
if (url.endsWith('/storeGame')) { | ||
return Promise.resolve("status ok") | ||
} | ||
}) | ||
axios.get.mockImplementation((url, data) => { | ||
if (url.endsWith('/questions?n_preguntas=1&n_respuestas=4&tema=capital')) { | ||
return Promise.resolve({data: { | ||
pregunta: '¿Cuál es la capital Italia?', | ||
respuesta_correcta: 'Roma', | ||
respuestas_incorrectas: ['Nápoles', 'Florencia', 'Milán'], | ||
}}) | ||
} | ||
}) | ||
|
||
|
||
it('should return a game id', async () => { | ||
const response = await request(app) | ||
.get('/generateGame'); | ||
expect(response.statusCode).toBe(200); | ||
expect(response.body).toHaveLength(24); | ||
}) | ||
|
||
it('should fail', async () => { | ||
const response = await request(app) | ||
.get('/questions?n_preguntas=2&n_respuestas=5&tema=capital&tema=lenguaje') | ||
expect(response.statusCode).toBe(500) | ||
}) | ||
|
||
it('should return a number o questions of a diferent types of topics', async () => { | ||
const response = await request(app) | ||
.get('/questions?n_preguntas=1&n_respuestas=4&tema=capital') | ||
expect(response.statusCode).toBe(200) | ||
expect(response.body.pregunta).toBe('¿Cuál es la capital Italia?') | ||
expect(response.body.respuesta_correcta).toBe('Roma') | ||
expect(response.body.respuestas_incorrectas[0]).toBe("Nápoles") | ||
expect(response.body.respuestas_incorrectas[1]).toBe("Florencia") | ||
expect(response.body.respuestas_incorrectas[2]).toBe("Milán") | ||
|
||
}) | ||
}) | ||
|
||
describe('Test the store game', () => { | ||
axios.post.mockImplementation((url, data) => { | ||
if (url.endsWith('/storeGame')) { | ||
return Promise.resolve(200) | ||
} | ||
}) | ||
|
||
it('should store the data of a game', async () => { | ||
const newGame = { | ||
id: "1", | ||
username: 'testuser', | ||
points: 100, | ||
questions: [{ | ||
title: 'Question 1', | ||
answers: ['Answer 1', 'Answer 2', 'Answer 3', 'Answer 4'], | ||
ansIndex: [1, 2] | ||
}, { | ||
title: 'Question 2', | ||
answers: ['Answer 1', 'Answer 2', 'Answer 3', 'Answer 4'], | ||
ansIndex: [1, 1] | ||
}] | ||
}; | ||
const response = await request(app) | ||
.post('/storeGame') | ||
.send(newGame) | ||
console.log(response) | ||
expect(response.statusCode).toBe(200) | ||
}) | ||
}) |
Oops, something went wrong.