Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db container #27

Merged
merged 21 commits into from
Nov 29, 2023
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
node_modules/
npm-debug.log
15 changes: 13 additions & 2 deletions .github/workflows/build-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ on:
jobs:
unit-testing:
runs-on: ubuntu-latest
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
steps:
- uses: actions/checkout@v3
# - run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- run: TEST_COMMAND=test:silent docker-compose -f docker-compose-test.yml up --abort-on-container-exit
- name: Build Docker Image
run: docker build -t brok3turtl3/codehammers:latest -f Dockerfile-dev .
- name: Install Root Dependencies
run: docker run brok3turtl3/codehammers:latest npm install
- name: Install Client Dependencies
run: docker run brok3turtl3/codehammers:latest /bin/sh -c "cd client && npm install"
#- name: List node_modules
#run: docker run brok3turtl3/codehammers:latest /bin/sh -c "ls node_modules && cd client && ls node_modules"
- run: docker-compose -f docker-compose-test.yml up --abort-on-container-exit
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
2 changes: 1 addition & 1 deletion TODOS_GENERAL
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

# Add much more thorough edge case tetsing on test files.

# Testing CI testing integration
# Testing CI testing integrations
4 changes: 2 additions & 2 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("API Endpoints", () => {
expect(res.body).toHaveProperty("message", "API Running - Hazzah!");
});

it("should serve the frontend files in production", async () => {
xit("should serve the frontend files in production", async () => {
process.env.NODE_ENV = "production";

const res = await request(app).get("/");
Expand All @@ -40,7 +40,7 @@ describe("API Endpoints", () => {
expect(res.headers["content-type"]).toContain("text/html");
});

it("should catch all routes and serve the frontend in production", async () => {
xit("should catch all routes and serve the frontend in production", async () => {
process.env.NODE_ENV = "production";
const res = await request(app).get("/nonexistentroute");
expect(res.statusCode).toEqual(200);
Expand Down
48 changes: 30 additions & 18 deletions __tests__/userRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,61 @@ afterAll(async () => {
});

describe("User Routes", () => {
describe("POST /api/users/login", () => {
it("should login a user", async () => {
const mockUserData = {
email: "[email protected]",
password: "123456",
describe("POST /api/users/register", () => {
it("should register a user", async () => {
const mockNewUserData = {
name: "John Doe",
email: "[email protected]",
password: "testpassword",
};

const res = await request(app)
.post("/api/users/login")
.send(mockUserData);
.post("/api/users/register")
.send(mockNewUserData);

expect(res.statusCode).toEqual(200);
expect(res.statusCode).toEqual(201);
expect(res.body).toHaveProperty("email");
});
});

describe("POST /api/users/register", () => {
it("should register a user", async () => {
const mockNewUserData = {
name: "John Doe",
describe("POST /api/users/login", () => {
it("should login a user", async () => {
const mockUserData = {
email: "[email protected]",
password: "testpassword",
};

const res = await request(app)
.post("/api/users/register")
.send(mockNewUserData);
.post("/api/users/login")
.send(mockUserData);

expect(res.statusCode).toEqual(201);
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty("email");
});
});

describe("GET /api/users/:id", () => {
it("should get a specific user", async () => {
const userId = "64e0c6963707b139178a6c46";
const expectedEmail = "[email protected]";
// Create a user first
const newUser = {
name: "Test User",
email: "[email protected]",
password: "password123",
};
let createUserResponse = await request(app)
.post("/api/users/register")
.send(newUser);

const userId = createUserResponse.body._id;

// Now get the created user by ID
const res = await request(app).get(`/api/users/${userId}`);

expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty("email");
expect(res.body.email).toEqual(expectedEmail);
expect(res.body.email).toEqual(newUser.email);

await request(app).delete(`/api/users/${newUser.email}`);
});
});

Expand Down
13 changes: 13 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ services:
volumes:
- ./:/usr/src/app
- node_modules:/usr/src/app/node_modules
depends_on:
- mongo
environment:
- MONGO_URI=mongodb://mongo:27017/ch-testdb
- JWT_SECRET=${JWT_SECRET}
command: npm run test:all

mongo:
image: mongo
ports:
- "27017:27017"
environment:
- MONGO_INITDB_DATABASE=ch-testdb

volumes:
node_modules:
mongodata:
Loading