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

chore: Integrate GitHub Actions #27

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
18 changes: 18 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2.1

jobs:
build_and_test:
docker:
- image: cimg/node:16.4.1
steps:
- checkout
- setup_remote_docker:
version: 19.03.13
- run: cp .env.example .env
- run: yarn docker:ci
- run: docker-compose down

workflows:
build_and_test:
jobs:
- build_and_test
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: develop

on:
push:
branches: [develop]
pull_request:
branches: [develop]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.15.4]

steps:
- uses: actions/checkout@v2
- name: Create .env
run: cp .env.example .env
- name: Docker Compose & Test
run: yarn docker:ci
env:
JWT_TOKEN_KEY: ${{ secrets.JWT_TOKEN_KEY }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
node_modules
node_modules
dist
22 changes: 22 additions & 0 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:14-alpine

ENV APP_HOME="/home/app/mcitmocks"

RUN mkdir -p ${APP_HOME} && chown -R node:node ${APP_HOME}

WORKDIR ${APP_HOME}

COPY package*.json ./
RUN yarn

COPY . .

EXPOSE 8000

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait /wait
RUN chmod +x /wait

ADD start.ci.sh /start.ci.sh
RUN chmod +x /start.ci.sh

CMD /wait && /start.ci.sh
2 changes: 1 addition & 1 deletion Dockerfile → Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ RUN yarn db:generate
RUN if [ "$ENV" = "production" ] ; then cd client && yarn build; fi

RUN chmod +x entrypoint.sh
ENTRYPOINT [ "sh", "entrypoint.sh" ]
ENTRYPOINT [ "sh", "entrypoint.dev.sh" ]

CMD if [ "$ENV" = "production" ] ; then yarn start; else yarn dev; fi
18 changes: 14 additions & 4 deletions controllers/__tests__/authControllerGetUser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import request from "supertest";
import { PrismaClient } from "@prisma/client";

import app from "../../index";
import AuthService from "../../services/AuthService";

describe("GET /api/auth/user", () => {
const prismaClient = new PrismaClient();
const authService = new AuthService(prismaClient);

it("should respond with 401 not authorized if cookie not provided", async () => {
const res = await request(app).get("/api/auth/user");
const res = await request("localhost:8000").get("/api/auth/user");
expect(res.statusCode).toEqual(401);
expect(res.body).toEqual({ error: "Not Authenticated." });
});

it("should return user if a valid cookie is provided", async () => {
const user = await prismaClient.user.findUnique({ where: { id: "1" } });
const token = authService.generateJWT(user!);
const res = await request(app).get("/api/auth/user").set("cookie", `mcitmocks=${token}`);
const res = await request("localhost:8000").get("/api/auth/user").set("cookie", `mcitmocks=${token}`);
expect(res.statusCode).toEqual(200);
expect(res.body).toEqual({ user: { email: "[email protected]", id: "1", timeZone: "America/Chicago" } });
expect(res.body).toEqual({
user: {
id: "1",
name: "Alice",
email: "[email protected]",
timeZone: "America/Chicago",
codingLanguage: [],
imageUrl: null,
questionDifficulty: "EASY",
questionTypes: [],
},
});
});
});
29 changes: 29 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"

services:
database:
image: postgres
container_name: database
restart: always
ports:
- 5432
environment:
POSTGRES_DB: mcitmocks_dev
POSTGRES_USER: mcitmocks
POSTGRES_PASSWORD: password

server:
build:
context: .
dockerfile: Dockerfile.ci
container_name: server
environment:
- JWT_TOKEN_KEY
- GOOGLE_CLIENT_ID
ports:
- 8000:8000
depends_on:
- database
environment:
DATABASE_URL: postgresql://mcitmocks:password@database:5432/mcitmocks_dev
WAIT_HOSTS: database:5432
4 changes: 3 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ services:
POSTGRES_PASSWORD: password

server:
build: .
build:
context: .
dockerfile: Dockerfile.dev
container_name: server
ports:
- 8000:8000
Expand Down
File renamed without changes.
Loading