-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from skgndi12/feature/issue-164/implement-cre…
…ate-reply-service-method [#164] Implement create reply service method
- Loading branch information
Showing
3 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,15 @@ import { DeepMockProxy, mockClear, mockDeep } from 'jest-mock-extended'; | |
import extendedPrisma from '@root/test/infrastructure/prisma/test.prisma.client'; | ||
|
||
import { AppIdToken } from '@src/core/entities/auth.entity'; | ||
import { Review } from '@src/core/entities/review.entity'; | ||
import { Reply, Review } from '@src/core/entities/review.entity'; | ||
import { User } from '@src/core/entities/user.entity'; | ||
import { ReplyRepository } from '@src/core/ports/reply.repository'; | ||
import { ReviewRepository } from '@src/core/ports/review.repository'; | ||
import { TransactionManager } from '@src/core/ports/transaction.manager'; | ||
import { UserRepository } from '@src/core/ports/user.repository'; | ||
import { ReviewService } from '@src/core/services/review/review.service'; | ||
import { | ||
CreateReplyDto, | ||
CreateReviewDto, | ||
DeleteReviewDto, | ||
GetReviewsDto, | ||
|
@@ -722,4 +723,96 @@ describe('Test review service', () => { | |
expect(reviewRepository.deleteById).toBeCalledTimes(0); | ||
}); | ||
}); | ||
|
||
describe('Test create reply', () => { | ||
const userId = 'randomId'; | ||
const nickname = 'randomNickname'; | ||
const tag = '#TAGG'; | ||
const idp = new IdpEnum(Idp.GOOGLE); | ||
const email = '[email protected]'; | ||
const accessLevel = new AccessLevelEnum(AccessLevel.USER); | ||
const reviewId = 0; | ||
const replyId = 1; | ||
const content = 'randomContent'; | ||
const currentDate = new Date(); | ||
const requesterIdToken = new AppIdToken( | ||
userId, | ||
nickname, | ||
tag, | ||
idp, | ||
email, | ||
accessLevel | ||
); | ||
|
||
const userFound = new User( | ||
userId, | ||
nickname, | ||
tag, | ||
idp, | ||
email, | ||
accessLevel, | ||
currentDate, | ||
currentDate | ||
); | ||
const replyCreated = new Reply( | ||
replyId, | ||
reviewId, | ||
requesterIdToken.userId, | ||
content, | ||
currentDate, | ||
currentDate | ||
); | ||
|
||
const userFindById = jest.fn(() => Promise.resolve(userFound)) as jest.Mock; | ||
const replyCreate = jest.fn(() => | ||
Promise.resolve(replyCreated) | ||
) as jest.Mock; | ||
|
||
beforeAll(() => { | ||
prismaMock.$transaction.mockImplementation((callback) => | ||
callback(prismaMock) | ||
); | ||
userRepository = new PostgresqlUserRepository(prismaMock); | ||
reviewRepository = new PostgresqlReviewRepository(prismaMock); | ||
replyRepository = new PostgresqlReplyRepository(prismaMock); | ||
txManager = new PrismaTransactionManager(prismaMock); | ||
userRepository.findById = userFindById; | ||
replyRepository.create = replyCreate; | ||
}); | ||
|
||
it('should success when valid', async () => { | ||
const givenDto: CreateReplyDto = { | ||
requesterIdToken, | ||
reviewId, | ||
content | ||
}; | ||
const actualResult = await new ReviewService( | ||
userRepository, | ||
reviewRepository, | ||
replyRepository, | ||
txManager | ||
).createReply(givenDto); | ||
|
||
expect(JSON.stringify(actualResult.user)).toEqual( | ||
JSON.stringify(userFound) | ||
); | ||
expect(JSON.stringify(actualResult.reply)).toEqual( | ||
JSON.stringify(replyCreated) | ||
); | ||
|
||
expect(userRepository.findById).toBeCalledTimes(1); | ||
const userFindByIdArgs = userFindById.mock.calls[0][0]; | ||
expect(userFindByIdArgs).toEqual(givenDto.requesterIdToken.userId); | ||
|
||
expect(replyRepository.create).toBeCalledTimes(1); | ||
const replyCreateArgs = replyCreate.mock.calls[0][0]; | ||
expect(replyCreateArgs).toEqual( | ||
expect.objectContaining({ | ||
reviewId: givenDto.reviewId, | ||
userId: givenDto.requesterIdToken.userId, | ||
content: givenDto.content | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |