generated 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.
stat- and question-services tests added
- Loading branch information
1 parent
1eaa00f
commit a26ae5b
Showing
3 changed files
with
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import request from 'supertest'; | ||
import { MongoMemoryServer } from 'mongodb-memory-server'; | ||
|
||
let mongoServer; | ||
let app; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
app = (await import('./question-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set | ||
}); | ||
|
||
afterAll(async () => { | ||
app.close(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Question Service', () => { | ||
it('should add a new question on POST /addquestion', async () => { | ||
const newQuestion = { | ||
type: 'testType', | ||
name: 'testName', | ||
path: 'testPath', | ||
right: 'testRight', | ||
wrong1: 'testWrong1', | ||
wrong2: 'testWrong2', | ||
wrong3: 'testWrong3', | ||
}; | ||
|
||
const response = await request(app).post('/addstst').send(newQuestion); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('userId', '507f1f77bcf86cd799439011'); | ||
}); | ||
}); |
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,34 @@ | ||
import request from 'supertest'; | ||
import { MongoMemoryServer } from 'mongodb-memory-server'; | ||
|
||
let mongoServer; | ||
let app; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
app = (await import('./stat-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set | ||
}); | ||
|
||
afterAll(async () => { | ||
app.close(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Stat Service', () => { | ||
it('should add a new stat on POST /addstat', async () => { | ||
const newStat = { | ||
userId: '507f1f77bcf86cd799439011', | ||
gameId: 'testGameId', | ||
questionId: 'testQuestionId', | ||
right: false, | ||
time: 10, | ||
points: 0, | ||
}; | ||
|
||
const response = await request(app).post('/addstst').send(newStat); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('userId', '507f1f77bcf86cd799439011'); | ||
}); | ||
}); |