Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testMatch: ["**/**/*.test.ts"],
verbose: true,
forceExit: true,
};
31 changes: 31 additions & 0 deletions src/__tests__/user.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
4 changes: 2 additions & 2 deletions src/http/user.http
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

###
Expand Down