Skip to content

Commit ab19ac5

Browse files
se030wcho21dohun31juyeong-s
committed
refactor: api 서비스 테스트 코드 리팩토링
Co-authored-by: Won-hee Cho <[email protected]> Co-authored-by: 백도훈 <[email protected]> Co-authored-by: Ruby <[email protected]>
1 parent 7920a40 commit ab19ac5

File tree

6 files changed

+14
-36
lines changed

6 files changed

+14
-36
lines changed

server/apis/auth/service.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ describe('login', () => {
6565
expect(() => login()).rejects.toThrow('fail');
6666
});
6767
});
68+
69+
export {};

server/apis/user/service.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,23 @@ jest.mock('@apis/workspace/model', () => {
1111
return { find: jest.fn() };
1212
});
1313

14-
describe('getWorkspaces()', () => {
14+
describe('getWorkspaces', () => {
1515
const successfulUser = '';
1616
const successfulWorkspaces: Object[] = [];
1717

1818
it('정상적인 유저 아이디를 받아서 성공적으로 워크스페이스를 가져온다.', async () => {
19-
// arrange
2019
userModel.findOne.mockResolvedValueOnce(successfulUser);
2120
workspaceModel.find.mockResolvedValueOnce(successfulWorkspaces);
2221

23-
// act
2422
const workspaces = await getWorkspaces('id', 'id');
2523

26-
// assert
2724
expect(workspaces).toEqual(successfulWorkspaces);
2825
});
2926

3027
it('비정상적인 유저 아이디를 받으면 에러를 던진다.', async () => {
31-
// arrange
3228
const user1 = 1;
3329
const user2 = 2;
3430

35-
// act & assert
3631
expect(() => getWorkspaces(user1, user2)).rejects.toThrow(
3732
AuthorizationError,
3833
);

server/apis/workspace/service.test.js renamed to server/apis/workspace/service.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
const workspaceModel = require('./model');
2+
const workspaceService = require('./service');
3+
const { default: InvalidJoinError } = require('@errors/invalid-join-error');
4+
15
jest.mock('./model', () => {
26
return {
3-
repository: {},
47
create: jest.fn(),
58
findOne: jest.fn(),
69
updateOne: jest.fn(),
710
};
811
});
9-
const workspaceModel = require('./model');
1012

1113
jest.mock('@apis/user/model', () => {
1214
return {
1315
updateOne: jest.fn(),
1416
};
1517
});
16-
const userModel = require('@apis/user/model');
1718

1819
const VALID_CODE = 'wab-0000-0000-0000';
1920

@@ -23,8 +24,6 @@ jest.mock('uuid', () => {
2324
};
2425
});
2526

26-
const workspaceService = require('./service');
27-
2827
describe('create', () => {
2928
it('워크스페이스 이름이 주어진 경우 생성에 성공한다.', async () => {
3029
const WORKSPACE_NAME = 'Wab';
@@ -71,7 +70,7 @@ describe('join', () => {
7170

7271
it('참여코드가 없는 경우 실패한다.', async () => {
7372
expect(() => workspaceService.join(USER_ID)).rejects.toThrow(
74-
'참여코드를 입력하세요 ^^',
73+
InvalidJoinError,
7574
);
7675
});
7776

@@ -80,7 +79,7 @@ describe('join', () => {
8079

8180
expect(() =>
8281
workspaceService.join(USER_ID, 'invalid-code'),
83-
).rejects.toThrow('잘못된 참여코드에요 ^^');
82+
).rejects.toThrow(InvalidJoinError);
8483
});
8584

8685
it('db 업데이트 중 에러가 발생하면 실패한다.', async () => {
@@ -91,3 +90,5 @@ describe('join', () => {
9190
expect(() => workspaceService.join(USER_ID, VALID_CODE)).rejects.toThrow();
9291
});
9392
});
93+
94+
export {};
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import CustomError from '.';
22
import { BAD_REQUEST } from '@constants/http-status';
33

4-
export default class InvalidJoinError extends CustomError {
4+
class InvalidJoinError extends CustomError {
55
constructor(message = 'Unauthorized') {
66
super(message, BAD_REQUEST);
77
}
88
}
9+
10+
export default InvalidJoinError;

server/exceptions/authorization-error.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

server/exceptions/index.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)