Skip to content

Commit

Permalink
refactor: mock 방식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Conut-1 committed Oct 17, 2024
1 parent a434434 commit 06c9f82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
22 changes: 10 additions & 12 deletions nestjs-BE/server/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('AuthController', () => {
access_token: 'access token',
};

jest.spyOn(authService, 'kakaoLogin').mockResolvedValue(tokenMock);
(authService.kakaoLogin as jest.Mock).mockResolvedValue(tokenMock);

const response = controller.kakaoLogin(requestMock);

Expand All @@ -49,9 +49,9 @@ describe('AuthController', () => {
});

it('kakao login fail', async () => {
jest
.spyOn(authService, 'kakaoLogin')
.mockRejectedValue(new NotFoundException());
(authService.kakaoLogin as jest.Mock).mockRejectedValue(
new NotFoundException(),
);

const response = controller.kakaoLogin(requestMock);

Expand All @@ -63,9 +63,9 @@ describe('AuthController', () => {
const requestMock = { refreshToken: 'refresh token' };

it('respond new access token', async () => {
jest
.spyOn(authService, 'renewAccessToken')
.mockResolvedValue('new access token');
(authService.renewAccessToken as jest.Mock).mockResolvedValue(
'new access token',
);

const response = controller.renewAccessToken(requestMock);

Expand All @@ -77,9 +77,9 @@ describe('AuthController', () => {
});

it('received expired token', async () => {
jest
.spyOn(authService, 'renewAccessToken')
.mockRejectedValue(new Error());
(authService.renewAccessToken as jest.Mock).mockRejectedValue(
new Error(),
);

const response = controller.renewAccessToken(requestMock);

Expand All @@ -91,8 +91,6 @@ describe('AuthController', () => {
it('received token deleted', async () => {
const requestMock = { refreshToken: 'refresh token' };

jest.spyOn(authService, 'logout');

const response = controller.logout(requestMock);

await expect(response).resolves.toEqual({
Expand Down
14 changes: 7 additions & 7 deletions nestjs-BE/server/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ describe('AuthService', () => {

describe('login', () => {
it('success', async () => {
jest.spyOn(jwtService, 'signAsync').mockResolvedValue('access token');
jest.spyOn(refreshTokensService, 'createRefreshToken').mockResolvedValue({
(jwtService.signAsync as jest.Mock).mockResolvedValue('access token');
(refreshTokensService.createRefreshToken as jest.Mock).mockResolvedValue({
token: 'refresh token',
} as unknown as RefreshToken);
} as RefreshToken);

const tokens = service.login('user uuid');

Expand All @@ -99,9 +99,9 @@ describe('AuthService', () => {

describe('renewAccessToken', () => {
it('success', async () => {
jest.spyOn(jwtService, 'verify').mockReturnValue({});
jest.spyOn(jwtService, 'signAsync').mockResolvedValue('access token');
jest.spyOn(refreshTokensService, 'findRefreshToken').mockResolvedValue({
(jwtService.verify as jest.Mock).mockReturnValue({});
(jwtService.signAsync as jest.Mock).mockResolvedValue('access token');
(refreshTokensService.findRefreshToken as jest.Mock).mockResolvedValue({
userUuid: 'user uuid',
} as RefreshToken);

Expand All @@ -111,7 +111,7 @@ describe('AuthService', () => {
});

it('fail', async () => {
jest.spyOn(jwtService, 'verify').mockImplementation(() => {
(jwtService.verify as jest.Mock).mockImplementation(() => {
throw new Error();
});

Expand Down

0 comments on commit 06c9f82

Please sign in to comment.