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 all 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
7 changes: 7 additions & 0 deletions backend/signal/mocks/events/logger.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const loggerServiceMock = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
fatal: jest.fn(),
};
28 changes: 28 additions & 0 deletions backend/signal/mocks/events/room.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { guestSocketMock, hostSocketMock } from './socket.mock';

type Room = {
roomId: string;
password: string;
wrongRoomId: string;
wrongPassword: string;
};

export const roomMock: Room = {
roomId: 'testRoomId',
password: 'testPassword',
wrongRoomId: 'wrongRoomId',
wrongPassword: 'wrongPassword',
};

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]);
22 changes: 22 additions & 0 deletions backend/signal/mocks/events/socket.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type SocketMock = {
id: string;
emit: jest.Mock;
join: jest.Mock;
to: jest.Mock;
};

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 })),
};
Comment on lines +1 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 이런 식으로 mock 파일들 모아놓는 거 참고 많이 했어!

28 changes: 28 additions & 0 deletions backend/signal/mocks/events/user.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { guestSocketMock, hostSocketMock } from './socket.mock';

type User = {
roomId: string;
role: 'host' | 'guest';
};

export const hostUserMock: User = {
roomId: 'testRoomId',
role: 'host',
};
export const guestUserMock: User = {
roomId: 'testRoomId',
role: 'guest',
};

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 }]);

export const createUsersMock = (mock: Array<{ id: string; user: User }>) =>
mock.reduce((acc, { id, user }) => ({ ...acc, [id]: user }), {});
46 changes: 42 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.

13 changes: 10 additions & 3 deletions backend/signal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 All @@ -57,7 +57,8 @@
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
"typescript": "^5.1.3",
"socket.io-client": "^4.7.3"
},
"jest": {
"moduleFileExtensions": [
Expand All @@ -74,6 +75,12 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
},
"modulePaths": [
"<rootDir>/.."
]
}
}
Loading