Skip to content

Commit

Permalink
test: 에픽 생성, 삭제, 업데이트 E2E 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
choyoungwoo9 committed Jul 3, 2024
1 parent bcf3487 commit 6000d2f
Show file tree
Hide file tree
Showing 2 changed files with 253 additions and 0 deletions.
196 changes: 196 additions & 0 deletions backend/test/project/ws-backlog-page/ws-epic.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import { Socket } from 'socket.io-client';
import { app, appInit } from 'test/setup';
import {
getMemberJoinedLandingPage,
getTwoMemberJoinedLandingPage,
} from '../ws-common';

describe('WS epic', () => {
beforeEach(async () => {
await app.close();
await appInit();
await app.listen(3000);
});

describe('epic create', () => {
it('should return created epic data', async () => {
const [socket1, socket2] = await getTwoMemberJoinedLandingPage();
socket1.emit('joinBacklog');
socket2.emit('joinBacklog');
await Promise.all([initBacklog(socket1), initBacklog(socket2)]);
const name = '회원';
const color = 'yellow';
const requestData = {
action: 'create',
content: { name, color },
};
socket1.emit('epic', requestData);
await Promise.all([
expectCreateEpic(socket1, name, color),
expectCreateEpic(socket2, name, color),
]);
socket1.close();
socket2.close();
});

const expectCreateEpic = (socket, name, color) => {
return new Promise<void>((resolve) => {
socket.once('backlog', async (data) => {
const { content, action, domain } = data;
expect(domain).toBe('epic');
expect(action).toBe('create');
expect(content?.id).toBeDefined();
expect(content?.name).toBe(name);
expect(content?.color).toBe(color);
resolve();
});
});
};
});

describe('epic delete', () => {
it('should return deleted epic data', async () => {
const [socket1, socket2] = await getTwoMemberJoinedLandingPage();
socket1.emit('joinBacklog');
socket2.emit('joinBacklog');
await Promise.all([initBacklog(socket1), initBacklog(socket2)]);
const name = '회원';
const color = 'yellow';
let requestData: any = {
action: 'create',
content: { name, color },
};
socket1.emit('epic', requestData);

const [id] = await Promise.all([getEpicId(socket1), getEpicId(socket2)]);

requestData = {
action: 'delete',
content: { id },
};

socket1.emit('epic', requestData);
await Promise.all([
expectDeleteEpic(socket1, id),
expectDeleteEpic(socket2, id),
]);

socket1.close();
socket2.close();
});

const expectDeleteEpic = (socket, id) => {
return new Promise<void>((resolve) => {
socket.once('backlog', async (data) => {
const { content, action, domain } = data;
expect(domain).toBe('epic');
expect(action).toBe('delete');
expect(content?.id).toBe(id);
resolve();
});
});
};
});

describe('epic update', () => {
it('should return updated epic data when update color', async () => {
const socket = await getMemberJoinedLandingPage();
socket.emit('joinBacklog');
await initBacklog(socket);
const name = '회원';
let color = 'yellow';
let requestData: any = {
action: 'create',
content: { name, color },
};
socket.emit('epic', requestData);
const id = await getEpicId(socket);

color = 'green';
requestData = {
action: 'update',
content: { id, color },
};

socket.emit('epic', requestData);
await expectColorUpdateEpic(socket, id, color);

socket.close();
});

const expectColorUpdateEpic = (socket, id, color) => {
return new Promise<void>((resolve) => {
socket.once('backlog', async (data) => {
const { content, action, domain } = data;
expect(domain).toBe('epic');
expect(action).toBe('update');
expect(content?.id).toBe(id);
expect(content?.color).toBe(color);
resolve();
});
});
};

it('should return updated epic data when update name and color', async () => {
const socket = await getMemberJoinedLandingPage();
socket.emit('joinBacklog');
await initBacklog(socket);
let name = '회원';
let color = 'yellow';
let requestData: any = {
action: 'create',
content: { name, color },
};
socket.emit('epic', requestData);
const id = await getEpicId(socket);

name = '프로젝트';
color = 'purple';
requestData = {
action: 'update',
content: { id, color, name },
};

socket.emit('epic', requestData);
await expectNameAndColorUpdateEpic(socket, id, name, color);

socket.close();
});

const expectNameAndColorUpdateEpic = (socket, id, name, color) => {
return new Promise<void>((resolve) => {
socket.once('backlog', async (data) => {
const { content, action, domain } = data;
expect(domain).toBe('epic');
expect(action).toBe('update');
expect(content?.id).toBe(id);
expect(content?.color).toBe(color);
expect(content?.name).toBe(name);
resolve();
});
});
};
});
});

const initBacklog = async (socket: Socket) => {
return await new Promise<void>((resolve, reject) => {
socket.once('backlog', (data) => {
const { action, domain } = data;
if (action === 'init' && domain === 'backlog') {
resolve();
} else reject();
});
});
};

const getEpicId = (socket) => {
return new Promise((resolve) => {
socket.once('backlog', async (data) => {
const { content, action, domain } = data;
if (domain === 'epic' && action === 'create') {
resolve(content.id);
}
});
});
};
57 changes: 57 additions & 0 deletions backend/test/project/ws-common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
import { Socket } from 'socket.io-client';
import {
app,
connectServer,
createMember,
createProject,
getProjectLinkId,
joinProject,
memberFixture,
memberFixture2,
projectPayload,
} from 'test/setup';

export const getMemberJoinedLandingPage = async () => {
let socket;
await new Promise<void>(async (resolve, reject) => {
const accessToken = (await createMember(memberFixture, app)).accessToken;
const project = await createProject(accessToken, projectPayload, app);

socket = connectServer(project.id, accessToken);
handleConnectErrorWithReject(socket, reject);
handleErrorWithReject(socket, reject);
await emitJoinLanding(socket);
await initLanding(socket);
resolve();
});
return socket;
};

export const getTwoMemberJoinedLandingPage = async () => {
let socket1;
let socket2;
await new Promise<void>(async (resolve, reject) => {
// 회원1 회원가입 + 프로젝트 생성
const accessToken = (await createMember(memberFixture, app)).accessToken;
const project = await createProject(accessToken, projectPayload, app);
const projectLinkId = await getProjectLinkId(accessToken, project.id);

// 회원2 회원가입 + 프로젝트 참여
const accessToken2 = (await createMember(memberFixture2, app)).accessToken;
await joinProject(accessToken2, projectLinkId);

socket1 = connectServer(project.id, accessToken);
handleConnectErrorWithReject(socket1, reject);
handleErrorWithReject(socket1, reject);
await emitJoinLanding(socket1);
await initLanding(socket1);

socket2 = connectServer(project.id, accessToken2);
handleConnectErrorWithReject(socket2, reject);
handleErrorWithReject(socket2, reject);
await emitJoinLanding(socket2);
const memberId2 = await initLandingAndReturnId(socket2);
await expectUpdatedMemberStatus(socket1, 'on', memberId2);
resolve();
});
return [socket1, socket2];
};

export const handleConnectErrorWithReject = (
socket: Socket,
Expand Down

0 comments on commit 6000d2f

Please sign in to comment.