Skip to content

Commit

Permalink
Fix history build (CS3219-AY2425S1#83)
Browse files Browse the repository at this point in the history
* Fix history build

Fix history building in wrong directory

* Fix compose.dev.yml

* Rename history entrypoint

* Make history endpoint gateway-accessible

The current endpoint is not accessible on production

* Fix tests

* Fix test typing

Make use of Project References to ensure tests has relevant types

* Remove root package-lock
  • Loading branch information
samuelim01 authored Nov 7, 2024
1 parent 65f37ff commit 517f526
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 23 deletions.
4 changes: 0 additions & 4 deletions compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ services:
volumes:
- /app/node_modules
- ./services/collaboration:/app

collaboration-db:
ports:
- 27020:27017

collaboration-db:
ports:
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion services/history/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ docker compose down -v

- This endpoint retrieves the history of a user.
- **HTTP Method**: `GET`
- **Endpoint**: http://localhost:8086/api/history
- **Endpoint**: http://localhost:8086/api/history/history
- **Headers**
- `Authorization: Bearer <JWT_ACCESS_TOKEN>` (Required)
- The endpoint requires the user to include a JWT (JSON Web Token) in the HTTP Request Header for authentication and authorization. This token is generated during the authentication process (i.e., login) and contains information about the user's identity. The server verifies this token to ensure that the client is authorized to access the data.
Expand Down
12 changes: 6 additions & 6 deletions services/history/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "history",
"version": "0.0.0",
"main": "index.js",
"main": "server.js",
"scripts": {
"build": "npx tsc",
"start": "npm run build && node ./dist/index.js",
"dev": "nodemon --files ./src/index.ts",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix",
"build": "npx tsc --build src/tsconfig.json",
"start": "npm run build && node ./dist/server.js",
"dev": "nodemon --files ./src/server.ts",
"lint": "npx eslint src tests",
"lint:fix": "npx eslint src tests --fix",
"test": "mocha --require ts-node/register tests/**/*.spec.ts --exit"
},
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion services/history/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ app.use(

// Routes
app.use('/', router);
app.use('/api/history', verifyAccessToken, historyRouter);
app.use('/api/history/history', verifyAccessToken, historyRouter);

export default app;
File renamed without changes.
14 changes: 14 additions & 0 deletions services/history/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Visit https://aka.ms/tsconfig to read more about this file */
{
"compilerOptions": {
"target": "es2016",
"module": "CommonJS",
"outDir": "../dist",
"composite": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
},
"include": ["**/*.ts"]
}
6 changes: 3 additions & 3 deletions services/history/tests/controllers/historyController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('History Controller', function () {

it('Should return history with token', done => {
chai.request(app)
.get(`/api/history`)
.get(`/api/history/history`)
.set('Authorization', `Bearer ${user1Token}`)
.end((err, res) => {
expect(res).to.have.status(200);
Expand All @@ -45,7 +45,7 @@ describe('History Controller', function () {

it('Should return empty history for different token', done => {
chai.request(app)
.get(`/api/history`)
.get(`/api/history/history`)
.set('Authorization', `Bearer ${user3Token}`)
.end((err, res) => {
expect(res).to.have.status(200);
Expand All @@ -57,7 +57,7 @@ describe('History Controller', function () {

it('Should return 401 without accessToken', done => {
chai.request(app)
.get(`/api/history`)
.get(`/api/history/history`)
.end((err, res) => {
expect(res).to.have.status(401);
expect(res.body).to.have.property('message');
Expand Down
15 changes: 15 additions & 0 deletions services/history/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2016",
"module": "CommonJS",
"composite": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
},
"references": [
{ "path": "../src" }
],
"include": ["**/*.ts"]
}
7 changes: 5 additions & 2 deletions services/history/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
"compilerOptions": {
"target": "es2016",
"module": "CommonJS",
"rootDir": "./src",
"outDir": "./dist",
"types": ["mocha"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
},
"include": ["src/**/*.ts", "tests/**/*.ts"],
"references": [
{ "path": "./src" },
{ "path": "./tests" }
],
"exclude": ["node_modules"],
"ts-node": {
"files": true
Expand Down

0 comments on commit 517f526

Please sign in to comment.