diff --git a/.github/workflows/api.yaml b/.github/workflows/api.yaml index b6af79e..654aed7 100644 --- a/.github/workflows/api.yaml +++ b/.github/workflows/api.yaml @@ -22,11 +22,11 @@ jobs: - name: Install dependencies working-directory: ./api - run: npm install + run: yarn install - name: Check formatting working-directory: ./api - run: npm run format:check + run: yarn format:check lint: runs-on: ubuntu-latest @@ -47,8 +47,33 @@ jobs: - name: Install dependencies working-directory: ./api - run: npm install + run: yarn install - name: Run linter working-directory: ./api - run: npm run lint + run: yarn lint + + test: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Set up Node + uses: actions/setup-node@v1 + with: + node-version: 12 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: api/node_modules + key: ${{ runner.os }}-cache + + - name: Install dependencies + working-directory: ./api + run: yarn install + + - name: Run tests + working-directory: ./api + run: yarn test diff --git a/.github/workflows/client.yaml b/.github/workflows/client.yaml index d13db80..994d021 100644 --- a/.github/workflows/client.yaml +++ b/.github/workflows/client.yaml @@ -22,11 +22,11 @@ jobs: - name: Install dependencies working-directory: ./client - run: npm install + run: yarn install - name: Check formatting working-directory: ./client - run: npm run format:check + run: yarn format:check lint: runs-on: ubuntu-latest @@ -47,11 +47,11 @@ jobs: - name: Install dependencies working-directory: ./client - run: npm install + run: yarn install - name: Run linter working-directory: ./client - run: npm run lint + run: yarn lint build: runs-on: ubuntu-latest @@ -72,8 +72,8 @@ jobs: - name: Install dependencies working-directory: ./client - run: npm install + run: yarn install - name: Build application working-directory: ./client - run: npm run build + run: yarn build diff --git a/api/.eslintrc.json b/api/.eslintrc.json index bd77fc7..291f4e0 100644 --- a/api/.eslintrc.json +++ b/api/.eslintrc.json @@ -1,4 +1,7 @@ { "plugins": ["@h4iuiuc"], - "extends": ["plugin:@h4iuiuc/recommended"] + "extends": ["plugin:@h4iuiuc/recommended"], + "env": { + "jest": true + } } diff --git a/api/package.json b/api/package.json index 9660320..3ac81fb 100644 --- a/api/package.json +++ b/api/package.json @@ -7,6 +7,7 @@ "format:check": "prettier --check \"./**/*.{js,jsx,json,md}\"", "lint": "eslint \"./**/*.js\"", "lint:fix": "eslint --fix \"./**/*.js\"", + "test": "cross-env NODE_ENV=test jest --testTimeout=10000", "start": "nodemon ./src/bin/www" }, "dependencies": { @@ -15,12 +16,22 @@ "debug": "~2.6.9", "express": "~4.16.1", "http-errors": "~1.6.3", + "http-status-codes": "^2.1.4", "morgan": "~1.9.1", "nodemon": "^2.0.4" }, "devDependencies": { "@h4iuiuc/eslint-plugin": "^1.0.12", + "cross-env": "^7.0.2", "eslint": "^6.8.0", - "prettier": "^2.0.5" + "jest": "^26.4.2", + "prettier": "^2.0.5", + "supertest": "^5.0.0" + }, + "jest": { + "testEnvironment": "node", + "coveragePathIgnorePatterns": [ + "/node_modules/" + ] } } diff --git a/api/src/app.js b/api/src/app.js index 4d918c4..b3475e1 100644 --- a/api/src/app.js +++ b/api/src/app.js @@ -17,7 +17,7 @@ app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, "public"))); -app.use("/", indexRouter); +app.use("/api", indexRouter); // catch 404 and forward to error handler app.use(function (req, res, next) { diff --git a/api/src/routes/index.js b/api/src/routes/index.js index 21a402c..323961a 100644 --- a/api/src/routes/index.js +++ b/api/src/routes/index.js @@ -1,9 +1,10 @@ -var express = require("express"); -var router = express.Router(); +const express = require("express"); +const router = express.Router(); +const statusCodes = require("http-status-codes"); /* GET home page. */ router.get("/", function (req, res) { - res.send("Closegap!"); + res.status(statusCodes.OK).send("Closegap!"); }); module.exports = router; diff --git a/api/tests/routes.test.js b/api/tests/routes.test.js new file mode 100644 index 0000000..edc2ab0 --- /dev/null +++ b/api/tests/routes.test.js @@ -0,0 +1,11 @@ +const request = require("supertest"); +const app = require("../src/app"); +const statusCodes = require("http-status-codes"); + +describe("Get Endpoints", () => { + it("should get our project name", async () => { + const res = await request(app).get("/api"); + expect(res.statusCode).toEqual(statusCodes.OK); + expect(res.text).toEqual("Closegap!"); + }); +});