From d1e32912a745dd695452c0a6539f967f4bd63537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Mon, 12 Feb 2024 01:57:16 +0900 Subject: [PATCH 1/8] =?UTF-8?q?test:=20e2e=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=84=B8=ED=8C=85=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 backend/test/reactions/reactions.e2e-spec.ts diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts new file mode 100644 index 0000000..3e44452 --- /dev/null +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -0,0 +1,46 @@ +import * as request from 'supertest'; +import { ExecutionContext, INestApplication } from '@nestjs/common'; +import { Test } from '@nestjs/testing'; +import { AppModule } from 'src/app.module'; +import { DataSource, QueryRunner } from 'typeorm'; +import { JwtAuthGuard } from 'src/auth/guards/jwtAuth.guard'; + +describe('FriendsController (e2e)', () => { + let app: INestApplication; + let queryRunner: QueryRunner; + + const mockUser = { id: 1 }; + + beforeAll(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }) + .overrideGuard(JwtAuthGuard) + .useValue({ + canActivate: (context: ExecutionContext) => { + const req = context.switchToHttp().getRequest(); + req.user = mockUser; + + return true; + }, + }) + .compile(); + + const dataSource = module.get(DataSource); + queryRunner = dataSource.createQueryRunner(); + dataSource.createQueryRunner = jest.fn(); + queryRunner.release = jest.fn(); + (dataSource.createQueryRunner as jest.Mock).mockReturnValue(queryRunner); + + app = module.createNestApplication(); + await app.init(); + }); + + beforeEach(async () => { + await queryRunner.startTransaction(); + }); + + afterEach(async () => { + await queryRunner.rollbackTransaction(); + }); +}); From e05dc6cdfd6f842d7e96bff437aeb4e77b8e2ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Mon, 12 Feb 2024 15:31:29 +0900 Subject: [PATCH 2/8] =?UTF-8?q?test:=20user=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EC=99=80=20JWT=20guard=20=EB=AA=A8=ED=82=B9=ED=95=98=EC=A7=80?= =?UTF-8?q?=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=84=B8=ED=8C=85=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 94 ++++++++++++++++---- 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts index 3e44452..001e9ee 100644 --- a/backend/test/reactions/reactions.e2e-spec.ts +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -1,30 +1,34 @@ import * as request from 'supertest'; -import { ExecutionContext, INestApplication } from '@nestjs/common'; +import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { AppModule } from 'src/app.module'; import { DataSource, QueryRunner } from 'typeorm'; -import { JwtAuthGuard } from 'src/auth/guards/jwtAuth.guard'; +import { Diary } from 'src/diaries/entity/diary.entity'; +import { SocialType } from 'src/users/entity/socialType'; +import { DiaryStatus } from 'src/diaries/entity/diaryStatus'; +import { DiariesRepository } from 'src/diaries/diaries.repository'; +import { ReactionsRepository } from 'src/reactions/reactions.repository'; +import { UsersRepository } from 'src/users/users.repository'; +import { MoodDegree } from 'src/diaries/utils/diaries.constant'; +import * as cookieParser from 'cookie-parser'; +import { User } from 'src/users/entity/user.entity'; +import { testLogin } from 'test/utils/testLogin'; describe('FriendsController (e2e)', () => { let app: INestApplication; let queryRunner: QueryRunner; - - const mockUser = { id: 1 }; + let reactionsRepository: ReactionsRepository; + let diariesRepository: DiariesRepository; + let usersRepository: UsersRepository; beforeAll(async () => { const module = await Test.createTestingModule({ imports: [AppModule], - }) - .overrideGuard(JwtAuthGuard) - .useValue({ - canActivate: (context: ExecutionContext) => { - const req = context.switchToHttp().getRequest(); - req.user = mockUser; - - return true; - }, - }) - .compile(); + }).compile(); + + reactionsRepository = module.get(ReactionsRepository); + diariesRepository = module.get(DiariesRepository); + usersRepository = module.get(UsersRepository); const dataSource = module.get(DataSource); queryRunner = dataSource.createQueryRunner(); @@ -33,14 +37,74 @@ describe('FriendsController (e2e)', () => { (dataSource.createQueryRunner as jest.Mock).mockReturnValue(queryRunner); app = module.createNestApplication(); + app.use(cookieParser()); await app.init(); }); + afterAll(async () => { + await app.close(); + }); + + let user: User; + let accessToken: string; + let diary: Diary; + + const userInfo = { + socialId: '1234', + socialType: SocialType.NAVER, + nickname: 'test', + email: 'test@abc.com', + profileImage: 'profile image', + }; + const friendInfo = { + socialId: '12345', + socialType: SocialType.NAVER, + nickname: 'friend', + email: 'friend@abc.com', + profileImage: 'profile image', + }; + const diaryInfo = { + title: '์ œ๋ชฉ', + content: '

๋‚ด์šฉ

', + thumbnail: null, + emotion: '๐Ÿฅฐ', + tagNames: ['์ผ๊ธฐ', '์•ˆ๋…•'], + status: DiaryStatus.PUBLIC, + summary: '์ผ๊ธฐ ์š”์•ฝ', + mood: MoodDegree.SO_SO, + }; + beforeEach(async () => { await queryRunner.startTransaction(); + + user = await usersRepository.save(userInfo); + accessToken = await testLogin(user); + diaryInfo['author'] = user; + diary = await diariesRepository.save(diaryInfo); }); afterEach(async () => { await queryRunner.rollbackTransaction(); }); + + // describe('/reactions/:diaryId (GET)', () => { + // it('ํŠน์ • ์ผ๊ธฐ์˜ ๋ฆฌ์•ก์…˜ ์กฐํšŒ', async () => { + // // given + // const url = `/reactions/${diary.id}`; + // const friend = await usersRepository.save(friendInfo); + + // await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); + // await reactionsRepository.save({ user: friend, diary, reaction: '๐Ÿฅฐ' }); + + // // when + // const response = await request(app.getHttpServer()) + // .get(url) + // .set('Cookie', [`utk=${accessToken}`]); + + // // then + // expect(response.statusCode).toEqual(200); + // expect(response.body.reactionList).toHaveLength(2); + // expect(response.body.reactionList[0].reaction).toEqual('๐Ÿ”ฅ'); + // }); + // }); }); From abe6759332802b830b25e0b78d9c84f7d50913dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Mon, 12 Feb 2024 15:35:36 +0900 Subject: [PATCH 3/8] =?UTF-8?q?test:=20=EC=9D=BC=EA=B8=B0=20=EB=A6=AC?= =?UTF-8?q?=EC=95=A1=EC=85=98=20=EC=A1=B0=ED=9A=8C=20API=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 54 ++++++++++++-------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts index 001e9ee..79f39b5 100644 --- a/backend/test/reactions/reactions.e2e-spec.ts +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -87,24 +87,38 @@ describe('FriendsController (e2e)', () => { await queryRunner.rollbackTransaction(); }); - // describe('/reactions/:diaryId (GET)', () => { - // it('ํŠน์ • ์ผ๊ธฐ์˜ ๋ฆฌ์•ก์…˜ ์กฐํšŒ', async () => { - // // given - // const url = `/reactions/${diary.id}`; - // const friend = await usersRepository.save(friendInfo); - - // await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); - // await reactionsRepository.save({ user: friend, diary, reaction: '๐Ÿฅฐ' }); - - // // when - // const response = await request(app.getHttpServer()) - // .get(url) - // .set('Cookie', [`utk=${accessToken}`]); - - // // then - // expect(response.statusCode).toEqual(200); - // expect(response.body.reactionList).toHaveLength(2); - // expect(response.body.reactionList[0].reaction).toEqual('๐Ÿ”ฅ'); - // }); - // }); + describe('/reactions/:diaryId (GET)', () => { + it('ํŠน์ • ์ผ๊ธฐ์˜ ๋ฆฌ์•ก์…˜ ์กฐํšŒ', async () => { + // given + const url = `/reactions/${diary.id}`; + const friend = await usersRepository.save(friendInfo); + + await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); + await reactionsRepository.save({ user: friend, diary, reaction: '๐Ÿฅฐ' }); + + // when + const response = await request(app.getHttpServer()) + .get(url) + .set('Cookie', [`utk=${accessToken}`]); + + // then + expect(response.statusCode).toEqual(200); + expect(response.body.reactionList).toHaveLength(2); + expect(response.body.reactionList[0].reaction).toEqual('๐Ÿ”ฅ'); + }); + + it('์ผ๊ธฐ์˜ ๋ฆฌ์•ก์…˜ ์—†๋Š” ๊ฒฝ์šฐ ๋นˆ ๋ฐฐ์—ด ๋ฐ˜ํ™˜', async () => { + // given + const url = `/reactions/${diary.id}`; + + // when + const response = await request(app.getHttpServer()) + .get(url) + .set('Cookie', [`utk=${accessToken}`]); + + // then + expect(response.statusCode).toEqual(200); + expect(response.body.reactionList).toEqual([]); + }); + }); }); From 132fe23217986b4990455e61970ee454da013d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Mon, 12 Feb 2024 16:08:13 +0900 Subject: [PATCH 4/8] =?UTF-8?q?test:=20=EB=A6=AC=EC=95=A1=EC=85=98=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts index 79f39b5..32689d7 100644 --- a/backend/test/reactions/reactions.e2e-spec.ts +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -121,4 +121,44 @@ describe('FriendsController (e2e)', () => { expect(response.body.reactionList).toEqual([]); }); }); + + describe('/reactions/:diaryId (POST)', () => { + beforeEach(() => { + jest.spyOn(reactionsRepository, 'save'); + }); + + it('๋ฆฌ์•ก์…˜ ์ €์žฅ', async () => { + // given + const url = `/reactions/${diary.id}`; + + // when + const response = await request(app.getHttpServer()) + .post(url) + .set('Cookie', [`utk=${accessToken}`]) + .send({ reaction: '๐Ÿฅฐ' }); + + // then + expect(response.statusCode).toEqual(201); + expect(reactionsRepository.save).toHaveBeenCalled(); + }); + + it('ํ•ด๋‹น ์ผ๊ธฐ์— ์ด๋ฏธ ๋ฆฌ์•ก์…˜์„ ๋‚จ๊ธด ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ', async () => { + // given + const url = `/reactions/${diary.id}`; + + await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); + jest.clearAllMocks(); + + // when + const response = await request(app.getHttpServer()) + .post(url) + .set('Cookie', [`utk=${accessToken}`]) + .send({ reaction: '๐Ÿฅฐ' }); + + // then + expect(response.statusCode).toEqual(400); + expect(response.body.message).toEqual('์ด๋ฏธ ํ•ด๋‹น ๊ธ€์— ๋ฆฌ์•ก์…˜์„ ๋‚จ๊ฒผ์Šต๋‹ˆ๋‹ค.'); + expect(reactionsRepository.save).toHaveBeenCalledTimes(0); + }); + }); }); From 39f84d2b1ad699a77a3a022245cabc7c1c5e8d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Mon, 12 Feb 2024 16:24:18 +0900 Subject: [PATCH 5/8] =?UTF-8?q?test:=20=EB=A6=AC=EC=95=A1=EC=85=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 48 ++++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts index 32689d7..4a6dce9 100644 --- a/backend/test/reactions/reactions.e2e-spec.ts +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -48,6 +48,7 @@ describe('FriendsController (e2e)', () => { let user: User; let accessToken: string; let diary: Diary; + let url: string; const userInfo = { socialId: '1234', @@ -81,6 +82,7 @@ describe('FriendsController (e2e)', () => { accessToken = await testLogin(user); diaryInfo['author'] = user; diary = await diariesRepository.save(diaryInfo); + url = `/reactions/${diary.id}`; }); afterEach(async () => { @@ -90,7 +92,6 @@ describe('FriendsController (e2e)', () => { describe('/reactions/:diaryId (GET)', () => { it('ํŠน์ • ์ผ๊ธฐ์˜ ๋ฆฌ์•ก์…˜ ์กฐํšŒ', async () => { // given - const url = `/reactions/${diary.id}`; const friend = await usersRepository.save(friendInfo); await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); @@ -108,9 +109,6 @@ describe('FriendsController (e2e)', () => { }); it('์ผ๊ธฐ์˜ ๋ฆฌ์•ก์…˜ ์—†๋Š” ๊ฒฝ์šฐ ๋นˆ ๋ฐฐ์—ด ๋ฐ˜ํ™˜', async () => { - // given - const url = `/reactions/${diary.id}`; - // when const response = await request(app.getHttpServer()) .get(url) @@ -128,9 +126,6 @@ describe('FriendsController (e2e)', () => { }); it('๋ฆฌ์•ก์…˜ ์ €์žฅ', async () => { - // given - const url = `/reactions/${diary.id}`; - // when const response = await request(app.getHttpServer()) .post(url) @@ -144,8 +139,6 @@ describe('FriendsController (e2e)', () => { it('ํ•ด๋‹น ์ผ๊ธฐ์— ์ด๋ฏธ ๋ฆฌ์•ก์…˜์„ ๋‚จ๊ธด ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ', async () => { // given - const url = `/reactions/${diary.id}`; - await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); jest.clearAllMocks(); @@ -161,4 +154,41 @@ describe('FriendsController (e2e)', () => { expect(reactionsRepository.save).toHaveBeenCalledTimes(0); }); }); + + describe('/reactions/:diaryId (PUT)', () => { + beforeEach(() => { + jest.spyOn(reactionsRepository, 'save'); + }); + + it('๋ฆฌ์•ก์…˜ ์ˆ˜์ •', async () => { + // given + await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); + + // when + const response = await request(app.getHttpServer()) + .put(url) + .set('Cookie', [`utk=${accessToken}`]) + .send({ reaction: '๐Ÿฅฐ' }); + + // then + expect(response.statusCode).toEqual(200); + expect(reactionsRepository.save).toHaveBeenCalledTimes(2); + }); + + it('๋ฆฌ์•ก์…˜์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋ฐ ํ•ด๋‹น ์š”์ฒญ์„ ๋ณด๋‚ธ ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ', async () => { + // given + jest.clearAllMocks(); + + // when + const response = await request(app.getHttpServer()) + .put(url) + .set('Cookie', [`utk=${accessToken}`]) + .send({ reaction: '๐Ÿฅฐ' }); + + // then + expect(response.statusCode).toEqual(400); + expect(response.body.message).toEqual('๋ฆฌ์•ก์…˜ ๊ธฐ๋ก์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.'); + expect(reactionsRepository.save).toHaveBeenCalledTimes(0); + }); + }); }); From 7f1789eef40e938cdae18737726218105528e6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Mon, 12 Feb 2024 16:37:57 +0900 Subject: [PATCH 6/8] =?UTF-8?q?test:=20=EB=A6=AC=EC=95=A1=EC=85=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 62 +++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts index 4a6dce9..61b62b2 100644 --- a/backend/test/reactions/reactions.e2e-spec.ts +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -39,6 +39,9 @@ describe('FriendsController (e2e)', () => { app = module.createNestApplication(); app.use(cookieParser()); await app.init(); + + jest.spyOn(reactionsRepository, 'save'); + jest.spyOn(reactionsRepository, 'remove'); }); afterAll(async () => { @@ -121,10 +124,6 @@ describe('FriendsController (e2e)', () => { }); describe('/reactions/:diaryId (POST)', () => { - beforeEach(() => { - jest.spyOn(reactionsRepository, 'save'); - }); - it('๋ฆฌ์•ก์…˜ ์ €์žฅ', async () => { // when const response = await request(app.getHttpServer()) @@ -157,7 +156,7 @@ describe('FriendsController (e2e)', () => { describe('/reactions/:diaryId (PUT)', () => { beforeEach(() => { - jest.spyOn(reactionsRepository, 'save'); + jest.clearAllMocks(); }); it('๋ฆฌ์•ก์…˜ ์ˆ˜์ •', async () => { @@ -176,9 +175,6 @@ describe('FriendsController (e2e)', () => { }); it('๋ฆฌ์•ก์…˜์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋ฐ ํ•ด๋‹น ์š”์ฒญ์„ ๋ณด๋‚ธ ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ', async () => { - // given - jest.clearAllMocks(); - // when const response = await request(app.getHttpServer()) .put(url) @@ -191,4 +187,54 @@ describe('FriendsController (e2e)', () => { expect(reactionsRepository.save).toHaveBeenCalledTimes(0); }); }); + + describe('/reactions/:diaryId (DELETE)', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('๋ฆฌ์•ก์…˜ ์‚ญ์ œ', async () => { + // given + await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); + + // when + const response = await request(app.getHttpServer()) + .delete(url) + .set('Cookie', [`utk=${accessToken}`]) + .send({ reaction: '๐Ÿ”ฅ' }); + + // then + expect(response.statusCode).toEqual(200); + expect(reactionsRepository.remove).toHaveBeenCalled(); + }); + + it('์‚ญ์ œํ•˜๋ ค๋Š” ๋ฆฌ์•ก์…˜์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ', async () => { + // when + const response = await request(app.getHttpServer()) + .delete(url) + .set('Cookie', [`utk=${accessToken}`]) + .send({ reaction: '๐Ÿ”ฅ' }); + + // then + expect(response.statusCode).toEqual(400); + expect(response.body.message).toEqual('์ด๋ฏธ ์‚ญ์ œ๋œ ๋ฆฌ์•ก์…˜ ์ •๋ณด์ž…๋‹ˆ๋‹ค.'); + expect(reactionsRepository.remove).toHaveBeenCalledTimes(0); + }); + + it('๊ธฐ์กด์— ๋‚จ๊ธด ๋ฆฌ์•ก์…˜๊ณผ ์‚ญ์ œํ•˜๋ ค๋Š” ๋ฆฌ์•ก์…˜์ด ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ', async () => { + // given + await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); + + // when + const response = await request(app.getHttpServer()) + .delete(url) + .set('Cookie', [`utk=${accessToken}`]) + .send({ reaction: '๐Ÿฅฐ' }); + + // then + expect(response.statusCode).toEqual(400); + expect(response.body.message).toEqual('์ด๋ฏธ ์‚ญ์ œ๋œ ๋ฆฌ์•ก์…˜ ์ •๋ณด์ž…๋‹ˆ๋‹ค.'); + expect(reactionsRepository.remove).toHaveBeenCalledTimes(0); + }); + }); }); From 96176d5cecb74cf7c7fad87fed643bccee6b0a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Mon, 12 Feb 2024 16:44:29 +0900 Subject: [PATCH 7/8] =?UTF-8?q?chore:=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts index 61b62b2..41676b1 100644 --- a/backend/test/reactions/reactions.e2e-spec.ts +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -14,7 +14,7 @@ import * as cookieParser from 'cookie-parser'; import { User } from 'src/users/entity/user.entity'; import { testLogin } from 'test/utils/testLogin'; -describe('FriendsController (e2e)', () => { +describe('ReactionsController (e2e)', () => { let app: INestApplication; let queryRunner: QueryRunner; let reactionsRepository: ReactionsRepository; @@ -60,13 +60,6 @@ describe('FriendsController (e2e)', () => { email: 'test@abc.com', profileImage: 'profile image', }; - const friendInfo = { - socialId: '12345', - socialType: SocialType.NAVER, - nickname: 'friend', - email: 'friend@abc.com', - profileImage: 'profile image', - }; const diaryInfo = { title: '์ œ๋ชฉ', content: '

๋‚ด์šฉ

', @@ -95,6 +88,13 @@ describe('FriendsController (e2e)', () => { describe('/reactions/:diaryId (GET)', () => { it('ํŠน์ • ์ผ๊ธฐ์˜ ๋ฆฌ์•ก์…˜ ์กฐํšŒ', async () => { // given + const friendInfo = { + socialId: '12345', + socialType: SocialType.NAVER, + nickname: 'friend', + email: 'friend@abc.com', + profileImage: 'profile image', + }; const friend = await usersRepository.save(friendInfo); await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); From 60358445dfa5c93e100dac50d5260fc64bc0af55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=88=98=ED=98=84?= Date: Tue, 13 Feb 2024 13:51:05 +0900 Subject: [PATCH 8/8] =?UTF-8?q?test:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20#382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/reactions/reactions.e2e-spec.ts | 67 +++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/backend/test/reactions/reactions.e2e-spec.ts b/backend/test/reactions/reactions.e2e-spec.ts index 41676b1..08e6df0 100644 --- a/backend/test/reactions/reactions.e2e-spec.ts +++ b/backend/test/reactions/reactions.e2e-spec.ts @@ -21,6 +21,11 @@ describe('ReactionsController (e2e)', () => { let diariesRepository: DiariesRepository; let usersRepository: UsersRepository; + let user: User; + let accessToken: string; + let diary: Diary; + let url: string; + beforeAll(async () => { const module = await Test.createTestingModule({ imports: [AppModule], @@ -42,43 +47,40 @@ describe('ReactionsController (e2e)', () => { jest.spyOn(reactionsRepository, 'save'); jest.spyOn(reactionsRepository, 'remove'); + + const userInfo = { + socialId: '1234', + socialType: SocialType.NAVER, + nickname: 'test', + email: 'test@abc.com', + profileImage: 'profile image', + }; + + user = await usersRepository.save(userInfo); + accessToken = await testLogin(user); + + const diaryInfo = { + author: user, + title: '์ œ๋ชฉ', + content: '

๋‚ด์šฉ

', + thumbnail: null, + emotion: '๐Ÿฅฐ', + tagNames: ['์ผ๊ธฐ', '์•ˆ๋…•'], + status: DiaryStatus.PUBLIC, + summary: '์ผ๊ธฐ ์š”์•ฝ', + mood: MoodDegree.SO_SO, + }; + + diary = await diariesRepository.save(diaryInfo); + url = `/reactions/${diary.id}`; }); afterAll(async () => { await app.close(); }); - let user: User; - let accessToken: string; - let diary: Diary; - let url: string; - - const userInfo = { - socialId: '1234', - socialType: SocialType.NAVER, - nickname: 'test', - email: 'test@abc.com', - profileImage: 'profile image', - }; - const diaryInfo = { - title: '์ œ๋ชฉ', - content: '

๋‚ด์šฉ

', - thumbnail: null, - emotion: '๐Ÿฅฐ', - tagNames: ['์ผ๊ธฐ', '์•ˆ๋…•'], - status: DiaryStatus.PUBLIC, - summary: '์ผ๊ธฐ ์š”์•ฝ', - mood: MoodDegree.SO_SO, - }; - beforeEach(async () => { await queryRunner.startTransaction(); - - user = await usersRepository.save(userInfo); - accessToken = await testLogin(user); - diaryInfo['author'] = user; - diary = await diariesRepository.save(diaryInfo); - url = `/reactions/${diary.id}`; }); afterEach(async () => { @@ -124,6 +126,10 @@ describe('ReactionsController (e2e)', () => { }); describe('/reactions/:diaryId (POST)', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + it('๋ฆฌ์•ก์…˜ ์ €์žฅ', async () => { // when const response = await request(app.getHttpServer()) @@ -139,7 +145,6 @@ describe('ReactionsController (e2e)', () => { it('ํ•ด๋‹น ์ผ๊ธฐ์— ์ด๋ฏธ ๋ฆฌ์•ก์…˜์„ ๋‚จ๊ธด ๊ฒฝ์šฐ ์˜ˆ์™ธ ๋ฐœ์ƒ', async () => { // given await reactionsRepository.save({ user, diary, reaction: '๐Ÿ”ฅ' }); - jest.clearAllMocks(); // when const response = await request(app.getHttpServer()) @@ -150,7 +155,7 @@ describe('ReactionsController (e2e)', () => { // then expect(response.statusCode).toEqual(400); expect(response.body.message).toEqual('์ด๋ฏธ ํ•ด๋‹น ๊ธ€์— ๋ฆฌ์•ก์…˜์„ ๋‚จ๊ฒผ์Šต๋‹ˆ๋‹ค.'); - expect(reactionsRepository.save).toHaveBeenCalledTimes(0); + expect(reactionsRepository.save).toHaveBeenCalledTimes(1); }); });