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.
- Loading branch information
Showing
6 changed files
with
66 additions
and
45 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,40 @@ | ||
const request = require('supertest'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
|
||
let mongoServer; | ||
let app; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
app = require('./gameservice'); | ||
}); | ||
|
||
afterAll(async () => { | ||
app.close(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Game service', () => { | ||
|
||
// mock data | ||
const questions = [{ _id: 'question1_id' }, { _id: 'question2_id' }]; | ||
const users = [{ _id: 'user1_id' }, { _id: 'user2_id' }]; | ||
|
||
it('should create a game and update user lastGame field', async () => { | ||
const response = await request(app).post('/creategame').send({questions,users}); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('_id'); | ||
|
||
const gameId = response.body._id; | ||
const gameFromDB = await mongoose.model('Game').findById(gameId); | ||
const user1FromDB = await mongoose.model('User').findById('user1_id'); | ||
const user2FromDB = await mongoose.model('User').findById('user2_id'); | ||
|
||
// Assertions for the database state | ||
expect(gameFromDB).toBeTruthy(); | ||
expect(user1FromDB.lastGame.toString()).toBe(gameId); | ||
expect(user2FromDB.lastGame.toString()).toBe(gameId); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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