From e771f50c499f9a978c61c683dd4588d7d6c36591 Mon Sep 17 00:00:00 2001 From: Asam Date: Thu, 16 Jan 2025 12:52:00 +0100 Subject: [PATCH] feat: run test users --- .github/workflows/test.yml | 32 ++++++++++++++++++++++++++++++++ index.ts | 2 +- jest.config.js | 7 +++++++ src/__tests__/user.test.ts | 31 +++++++++++++++++++++++++++++++ src/http/user.http | 4 ++-- 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 jest.config.js create mode 100644 src/__tests__/user.test.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..65dcc55 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: Run Jest Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout code + uses: actions/checkout@v3 + + # Setup Node.js environment + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "18" # Use the Node.js version your project supports + + # Install dependencies + - name: Install dependencies + run: npm install + + # Run tests + - name: Run Jest tests + run: npm test diff --git a/index.ts b/index.ts index 1701174..d93e21b 100644 --- a/index.ts +++ b/index.ts @@ -3,7 +3,7 @@ import { PORT } from "./src/startup/config"; import { connectToDatabase } from "./src/startup/database"; import { setupRestEndPoint } from "./src/server"; -const app = express(); +export const app = express(); connectToDatabase(); setupRestEndPoint(app); diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..14d0a8c --- /dev/null +++ b/jest.config.js @@ -0,0 +1,7 @@ +module.exports = { + preset: "ts-jest", + testEnvironment: "node", + testMatch: ["**/**/*.test.ts"], + verbose: true, + forceExit: true, +}; diff --git a/src/__tests__/user.test.ts b/src/__tests__/user.test.ts new file mode 100644 index 0000000..ded786a --- /dev/null +++ b/src/__tests__/user.test.ts @@ -0,0 +1,31 @@ +import supertest from "supertest"; +import { connectToDatabase } from "../startup/database"; +import { pool } from "../utils/db"; +import { app } from "../.."; + +describe("user", () => { + beforeAll(async () => { + await connectToDatabase(); + }); + afterAll(async () => { + await pool.end(); + }); + it("login user", async () => { + const email = "abbasaliaboubakar@gmail.com"; + const password = "password123"; + const resp = await supertest(app).post("/users/login").send({ + email, + password, + }); + expect(resp.statusCode).toBe(200); + }); + it("get all users", async () => { + const resp = await supertest(app).get("/users/"); + expect(resp.statusCode).toBe(200); + }); + it("get one user", async () => { + const userId = "0194697b-b580-77cb-b047-62a56594af1c"; + const resp = await supertest(app).get(`/users/${userId}`); + expect(resp.statusCode).toBe(200); + }); +}); diff --git a/src/http/user.http b/src/http/user.http index 3543f18..0adf941 100644 --- a/src/http/user.http +++ b/src/http/user.http @@ -32,11 +32,11 @@ Content-Type: application/json ### ### Verify a user -POST http://localhost:3010/users/verify/01946483-6860-77fd-b53c-6894533b709b +POST http://localhost:3010/users/verify/0194697b-b580-77cb-b047-62a56594af1c Content-Type: application/json { - "code": 2334 + "code": 6371 } ###