mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
modified insert room test
This commit is contained in:
parent
c54d4fd2a3
commit
0b4bd8a04a
1 changed files with 22 additions and 6 deletions
|
|
@ -50,9 +50,20 @@ describe('Rooms', () => {
|
|||
const roomID = '123456';
|
||||
const roomName = 'room123456';
|
||||
const hostname = 'localhost';
|
||||
const mongoObjectID = new ObjectId();
|
||||
|
||||
collection.findOne.mockResolvedValue(null);
|
||||
collection.insertOne.mockResolvedValue({ insertedId: new ObjectId() });
|
||||
// Mock first findOne to simulate no entry
|
||||
collection.findOne.mockResolvedValueOnce(null);
|
||||
|
||||
//Mock second findOne to simulate new room
|
||||
collection.findOne.mockResolvedValueOnce({
|
||||
_id: mongoObjectID,
|
||||
id: roomID,
|
||||
name: roomName,
|
||||
host: hostname,
|
||||
});
|
||||
|
||||
collection.insertOne.mockResolvedValue({ insertedId: mongoObjectID });
|
||||
|
||||
const room = new Room(roomID, roomName, hostname);
|
||||
|
||||
|
|
@ -60,16 +71,21 @@ describe('Rooms', () => {
|
|||
|
||||
expect(db.connect).toHaveBeenCalled();
|
||||
expect(db.getConnection).toHaveBeenCalled();
|
||||
expect(collection.findOne).toHaveBeenCalled();
|
||||
expect(result).toBeDefined();
|
||||
expect(collection.findOne).toHaveBeenCalledWith({id: '123456'});
|
||||
});
|
||||
|
||||
it('should throw an error if a room with same ID exists', async () => {
|
||||
const roomID = '123456';
|
||||
const roomName = 'room123456';
|
||||
const roomName = 'otherRoom';
|
||||
const hostname = 'localhost';
|
||||
const mongoObjectID = new ObjectId();
|
||||
|
||||
collection.findOne.mockResolvedValue({ id: roomID });
|
||||
collection.findOne.mockResolvedValueOnce({
|
||||
_id: mongoObjectID,
|
||||
id: roomID,
|
||||
name: roomName,
|
||||
host: hostname,
|
||||
});
|
||||
|
||||
const room = new Room(roomID, roomName, hostname);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue