Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fe,be/feature/#456 web rtc test code작성 #466

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions backend/signal/mocks/eventGatewayMocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
type User = {
roomId: string;
role: 'host' | 'guest';
};
type Room = {
roomId: string;
password: string;
wrongRoomId: string;
wrongPassword: string;
};
export type SocketMock = {
id: string;
emit: jest.Mock;
join: jest.Mock;
to: jest.Mock;
};

export const hostUserMock: User = {
roomId: 'testRoomId',
role: 'host',
};
export const guestUserMock: User = {
roomId: 'testRoomId',
role: 'guest',
};
export const roomMock: Room = {
roomId: 'testRoomId',
password: 'testPassword',
wrongRoomId: 'wrongRoomId',
wrongPassword: 'wrongPassword',
};

export const toRoomEmitMock = jest.fn();

export const guestSocketMock: SocketMock = {
id: 'testGuestSocketId',
emit: jest.fn(),
join: jest.fn(),
to: jest.fn().mockImplementation(() => ({ emit: toRoomEmitMock })),
};

export const hostSocketMock: SocketMock = {
id: 'testHostSocketId',
emit: jest.fn(),
join: jest.fn(),
to: jest.fn().mockImplementation(() => ({ emit: toRoomEmitMock })),
};

export const loggerServiceMock = { debug: jest.fn(), info: jest.fn() };

export const createRoomMock = (users: string[]) => ({
[roomMock.roomId]: {
users,
password: roomMock.password,
},
});

export const twoPeopleInsideRoomMock = () =>
createRoomMock([hostSocketMock.id, guestSocketMock.id]);
export const onlyGuestInsideRoomMock = () =>
createRoomMock([guestSocketMock.id]);
export const onlyHostInsideRoomMock = () => createRoomMock([hostSocketMock.id]);

export const createUsersMock = (mock: Array<{ id: string; user: User }>) =>
mock.reduce((acc, { id, user }) => ({ ...acc, [id]: user }), {});

export const twoPeopleInsideUsersMock = () =>
createUsersMock([
{ id: hostSocketMock.id, user: hostUserMock },
{ id: guestSocketMock.id, user: guestUserMock },
]);
export const onlyGuestInsideUsersMock = () =>
createUsersMock([{ id: guestSocketMock.id, user: guestUserMock }]);
export const onlyHostInsideUsersMock = () =>
createUsersMock([{ id: hostSocketMock.id, user: hostUserMock }]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 오 mock을 별도의 파일로 분리하니까 좋은 것 같아 👍 mock 이 많으니까 이것도 용도에 따라 분리하는 건 어떨까? 예를 들어 user 관련은 user.mocks.ts 파일에 저장하는 식으로?

✨ signal 서버에 다른 서비스가 추가될 수도 있으니까 eventsGatewayMocks.tsevents 디렉토리 안에 넣는 게 어떨까??

mocks
- events # src/events니까 events로 작성해주면 좋겠어!
  - gateway.mocks.ts # nest cli가 파일명을 camel case로 작성하지 않더라구! 주로 온점을 활용하는 것 같아  

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 오 mock을 별도의 파일로 분리하니까 좋은 것 같아 👍 mock 이 많으니까 이것도 용도에 따라 분리하는 건 어떨까? 예를 들어 user 관련은 user.mocks.ts 파일에 저장하는 식으로?

확실히 지금도 한눈에 파악이 안돼서 용도에 따라 분리하면 더 좋을것같아 추가해둘게!

✨ signal 서버에 다른 서비스가 추가될 수도 있으니까 eventsGatewayMocks.ts를 events 디렉토리 안에 넣는 게 어떨까??

이것도 좋은것같아!👍

43 changes: 39 additions & 4 deletions backend/signal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions backend/signal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.3",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socket.io-client가 유닛 테스트를 할 때 필요한 거지?? (갑자기 추가된 것 같아서!!) 유닛 테스트용이면 devDependencies에 있어야 하지 않을까?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 그렇네 테스트 할때만 필요한거니까 저기 있을 필요는 없겠다

"uuid": "^9.0.1",
"winston": "^3.11.0"
},
Expand All @@ -41,7 +42,7 @@
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/node": "^20.10.7",
"@types/supertest": "^2.0.12",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
Expand Down Expand Up @@ -74,6 +75,9 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
}
}
Loading