Skip to content

Commit

Permalink
resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
feliciagan committed Oct 20, 2024
2 parents 94fa627 + 59f7419 commit c12affc
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 45 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
5 changes: 5 additions & 0 deletions backend/matching-service/tests/webSocketHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("Test web socket", () => {
it("Test", () => {
expect(true);
});
});
3 changes: 2 additions & 1 deletion backend/user-service/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
16 changes: 12 additions & 4 deletions backend/user-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 31 additions & 34 deletions frontend/src/contexts/MatchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
}
const { user } = auth;

const [matchUser] = useState<MatchUser | null>(
user
? {
id: user.id,
username: user.username,
profile: user.profilePictureUrl,
}
: null
);

const [matchUser, setMatchUser] = useState<MatchUser | null>(null);
const [matchCriteria, setMatchCriteria] = useState<MatchCriteria | null>(
null
);
Expand All @@ -118,6 +109,18 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
const [matchPending, setMatchPending] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(true);

useEffect(() => {
if (user) {
setMatchUser({
id: user.id,
username: user.username,
profile: user.profilePictureUrl,
});
} else {
setMatchUser(null);
}
}, [user]);

useEffect(() => {
if (
!matchUser?.id ||
Expand Down Expand Up @@ -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, () => {
Expand All @@ -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);
});
};

Expand All @@ -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, () => {
Expand All @@ -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[],
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/CollabSandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const CollabSandbox: React.FC = () => {
return (
<AppMargin classname={`${classes.fullheight} ${classes.center}`}>
<Stack spacing={2} alignItems={"center"}>
<Typography variant="h1">Collaborative Sandbox</Typography>
<Typography variant="h3">Coming soon...</Typography>
<Typography variant="h1">Successfully matched!</Typography>
<Button variant="outlined" color="error" onClick={() => stopMatch()}>
End Session
</Button>
Expand Down

0 comments on commit c12affc

Please sign in to comment.