import vitest from "vitest"; import app from "../server.js"; import request from "supertest"; const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcm5hbWUiOiJ0ZXN0IiwiaWF0IjoxNzUxNzk2MjM2fQ.XmaVA_NQcpW7fxRtDWOinMyQXPaFixpp3ib_mzo6M6c" const videoId = 14 describe("GET BY ID", async () => { it("Should return 401 if token is missing", async () => { const req = await request(app).get("/api/videos/" + videoId).send() expect(req.status).toBe(401) }) it("Should return 400 if id is not number", async () => { const req = await request(app).get("/api/videos/sacha").send().set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 404 if video does not exist", async () => { const req = await request(app).get("/api/videos/404").send().set("Authorization", `Bearer ${token}`); expect(req.status).toBe(404) }) it("Should return 200 if OK", async () => { const req = await request(app).get("/api/videos/" + videoId).send().set("Authorization", `Bearer ${token}`); expect(req.status).toBe(200) }) }) describe("GET BY CHANNEL", async () => { it("Should return 401 if token is missing", async () => { const req = await request(app).get("/api/videos/channel/2").send() expect(req.status).toBe(401) }) it("Should return 400 if channeld id is not number", async () => { const req = await request(app).get("/api/videos/channel/astria").send().set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 404 if channel does not exist", async () => { const req = await request(app).get("/api/videos/channel/404").send().set("Authorization", `Bearer ${token}`); expect(req.status).toBe(404) }) it("Should return 200 if OK", async () => { const req = await request(app).get("/api/videos/channel/2").send().set("Authorization", `Bearer ${token}`); expect(req.status).toBe(200) }) }) describe("UPDATE VIDEO DATA", async () => { it("Should return 401 if token is missing", async () => { const video = { "title": "video", "description": "video", "visibility": "private", "channel": 2 } const req = await request(app).put(`/api/videos/` + videoId).send(video) expect(req.status).toBe(401) }) it("Should return 400 if id is not number", async () => { const video = { "title": "video", "description": "video", "visibility": "private", "channel": 2 } const req = await request(app).put(`/api/videos/sacha`).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 400 if title is missing", async () => { const video = { "description": "video", "visibility": "private", "channel": 2 } const req = await request(app).put(`/api/videos/` + videoId).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 400 if visibility is missing", async () => { const video = { "title": "video", "description": "video", "channel": 2 } const req = await request(app).put('/api/videos/' + videoId).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 400 if visibility is not string", async () => { const video = { "title": "video", "description": "video", "visibility": 400, "channel": 2 } const req = await request(app).put("/api/videos/" + videoId).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 400 if channel is missing", async () => { const video = { "title": "video", "description": "video", "visibility": "private", } const req = await request(app).put("/api/videos/" + videoId).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 400 if channel is not number", async () => { const video = { "title": "video", "description": "video", "visibility": "private", "channel": "astria" } const req = await request(app).put("/api/videos/" + videoId).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 404 if video does not exist", async () => { const video = { "title": "video", "description": "video", "visibility": "private", "channel": 2 } const req = await request(app).put("/api/videos/404").send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(404); }) it("Should return 404 if channel does not exist", async () => { const video = { "title": "video", "description": "video", "visibility": "private", "channel": 404 } const req = await request(app).put("/api/videos/" + videoId).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(404); }) it("Should return 403 if user not the owner", async () => { const video = { "title": "video", "description": "video", "visibility": "private", "channel": 3 } const req = await request(app).put("/api/videos/" + videoId).send(video).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(403); }) }) describe("UPDATE TAGS", async () => { it("Should return 401 if token is missing", async () => { const tags = { "tags": ["tag1", "tag2"] } const req = await request(app).put(`/api/videos/` + videoId + "/tags").send(tags) expect(req.status).toBe(401) }) it("Should return 400 if id is not number", async () => { const tags = { "tags": ["tag1", "tag2"] } const req = await request(app).put(`/api/videos/sacha/tags`).send(tags).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 400 if tags is not array", async () => { const tags = { "tags": "tag1, tag2" } const req = await request(app).put(`/api/videos/` + videoId + "/tags").send(tags).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(400) }) it("Should return 404 if video does not exist", async () => { const tags = { "tags": ["tag1", "tag2"] } const req = await request(app).put("/api/videos/404/tags").send(tags).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(404); }) it("Should return 403 if user not the owner", async () => { const tags = { "tags": ["tag1", "tag2"], "channel": 3 } const req = await request(app).put("/api/videos/" + videoId + "/tags").send(tags).set("Authorization", `Bearer ${token}`); expect(req.status).toBe(403); }) })