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.
Test QuestionService y modificación git actions
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 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
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,47 @@ | ||
const request = require('supertest'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
|
||
const Template = require('./template-model'); | ||
|
||
let app; | ||
let mongoServer; | ||
const template = { | ||
question: "¿Cuál es la capital de ^ ?", | ||
query: "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P36 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }", | ||
|
||
} | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
app = require('./question-service'); | ||
|
||
await addTemplate(template); | ||
}); | ||
|
||
//Function to add template | ||
async function addTemplate(template){ | ||
const newTemplate = new Template({ | ||
question: template.question, | ||
query: template.query, | ||
}); | ||
|
||
await newTemplate.save(); | ||
} | ||
|
||
afterAll(async () => { | ||
app.close(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Question Service', () => { | ||
it('should generate and store a question', async () => { | ||
const response = await request(app).get('/generate-question'); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('question'); | ||
expect(response.body).toHaveProperty('correctAnswer'); | ||
expect(response.body).toHaveProperty('allAnswers'); | ||
expect(response.body.allAnswers).toHaveLength(4); | ||
}); | ||
}); |