From 6257f424f63f5ba1fcfca8657da7d2e00f9fa09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=98=81=EC=9A=B0?= Date: Thu, 11 Jul 2024 08:09:15 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=ED=83=9C=EC=8A=A4=ED=81=AC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EC=82=AD=EC=A0=9C,=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20E2E=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ws-backlog-page/ws-story.e2e-spec.ts | 1 - .../ws-backlog-page/ws-task.e2e-spec.ts | 394 ++++++++++++++++++ 2 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 backend/test/project/ws-backlog-page/ws-task.e2e-spec.ts diff --git a/backend/test/project/ws-backlog-page/ws-story.e2e-spec.ts b/backend/test/project/ws-backlog-page/ws-story.e2e-spec.ts index a4a560c..02cf54e 100644 --- a/backend/test/project/ws-backlog-page/ws-story.e2e-spec.ts +++ b/backend/test/project/ws-backlog-page/ws-story.e2e-spec.ts @@ -150,7 +150,6 @@ describe('WS story', () => { const expectTitleUpdateStory = (socket, id, title) => { return new Promise((resolve) => { socket.once('backlog', async (data) => { - console.log(data); const { content, action, domain } = data; expect(domain).toBe('story'); expect(action).toBe('update'); diff --git a/backend/test/project/ws-backlog-page/ws-task.e2e-spec.ts b/backend/test/project/ws-backlog-page/ws-task.e2e-spec.ts new file mode 100644 index 0000000..787411c --- /dev/null +++ b/backend/test/project/ws-backlog-page/ws-task.e2e-spec.ts @@ -0,0 +1,394 @@ +import { Socket } from 'socket.io-client'; +import { app, appInit } from 'test/setup'; +import { + getMemberJoinedLandingPage, + getTwoMemberJoinedLandingPage, +} from '../ws-common'; + +describe('WS task', () => { + beforeEach(async () => { + await app.close(); + await appInit(); + await app.listen(3000); + }); + + describe('task create', () => { + it('should return created task 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 [epicId] = await Promise.all([ + getEpicId(socket1), + getEpicId(socket2), + ]); + + const storyTitle = '타이틀'; + const storyPoint = 2; + const storyStatus = '시작전'; + requestData = { + action: 'create', + content: { + title: storyTitle, + point: storyPoint, + status: storyStatus, + epicId, + }, + }; + socket1.emit('story', requestData); + const [storyId] = await Promise.all([ + getStoryId(socket1), + getStoryId(socket2), + ]); + + await testCreateTask( + socket1, + socket2, + '타이틀', + '시작전', + storyId, + null, + null, + null, + ); + + await testCreateTask( + socket1, + socket2, + '타이틀', + '시작전', + storyId, + 2.1, + 3.3, + null, + ); + + await testCreateTask( + socket1, + socket2, + '타이틀', + '진행중', + storyId, + null, + null, + null, + ); + + await testCreateTask( + socket1, + socket2, + '타이틀', + '완료', + storyId, + null, + null, + null, + ); + + socket1.close(); + socket2.close(); + }); + + const testCreateTask = async ( + socket1, + socket2, + title, + status, + storyId, + expectedTime, + actualTime, + assignedMemberId, + ) => { + const requestData = { + action: 'create', + content: { + title, + status, + storyId, + expectedTime, + actualTime, + assignedMemberId, + }, + }; + socket1.emit('task', requestData); + + await Promise.all([ + expectCreateTask( + socket1, + title, + status, + storyId, + expectedTime, + actualTime, + assignedMemberId, + ), + expectCreateTask( + socket2, + title, + status, + storyId, + expectedTime, + actualTime, + assignedMemberId, + ), + ]); + }; + + const expectCreateTask = ( + socket, + title, + status, + storyId, + expectedTime, + actualTime, + assignedMemberId, + ) => { + return new Promise((resolve) => { + socket.once('backlog', async (data) => { + const { content, action, domain } = data; + expect(domain).toBe('task'); + expect(action).toBe('create'); + expect(content?.id).toBeDefined(); + expect(content?.displayId).toBeDefined(); + expect(content?.title).toBe(title); + expect(content?.status).toBe(status); + expect(content?.storyId).toBe(storyId); + expect(content?.actualTime).toBe(actualTime); + expect(content?.expectedTime).toBe(expectedTime); + expect(content?.assignedMemberId).toBe(assignedMemberId); + resolve(); + }); + }); + }; + }); + + describe('task delete', () => { + it('should return deleted task data', async () => { + const socket = await getMemberJoinedLandingPage(); + socket.emit('joinBacklog'); + await initBacklog(socket); + + const name = '회원'; + const color = 'yellow'; + let requestData: any = { + action: 'create', + content: { name, color }, + }; + socket.emit('epic', requestData); + const [epicId] = await Promise.all([getEpicId(socket)]); + + const title = '타이틀'; + const point = 2; + const status = '시작전'; + requestData = { + action: 'create', + content: { title, point, status, epicId }, + }; + socket.emit('story', requestData); + const storyId = await getStoryId(socket); + + let taskTitle = '타이틀'; + let taskStatus = '시작전'; + let expectedTime = null; + let actualTime = null; + let assignedMemberId = null; + requestData = { + action: 'create', + content: { + title: taskTitle, + status: taskStatus, + storyId, + expectedTime, + actualTime, + assignedMemberId, + }, + }; + socket.emit('task', requestData); + const taskId = await getTaskId(socket); + + requestData = { + action: 'delete', + content: { id: taskId }, + }; + socket.emit('task', requestData); + await expectDeleteTask(socket, taskId); + + socket.close(); + }); + + const expectDeleteTask = (socket, id) => { + return new Promise((resolve) => { + socket.once('backlog', async (data) => { + const { content, action, domain } = data; + expect(domain).toBe('task'); + expect(action).toBe('delete'); + expect(content?.id).toBe(id); + resolve(); + }); + }); + }; + }); + + describe('task update', () => { + it('should return updated task data when update color', async () => { + const socket = await getMemberJoinedLandingPage(); + socket.emit('joinBacklog'); + await initBacklog(socket); + + const name = '회원'; + const color = 'yellow'; + let requestData: any = { + action: 'create', + content: { name, color }, + }; + socket.emit('epic', requestData); + const [epicId] = await Promise.all([getEpicId(socket)]); + + const title = '타이틀'; + const point = 2; + const status = '시작전'; + requestData = { + action: 'create', + content: { title, point, status, epicId }, + }; + socket.emit('story', requestData); + const storyId = await getStoryId(socket); + + let taskTitle = '타이틀'; + let taskStatus = '시작전'; + let expectedTime = null; + let actualTime = null; + let assignedMemberId = null; + requestData = { + action: 'create', + content: { + title: taskTitle, + status: taskStatus, + storyId, + expectedTime, + actualTime, + assignedMemberId, + }, + }; + socket.emit('task', requestData); + const taskId = await getTaskId(socket); + + const newTitle = 'newTitle'; + requestData = { + action: 'update', + content: { id: taskId, title: newTitle }, + }; + socket.emit('task', requestData); + await expectTitleUpdateTask(socket, taskId, newTitle); + + const newExpectedTime = 5; + const newActualTime = 3; + const newStatus = '완료'; + requestData = { + action: 'update', + content: { + id: taskId, + expectedTime: newExpectedTime, + actualTime: newActualTime, + status: newStatus, + }, + }; + socket.emit('task', requestData); + await expectTimeAndStatusWhenUpdateTask( + socket, + taskId, + newExpectedTime, + newActualTime, + newStatus, + ); + + socket.close(); + }); + + const expectTitleUpdateTask = (socket, id, title) => { + return new Promise((resolve) => { + socket.once('backlog', async (data) => { + const { content, action, domain } = data; + expect(domain).toBe('task'); + expect(action).toBe('update'); + expect(content?.id).toBe(id); + expect(content?.title).toBe(title); + resolve(); + }); + }); + }; + + const expectTimeAndStatusWhenUpdateTask = ( + socket, + id, + expectedTime, + actualTime, + status, + ) => { + return new Promise((resolve) => { + socket.once('backlog', async (data) => { + const { content, action, domain } = data; + expect(domain).toBe('task'); + expect(action).toBe('update'); + expect(content?.id).toBe(id); + expect(content?.expectedTime).toBe(expectedTime); + expect(content?.actualTime).toBe(actualTime); + expect(content?.status).toBe(status); + resolve(); + }); + }); + }; + }); +}); + +const initBacklog = async (socket: Socket) => { + return await new Promise((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); + } + }); + }); +}; + +const getStoryId = (socket) => { + return new Promise((resolve) => { + socket.once('backlog', async (data) => { + const { content, action, domain } = data; + if (domain === 'story' && action === 'create') { + resolve(content.id); + } + }); + }); +}; + +const getTaskId = (socket) => { + return new Promise((resolve) => { + socket.once('backlog', async (data) => { + const { content, action, domain } = data; + if (domain === 'task' && action === 'create') { + resolve(content.id); + } + }); + }); +};