diff --git a/backend/src/tests/messageRoute.test.ts b/backend/src/tests/messageRoute.test.ts index 417ed9d..b994126 100644 --- a/backend/src/tests/messageRoute.test.ts +++ b/backend/src/tests/messageRoute.test.ts @@ -1,20 +1,20 @@ -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); @@ -22,15 +22,15 @@ describe('GET /messages', () => { }); }); -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(); }); -}); \ No newline at end of file +}); diff --git a/backend/src/tests/roomRoutes.test.ts b/backend/src/tests/roomRoutes.test.ts index cdb10ca..b9da223 100644 --- a/backend/src/tests/roomRoutes.test.ts +++ b/backend/src/tests/roomRoutes.test.ts @@ -1,20 +1,20 @@ -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); @@ -22,12 +22,12 @@ describe('GET /rooms', () => { }); }); -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); @@ -35,15 +35,15 @@ describe('GET /rooms/all', () => { }); }); -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(); }); -}); \ No newline at end of file +});