Skip to content

Commit c12affc

Browse files
committed
resolve merge conflict
2 parents 94fa627 + 59f7419 commit c12affc

File tree

7 files changed

+72
-45
lines changed

7 files changed

+72
-45
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ jobs:
2727
- name: Linting
2828
working-directory: frontend
2929
run: npm run lint
30-
- name: Frontend tests
31-
working-directory: frontend
30+
- name: Test
3231
run: docker compose -f docker-compose-test.yml run --rm test-frontend
3332
backend-ci:
3433
runs-on: ubuntu-latest
3534
strategy:
3635
matrix:
37-
service: [question-service, user-service]
36+
service: [question-service, user-service, matching-service]
3837
steps:
3938
- name: Checkout code
4039
uses: actions/checkout@v4
@@ -48,7 +47,7 @@ jobs:
4847
- name: Linting
4948
working-directory: backend/${{ matrix.service }}
5049
run: npm run lint
51-
- name: Backend tests
50+
- name: Test
5251
env:
5352
FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
5453
FIREBASE_PRIVATE_KEY: ${{ secrets.FIREBASE_PRIVATE_KEY }}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe("Test web socket", () => {
2+
it("Test", () => {
3+
expect(true);
4+
});
5+
});

backend/user-service/.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ USER=EMAIL_ADDRESS
2626
PASS=PASSWORD
2727

2828
# Redis configuration
29-
REDIS_URI=redis://redis:6379
29+
REDIS_URI=redis://redis:6379 # Uncomment if you're running the user service using docker compose
30+
# REDIS_URI=redis://localhost:6379 # Uncomment if you're running the user service individually without docker
3031

3132
# Test
3233
MONGO_URI_TEST=mongodb://mongo:mongo@test-mongo:27017/

backend/user-service/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,23 @@
4444

4545
3. Enter `host.internal.docker` as the Host.
4646

47-
## Running User Service without Docker
47+
## Running User Service Individually
4848

4949
> Make sure you have the cloud MongoDB URI in your .env file and set NODE_ENV to production already.
5050
51-
1. Open Command Line/Terminal and navigate into the `user-service` directory.
51+
1. Set up and run Redis using `docker compose run --rm --name redis -p 6379:6379 redis`.
5252

53-
2. Run the command: `npm install`. This will install all the necessary dependencies.
53+
2. Open Command Line/Terminal and navigate into the `user-service` directory.
5454

55-
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.
55+
3. Run the command: `npm install`. This will install all the necessary dependencies.
56+
57+
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.
58+
59+
## Running User Service Individually with Docker
60+
61+
1. Open the command line/terminal.
62+
63+
2. Run the command `docker compose run user-service` to start up the user service and its dependencies.
5664

5765
## After running
5866

docker-compose-test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ services:
5353
restart: on-failure
5454
command: ["npm", "test"]
5555

56+
test-matching-service:
57+
image: peerprep/matching-service
58+
build: ./backend/matching-service
59+
# env_file: ./backend/matching-service/.env
60+
environment:
61+
- NODE_ENV=test
62+
- PORT=3002
63+
- RABBITMQ_DEFAULT_USER=admin
64+
- RABBITMQ_DEFAULT_PASS=password
65+
- RABBITMQ_ADDR=amqp://admin:password@rabbitmq:5672
66+
networks:
67+
- peerprep-network
68+
volumes:
69+
- ./backend/matching-service:/matching-service
70+
- /matching-service/node_modules
71+
restart: on-failure
72+
command: ["npm", "test"]
73+
5674
test-frontend:
5775
image: peerprep/frontend
5876
build: ./frontend

frontend/src/contexts/MatchContext.tsx

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
100100
}
101101
const { user } = auth;
102102

103-
const [matchUser] = useState<MatchUser | null>(
104-
user
105-
? {
106-
id: user.id,
107-
username: user.username,
108-
profile: user.profilePictureUrl,
109-
}
110-
: null
111-
);
112-
103+
const [matchUser, setMatchUser] = useState<MatchUser | null>(null);
113104
const [matchCriteria, setMatchCriteria] = useState<MatchCriteria | null>(
114105
null
115106
);
@@ -118,6 +109,18 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
118109
const [matchPending, setMatchPending] = useState<boolean>(false);
119110
const [loading, setLoading] = useState<boolean>(true);
120111

112+
useEffect(() => {
113+
if (user) {
114+
setMatchUser({
115+
id: user.id,
116+
username: user.username,
117+
profile: user.profilePictureUrl,
118+
});
119+
} else {
120+
setMatchUser(null);
121+
}
122+
}, [user]);
123+
121124
useEffect(() => {
122125
if (
123126
!matchUser?.id ||
@@ -233,14 +236,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
233236

234237
const initMatchRequestListeners = () => {
235238
matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => {
236-
setMatchId(matchId);
237-
if (matchUser?.id === user1.id) {
238-
setPartner(user2);
239-
} else {
240-
setPartner(user1);
241-
}
242-
setMatchPending(true);
243-
appNavigate(MatchPaths.MATCHED);
239+
handleMatchFound(matchId, user1, user2);
244240
});
245241

246242
matchSocket.on(MatchEvents.MATCH_REQUEST_EXISTS, () => {
@@ -254,14 +250,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
254250

255251
const initMatchingListeners = () => {
256252
matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => {
257-
setMatchId(matchId);
258-
if (matchUser?.id === user1.id) {
259-
setPartner(user2);
260-
} else {
261-
setPartner(user1);
262-
}
263-
setMatchPending(true);
264-
appNavigate(MatchPaths.MATCHED);
253+
handleMatchFound(matchId, user1, user2);
265254
});
266255
};
267256

@@ -277,14 +266,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
277266
});
278267

279268
matchSocket.on(MatchEvents.MATCH_FOUND, ({ matchId, user1, user2 }) => {
280-
setMatchId(matchId);
281-
if (matchUser?.id === user1.id) {
282-
setPartner(user2);
283-
} else {
284-
setPartner(user1);
285-
}
286-
setMatchPending(true);
287-
appNavigate(MatchPaths.MATCHED);
269+
handleMatchFound(matchId, user1, user2);
288270
});
289271

290272
matchSocket.on(MatchEvents.MATCH_REQUEST_ERROR, () => {
@@ -299,6 +281,21 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
299281
});
300282
};
301283

284+
const handleMatchFound = (
285+
matchId: string,
286+
user1: MatchUser,
287+
user2: MatchUser
288+
) => {
289+
setMatchId(matchId);
290+
if (matchUser?.id === user1.id) {
291+
setPartner(user2);
292+
} else {
293+
setPartner(user1);
294+
}
295+
setMatchPending(true);
296+
appNavigate(MatchPaths.MATCHED);
297+
};
298+
302299
const findMatch = (
303300
complexities: string[],
304301
categories: string[],

frontend/src/pages/CollabSandbox/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const CollabSandbox: React.FC = () => {
3535
return (
3636
<AppMargin classname={`${classes.fullheight} ${classes.center}`}>
3737
<Stack spacing={2} alignItems={"center"}>
38-
<Typography variant="h1">Collaborative Sandbox</Typography>
39-
<Typography variant="h3">Coming soon...</Typography>
38+
<Typography variant="h1">Successfully matched!</Typography>
4039
<Button variant="outlined" color="error" onClick={() => stopMatch()}>
4140
End Session
4241
</Button>

0 commit comments

Comments
 (0)