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 'Develop' into FeatureQuestions
- Loading branch information
Showing
4 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const request = require('supertest'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
const mongoose = require('mongoose'); | ||
const app = require('./question-service'); | ||
|
||
let mongoServer; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_QUESTIONS_URI = mongoUri; | ||
mongoose.connect(mongoUri); | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoose.disconnect(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Question Service', () => { | ||
it('should add a new question on POST /addquestion', async () => { | ||
const newQuestion = { | ||
question: 'What is the capital of France?', | ||
options: ['Paris', 'Berlin', 'Madrid', 'Rome'], | ||
correctOptionIndex: 0, | ||
}; | ||
|
||
const response = await request(app).post('/addquestion').send(newQuestion); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('question', 'What is the capital of France?'); | ||
}); | ||
|
||
}); |
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