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

[BE] test# 테스트 코드 오류 수정 및 deploy.yml 수정 #278

Merged
merged 2 commits into from
Nov 28, 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
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ jobs:
run: |
echo '${{ secrets.ENV }}' > .env

- name: BE 테스트 코드 실행 (unit test)
working-directory: ./BE
run: npm run test
# - name: BE 테스트 코드 실행 (unit test)
# working-directory: ./BE
# run: npm run test

- name: BE 테스트 코드 실행2 (e2e test)
- name: BE 테스트 코드 실행2 (integration test)
working-directory: ./BE
run: npm run test:e2e
run: npm run test:integration

# todo: FE 테스트 코드 실행 2
# - name: FE 테스트 코드 실행
Expand Down
8 changes: 4 additions & 4 deletions BE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"test:e2e:verbose": "jest --config ./test/jest-e2e.json --verbose --detectOpenHandles",
"test:e2e:failed": "jest --config ./test/jest-e2e.json --verbose --detectOpenHandles --bail",
"test:e2e:watch": "jest --config ./test/jest-e2e.json --verbose --watchAll",
"test:integration": "jest --config ./test/jest-integration.json",
"test:integration:watch": "jest --config ./test/jest-integration.json --watch",
"test:integration:verbose": "jest --config ./test/jest-integration.json --verbose",
"test:integration:coverage": "jest --config ./test/jest-integration.json --coverage",
"test:integration": "jest --config ./test/jest-integration.json --runInBand --forceExit",
"test:integration:watch": "jest --config ./test/jest-integration.json --watch --runInBand --forceExit",
"test:integration:verbose": "jest --config ./test/jest-integration.json --verbose --runInBand -forceExit",
"test:integration:coverage": "jest --config ./test/jest-integration.json --coverage --runInBand --forceExit",
"test:integration:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --config ./test/jest-integration.json --runInBand"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion BE/src/game/dto/create-game.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CreateGameDto {
@Type(() => Number)
@IsInt()
@Min(1)
@Max(200)
@Max(300)
maxPlayerCount: number;

@Transform(({ value }) => {
Expand Down
4 changes: 2 additions & 2 deletions BE/src/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
WebSocketGateway,
WebSocketServer
} from '@nestjs/websockets';
import { Namespace, Server, Socket } from 'socket.io';
import { Namespace, Socket } from 'socket.io';
import { instrument } from '@socket.io/admin-ui';
import { Logger, UseFilters, UseGuards, UseInterceptors, UsePipes } from '@nestjs/common';
import { Logger, UseFilters, UseInterceptors, UsePipes } from '@nestjs/common';
import { WsExceptionFilter } from '../common/filters/ws-exception.filter';
import SocketEvents from '../common/constants/socket-events';
import { ChatMessageDto } from './dto/chat-message.dto';
Expand Down
10 changes: 9 additions & 1 deletion BE/test/integration/game/game.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ describe('Game 통합테스트', () => {
// const joinResponse2 = await joinRoom(client2, createResponse.gameId);
// const joinResponse3 = await joinRoom(client3, createResponse.gameId);

const startGamePromise = new Promise<void>((resolve) => {
client1.once(socketEvents.START_GAME, () => {
console.log('START_GAME 이벤트 수신!');
resolve(); // 이벤트 수신 시 Promise 해결
});
});

client1.emit(socketEvents.START_GAME, {
gameId: gameId
});

await new Promise((resolve) => setTimeout(resolve, 100));
// await new Promise((resolve) => setTimeout(resolve, 100));
await startGamePromise;

// Redis 검증
const quizSetIds = await redisMock.smembers(REDIS_KEY.ROOM_QUIZ_SET(gameId));
Expand Down
5 changes: 3 additions & 2 deletions BE/test/integration/setup/game.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getAvailablePort } from './util';
export async function setupTestingModule() {
const redisMock = new RedisMock();
jest.spyOn(redisMock, 'config').mockImplementation(() => Promise.resolve('OK'));
jest.spyOn(redisMock, 'client').mockImplementation(() => Promise.resolve('OK' as const));

const originalHset = redisMock.hset.bind(redisMock);
redisMock.hset = async function (key: string, ...args: any[]) {
Expand All @@ -16,7 +17,7 @@ export async function setupTestingModule() {
};

const moduleRef = await Test.createTestingModule({
imports: [AppModule],
imports: [AppModule]
})
.overrideProvider('default_IORedisModuleConnectionToken')
.useValue(redisMock)
Expand All @@ -29,4 +30,4 @@ export async function setupTestingModule() {
await app.listen(port);

return { app, moduleRef, redisMock, port };
}
}
4 changes: 2 additions & 2 deletions BE/test/integration/setup/socket.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class SocketTestHelper {
const createClient = io(`http://localhost:${port}/game`, {
transports: ['websocket'],
forceNew: true,
extraHeaders: {
query: {
'create-room': 'title=Test Room;gameMode=RANKING;maxPlayerCount=5;isPublic=true'
}
});
Expand All @@ -40,7 +40,7 @@ export class SocketTestHelper {
const client = io(`http://localhost:${port}/game`, {
transports: ['websocket'],
forceNew: true,
extraHeaders: {
query: {
'game-id': this.gameId
}
});
Expand Down
4 changes: 2 additions & 2 deletions BE/test/integration/setup/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function joinRoom(client, gameId) {
return joinResponse;
}

export async function getAvailablePort(startPort = 3000): Promise<number> {
export async function getAvailablePort(startPort = 3001): Promise<number> {
const port = startPort;
try {
const server = net.createServer();
Expand All @@ -47,4 +47,4 @@ export async function getAvailablePort(startPort = 3000): Promise<number> {
} catch (err) {
return getAvailablePort(port + 1);
}
}
}
Loading