forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Arquisoft/laura
Laura
- Loading branch information
Showing
3 changed files
with
76 additions
and
50 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
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 bcrypt = require('bcrypt'); | ||
const Answer = require('./answer-model'); | ||
|
||
let mongoServer; | ||
let app; | ||
|
||
//test answer | ||
const answerTest = { | ||
|
||
answerBody: "Cervantes", | ||
typeAnswer: "autor" | ||
}; | ||
|
||
async function addanswer(answerTest){ | ||
const newAnswer = new Answer({ | ||
answerBody: answerTest.answerBody, | ||
typeAnswer: answerTest.typeAnswer | ||
}); | ||
|
||
await newAnswer.save(); | ||
} | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
app = require('./answer-service'); | ||
//Load database with initial conditions | ||
await addanswer(answerTest); | ||
}); | ||
|
||
afterAll(async () => { | ||
app.close(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Answer Service', () => { | ||
it('Should perform an addRecord operation /addAnswer', async () => { | ||
const response = await request(app).post('/addAnswer').send(answerTest); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('answerBody', 'Cervantes'); | ||
expect(response.body).toHaveProperty('typeAnswer', 'autor'); | ||
}); | ||
|
||
}); |
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