diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 505efd528d..e7dceb180d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,14 +27,13 @@ jobs: - name: Linting working-directory: frontend run: npm run lint - - name: Frontend tests - working-directory: frontend + - 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 @@ -48,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/backend/user-service/.env.sample b/backend/user-service/.env.sample index 34c14ef94d..b94597ae29 100644 --- a/backend/user-service/.env.sample +++ b/backend/user-service/.env.sample @@ -26,7 +26,8 @@ USER=EMAIL_ADDRESS PASS=PASSWORD # Redis configuration -REDIS_URI=redis://redis:6379 +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 MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/ diff --git a/backend/user-service/README.md b/backend/user-service/README.md index 7701cab40e..5bd2f732f3 100644 --- a/backend/user-service/README.md +++ b/backend/user-service/README.md @@ -44,15 +44,23 @@ 3. Enter `host.internal.docker` as the Host. -## Running User Service without Docker +## Running User Service Individually > Make sure you have the cloud MongoDB URI in your .env file and set NODE_ENV to production already. -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 diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 16cff61140..6e6b60e26e 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 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[], diff --git a/frontend/src/pages/CollabSandbox/index.tsx b/frontend/src/pages/CollabSandbox/index.tsx index 969a9e89bb..3bc93e2170 100644 --- a/frontend/src/pages/CollabSandbox/index.tsx +++ b/frontend/src/pages/CollabSandbox/index.tsx @@ -35,8 +35,7 @@ const CollabSandbox: React.FC = () => { return ( - Collaborative Sandbox - Coming soon... + Successfully matched!