-
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
etienne
committed
Feb 18, 2024
1 parent
7b2bef5
commit 4db2eef
Showing
2 changed files
with
41 additions
and
41 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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import request from 'supertest'; | ||
import express from 'express'; | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { router as messageRoutes } from '../routes/messageRoutes'; | ||
import { Message } from '../models/messages'; | ||
import request from "supertest"; | ||
import express from "express"; | ||
import { expect } from "chai"; | ||
import sinon from "sinon"; | ||
import { router as messageRoutes } from "../routes/messageRoutes.js"; | ||
import { Message } from "../models/messages.js"; | ||
|
||
const app = express(); | ||
app.use(express.json()); | ||
app.use('/messages', messageRoutes); | ||
app.use("/messages", messageRoutes); | ||
|
||
describe('GET /messages', () => { | ||
it('should fetch all messages', async () => { | ||
const mockMessages = [{ _id: '1', text: 'Test message', roomId: '1' }]; | ||
sinon.stub(Message, 'find').resolves(mockMessages); | ||
describe("GET /messages", () => { | ||
it("should fetch all messages", async () => { | ||
const mockMessages = [{ _id: "1", text: "Test message", roomId: "1" }]; | ||
sinon.stub(Message, "find").resolves(mockMessages); | ||
|
||
const res = await request(app).get('/messages'); | ||
const res = await request(app).get("/messages"); | ||
expect(res.status).to.equal(200); | ||
expect(res.body).to.deep.equal(mockMessages); | ||
|
||
sinon.restore(); | ||
}); | ||
}); | ||
|
||
describe('GET /messages/:roomId', () => { | ||
it('should fetch all messages for a specific room', async () => { | ||
const mockMessages = [{ _id: '1', text: 'Test message', roomId: '1' }]; | ||
sinon.stub(Message, 'find').resolves(mockMessages); | ||
describe("GET /messages/:roomId", () => { | ||
it("should fetch all messages for a specific room", async () => { | ||
const mockMessages = [{ _id: "1", text: "Test message", roomId: "1" }]; | ||
sinon.stub(Message, "find").resolves(mockMessages); | ||
|
||
const res = await request(app).get('/messages/1'); | ||
const res = await request(app).get("/messages/1"); | ||
expect(res.status).to.equal(200); | ||
expect(res.body).to.deep.equal(mockMessages); | ||
|
||
sinon.restore(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import request from 'supertest'; | ||
import express from 'express'; | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { router as roomRoutes } from '../routes/roomRoutes'; | ||
import { Room } from '../models/room'; | ||
import request from "supertest"; | ||
import express from "express"; | ||
import { expect } from "chai"; | ||
import sinon from "sinon"; | ||
import { router as roomRoutes } from "../routes/roomRoutes.js"; | ||
import { Room } from "../models/room.js"; | ||
|
||
const app = express(); | ||
app.use(express.json()); | ||
app.use('/rooms', roomRoutes); | ||
app.use("/rooms", roomRoutes); | ||
|
||
describe('GET /rooms', () => { | ||
it('should fetch all rooms', async () => { | ||
const mockRooms = [{ title: 'Global Chatroom', id: '1' }]; | ||
sinon.stub(Room, 'find').resolves(mockRooms); | ||
describe("GET /rooms", () => { | ||
it("should fetch all rooms", async () => { | ||
const mockRooms = [{ title: "Global Chatroom", id: "1" }]; | ||
sinon.stub(Room, "find").resolves(mockRooms); | ||
|
||
const res = await request(app).get('/rooms'); | ||
const res = await request(app).get("/rooms"); | ||
expect(res.status).to.equal(200); | ||
expect(res.body).to.deep.equal(mockRooms); | ||
|
||
sinon.restore(); | ||
}); | ||
}); | ||
|
||
describe('GET /rooms/all', () => { | ||
it('should fetch all rooms from the database', async () => { | ||
const mockRooms = [{ title: 'Global Chatroom', id: '1' }]; | ||
sinon.stub(Room, 'find').resolves(mockRooms); | ||
describe("GET /rooms/all", () => { | ||
it("should fetch all rooms from the database", async () => { | ||
const mockRooms = [{ title: "Global Chatroom", id: "1" }]; | ||
sinon.stub(Room, "find").resolves(mockRooms); | ||
|
||
const res = await request(app).get('/rooms/all'); | ||
const res = await request(app).get("/rooms/all"); | ||
expect(res.status).to.equal(200); | ||
expect(res.body).to.deep.equal(mockRooms); | ||
|
||
sinon.restore(); | ||
}); | ||
}); | ||
|
||
describe('GET /rooms/:roomId', () => { | ||
it('should fetch a specific room by id', async () => { | ||
const mockRoom = { title: 'Global Chatroom', id: '1' }; | ||
sinon.stub(Room, 'find').resolves([mockRoom]); | ||
describe("GET /rooms/:roomId", () => { | ||
it("should fetch a specific room by id", async () => { | ||
const mockRoom = { title: "Global Chatroom", id: "1" }; | ||
sinon.stub(Room, "find").resolves([mockRoom]); | ||
|
||
const res = await request(app).get('/rooms/1'); | ||
const res = await request(app).get("/rooms/1"); | ||
expect(res.status).to.equal(200); | ||
expect(res.body).to.deep.equal(mockRoom); | ||
|
||
sinon.restore(); | ||
}); | ||
}); | ||
}); |