From 831418b49a9b90b542b6c73c6dcc2337cb072221 Mon Sep 17 00:00:00 2001 From: Guan Quan <76832850+guanquann@users.noreply.github.com> Date: Sun, 20 Oct 2024 15:59:45 +0800 Subject: [PATCH 1/7] Fix ci.yml --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 505efd528d..9a9028ae98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,6 @@ jobs: working-directory: frontend run: npm run lint - name: Frontend tests - working-directory: frontend run: docker compose -f docker-compose-test.yml run --rm test-frontend backend-ci: runs-on: ubuntu-latest From 40af7b97a9daf6c6f50de8f5d0c8e6b147003a95 Mon Sep 17 00:00:00 2001 From: Tin Ruiqi Date: Sun, 20 Oct 2024 19:58:41 +0800 Subject: [PATCH 2/7] Fix match bug on account change --- frontend/src/contexts/MatchContext.tsx | 65 ++++++++++++-------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/frontend/src/contexts/MatchContext.tsx b/frontend/src/contexts/MatchContext.tsx index b6af67aec3..2554034159 100644 --- a/frontend/src/contexts/MatchContext.tsx +++ b/frontend/src/contexts/MatchContext.tsx @@ -100,16 +100,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => { } const { user } = auth; - const [matchUser] = useState( - user - ? { - id: user.id, - username: user.username, - profile: user.profilePictureUrl, - } - : null - ); - + const [matchUser, setMatchUser] = useState(null); const [matchCriteria, setMatchCriteria] = useState( null ); @@ -118,6 +109,18 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => { const [matchPending, setMatchPending] = useState(false); const [loading, setLoading] = useState(true); + useEffect(() => { + if (user) { + setMatchUser({ + id: user.id, + username: user.username, + profile: user.profilePictureUrl, + }); + } else { + setMatchUser(null); + } + }, [user]); + useEffect(() => { if ( !matchUser?.id || @@ -233,14 +236,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => { const initMatchRequestListeners = () => { matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => { - setMatchId(matchId); - if (matchUser?.id === user1.id) { - setPartner(user2); - } else { - setPartner(user1); - } - setMatchPending(true); - appNavigate(MatchPaths.MATCHED); + handleMatchFound(matchId, user1, user2); }); matchSocket.on(MatchEvents.MATCH_REQUEST_EXISTS, () => { @@ -254,14 +250,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => { const initMatchingListeners = () => { matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => { - setMatchId(matchId); - if (matchUser?.id === user1.id) { - setPartner(user2); - } else { - setPartner(user1); - } - setMatchPending(true); - appNavigate(MatchPaths.MATCHED); + handleMatchFound(matchId, user1, user2); }); }; @@ -277,14 +266,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => { }); matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => { - setMatchId(matchId); - if (matchUser?.id === user1.id) { - setPartner(user2); - } else { - setPartner(user1); - } - setMatchPending(true); - appNavigate(MatchPaths.MATCHED); + handleMatchFound(matchId, user1, user2); }); matchSocket.on(MatchEvents.MATCH_REQUEST_ERROR, () => { @@ -299,6 +281,21 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => { }); }; + const handleMatchFound = ( + matchId: string, + user1: MatchUser, + user2: MatchUser + ) => { + setMatchId(matchId); + if (matchUser?.id === user1.id) { + setPartner(user2); + } else { + setPartner(user1); + } + setMatchPending(true); + appNavigate(MatchPaths.MATCHED); + }; + const findMatch = ( complexities: string[], categories: string[], From 590065201004d974cd9fe136251dc96871bbf677 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Sun, 20 Oct 2024 20:21:15 +0800 Subject: [PATCH 3/7] Add instructions to run redis --- backend/user-service/.env.sample | 3 ++- backend/user-service/README.md | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/user-service/.env.sample b/backend/user-service/.env.sample index 14bb3016aa..fc13daa4bf 100644 --- a/backend/user-service/.env.sample +++ b/backend/user-service/.env.sample @@ -29,7 +29,8 @@ USER=EMAIL_ADDRESS PASS=PASSWORD # Redis configuration -REDIS_URI=REDIS_URI +REDIS_URI=redis://redis:6379 # Uncomment if you're running the user service with docker +# REDIS_URI=redis://localhost:6379 # Uncomment if you're running the user service individually without docker # Test MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/ diff --git a/backend/user-service/README.md b/backend/user-service/README.md index 0a1cbdb384..6618903821 100644 --- a/backend/user-service/README.md +++ b/backend/user-service/README.md @@ -44,11 +44,19 @@ ## Running User Service without Docker -1. Open Command Line/Terminal and navigate into the `user-service` directory. +1. Set up and run Redis using `docker compose run --rm --name redis -p 6379:6379 redis`. -2. Run the command: `npm install`. This will install all the necessary dependencies. +2. Open Command Line/Terminal and navigate into the `user-service` directory. -3. Run the command `npm start` to start the User Service in production mode, or use `npm run dev` for development mode, which includes features like automatic server restart when you make code changes. +3. Run the command: `npm install`. This will install all the necessary dependencies. + +4. Run the command `npm start` to start the User Service in production mode, or use `npm run dev` for development mode, which includes features like automatic server restart when you make code changes. + +## Running User Service Individually with Docker + +1. Open the command line/terminal. + +2. Run the command `docker compose run user-service` to start up the user service and its dependencies. ## After running From 0608776c6033d1287dc74afadecd817d74a8352c Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Sun, 20 Oct 2024 21:19:07 +0800 Subject: [PATCH 4/7] Update according to comments --- backend/user-service/.env.sample | 2 +- backend/user-service/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/user-service/.env.sample b/backend/user-service/.env.sample index fc13daa4bf..d5f06fada2 100644 --- a/backend/user-service/.env.sample +++ b/backend/user-service/.env.sample @@ -29,7 +29,7 @@ USER=EMAIL_ADDRESS PASS=PASSWORD # Redis configuration -REDIS_URI=redis://redis:6379 # Uncomment if you're running the user service with docker +REDIS_URI=redis://redis:6379 # Uncomment if you're running the user service using docker compose # REDIS_URI=redis://localhost:6379 # Uncomment if you're running the user service individually without docker # Test diff --git a/backend/user-service/README.md b/backend/user-service/README.md index 6618903821..24fbddefd5 100644 --- a/backend/user-service/README.md +++ b/backend/user-service/README.md @@ -42,7 +42,7 @@ 3. Enter `host.internal.docker` as the Host. -## Running User Service without Docker +## Running User Service Individually 1. Set up and run Redis using `docker compose run --rm --name redis -p 6379:6379 redis`. From 06d4ae4b57fa042812c4b08d8c21f963d3ab4730 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Sun, 20 Oct 2024 21:24:22 +0800 Subject: [PATCH 5/7] Add matching service to ci --- .github/workflows/ci.yml | 6 +++--- .../tests/webSocketHandler.spec.ts | 5 +++++ docker-compose-test.yml | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 backend/matching-service/tests/webSocketHandler.spec.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a9028ae98..e7dceb180d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,13 +27,13 @@ jobs: - name: Linting working-directory: frontend run: npm run lint - - name: Frontend tests + - name: Test run: docker compose -f docker-compose-test.yml run --rm test-frontend backend-ci: runs-on: ubuntu-latest strategy: matrix: - service: [question-service, user-service] + service: [question-service, user-service, matching-service] steps: - name: Checkout code uses: actions/checkout@v4 @@ -47,7 +47,7 @@ jobs: - name: Linting working-directory: backend/${{ matrix.service }} run: npm run lint - - name: Backend tests + - name: Test env: FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }} FIREBASE_PRIVATE_KEY: ${{ secrets.FIREBASE_PRIVATE_KEY }} diff --git a/backend/matching-service/tests/webSocketHandler.spec.ts b/backend/matching-service/tests/webSocketHandler.spec.ts new file mode 100644 index 0000000000..1b286ac176 --- /dev/null +++ b/backend/matching-service/tests/webSocketHandler.spec.ts @@ -0,0 +1,5 @@ +describe("Test web socket", () => { + it("Test", () => { + expect(true); + }); +}); diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 37302b7c30..d0fb46f074 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -53,6 +53,24 @@ services: restart: on-failure command: ["npm", "test"] + test-matching-service: + image: peerprep/matching-service + build: ./backend/matching-service + # env_file: ./backend/matching-service/.env + environment: + - NODE_ENV=test + - PORT=3002 + - RABBITMQ_DEFAULT_USER=admin + - RABBITMQ_DEFAULT_PASS=password + - RABBITMQ_ADDR=amqp://admin:password@rabbitmq:5672 + networks: + - peerprep-network + volumes: + - ./backend/matching-service:/matching-service + - /matching-service/node_modules + restart: on-failure + command: ["npm", "test"] + test-frontend: image: peerprep/frontend build: ./frontend From 6a69919bbd8c904e4ea9eba30ee5d7d53b9052b4 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Sun, 20 Oct 2024 21:42:20 +0800 Subject: [PATCH 6/7] Change collab sandbox text --- frontend/src/pages/CollabSandbox/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/CollabSandbox/index.tsx b/frontend/src/pages/CollabSandbox/index.tsx index 969a9e89bb..e46465f10d 100644 --- a/frontend/src/pages/CollabSandbox/index.tsx +++ b/frontend/src/pages/CollabSandbox/index.tsx @@ -35,7 +35,7 @@ const CollabSandbox: React.FC = () => { return ( - Collaborative Sandbox + Successfully matched! Coming soon...