diff --git a/.github/workflows/verify-server-integration-tests.yml b/.github/workflows/verify-server-integration-tests.yml index b68ceec..3fab77b 100644 --- a/.github/workflows/verify-server-integration-tests.yml +++ b/.github/workflows/verify-server-integration-tests.yml @@ -11,7 +11,7 @@ defaults: working-directory: ./server env: - DATABASE_URL: postgresql://postgres:password@localhost:5432/f1_fantasy_league_db?schema=public + DATABASE_URL: postgresql://postgres:password@localhost:5433/f1_fantasy_league_db?schema=public jobs: execute: diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..0c509af --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,18 @@ +FROM node:18-alpine + +RUN mkdir -p /usr/src/app + +WORKDIR /usr/src/app + +COPY . . + +RUN npm install + +ARG API_DB_URL +ARG SESSION_KEY +ENV DATABASE_URL=$API_DB_URL +ENV SESSION_KEY=$SESSION_KEY + +EXPOSE 3000 + +CMD ["npm", "run", "run-server"] diff --git a/server/app.ts b/server/app.ts index d368853..dbeaf84 100644 --- a/server/app.ts +++ b/server/app.ts @@ -43,13 +43,7 @@ app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec)); app.use("/auth", authRouter); /* Auth Middleware */ -// app.use(authMiddleware); -app.use((req, res, next) => { - if (req.path.startsWith("/auth")) { - return next(); // Skip authMiddleware for /auth routes - } - authMiddleware(req, res, next); -}); +app.use(authMiddleware); /* Choices */ app.use("/choice", choicesRouter); diff --git a/server/controllers/players.ts b/server/controllers/players.ts index 526f11c..53cccf8 100644 --- a/server/controllers/players.ts +++ b/server/controllers/players.ts @@ -13,7 +13,7 @@ const deletePlayer = async (req: Request, res: Response) => { }); if (player) { const deletedPlayer = await playersModel.deletePlayer(numericId); - res.json({ + res.status(204).json({ message: "Deleted player", player: { id: deletedPlayer.id, diff --git a/server/middleware/auth.ts b/server/middleware/auth.ts index 7437b29..28f326e 100644 --- a/server/middleware/auth.ts +++ b/server/middleware/auth.ts @@ -11,6 +11,10 @@ export async function authMiddleware( return next(); } + if (req.path.startsWith("/auth")) { + return next(); // Skip authMiddleware for /auth routes + } + const authToken = req.headers.authorization?.split(" ")[1]; if (authToken) { diff --git a/server/routers/__tests__/players.test.ts b/server/routers/__tests__/players.test.ts new file mode 100644 index 0000000..65ab2d6 --- /dev/null +++ b/server/routers/__tests__/players.test.ts @@ -0,0 +1,89 @@ +import app from "../../app"; +import request from "supertest"; + +describe("/player", () => { + describe("POST /player", () => { + it("should respond with a 201", async () => { + await request(app) + .post("/player") + .send({ + first_name: "Magic", + last_name: "Johnson", + identifier: "magic@johnson.basketball", + password: "b@sketB@11", + }) + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(201); + }); + + it("should respond with a 201 again", async () => { + await request(app) + .post("/player") + .send({ + first_name: "Larry", + last_name: "Bird", + identifier: "bird@threepointking.basketball", + password: "Thr$$p0IntKing", + }) + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(201); + }); + }); + + describe("DELETE /player/1", () => { + it("should respond with a 204", async () => { + await request(app) + .delete("/player/1") + .set("Accept", "application/json") + .expect(204); + }); + }); + + describe("GET /player", () => { + it("should respond with a 200", async () => { + await request(app) + .get("/player") + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(200); + }); + }); + + describe("GET /player/1", () => { + it("should respond with a 404", async () => { + await request(app) + .get("/player/1") + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(404); + }); + }); + + describe("GET /player/2", () => { + it("should respond with a 200", async () => { + await request(app) + .get("/player/2") + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(200); + }); + }); + + describe("PUT /player/2", () => { + it("should respond with a 200", async () => { + await request(app) + .put("/player/2") + .send({ + first_name: "Bruce", + last_name: "Wayne", + identifier: "bruce@wayneenterprises.com", + password: "Imn0tb@tman", + }) + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(200); + }); + }); +});