Skip to content

Commit 7920a40

Browse files
committed
Merge branch 'dev' of https://github.com/boostcampwm-2022/web27-Wabinar into test/#24-K
2 parents f7f8f8f + 77d11b7 commit 7920a40

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

server/apis/user/service.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const { getWorkspaces } = require('./service');
2+
const userModel = require('@apis/user/model');
3+
const workspaceModel = require('@apis/workspace/model');
4+
const { default: AuthorizationError } = require('@errors/authorization-error');
5+
6+
jest.mock('@apis/user/model', () => {
7+
return { findOne: jest.fn() };
8+
});
9+
10+
jest.mock('@apis/workspace/model', () => {
11+
return { find: jest.fn() };
12+
});
13+
14+
describe('getWorkspaces()', () => {
15+
const successfulUser = '';
16+
const successfulWorkspaces: Object[] = [];
17+
18+
it('정상적인 유저 아이디를 받아서 성공적으로 워크스페이스를 가져온다.', async () => {
19+
// arrange
20+
userModel.findOne.mockResolvedValueOnce(successfulUser);
21+
workspaceModel.find.mockResolvedValueOnce(successfulWorkspaces);
22+
23+
// act
24+
const workspaces = await getWorkspaces('id', 'id');
25+
26+
// assert
27+
expect(workspaces).toEqual(successfulWorkspaces);
28+
});
29+
30+
it('비정상적인 유저 아이디를 받으면 에러를 던진다.', async () => {
31+
// arrange
32+
const user1 = 1;
33+
const user2 = 2;
34+
35+
// act & assert
36+
expect(() => getWorkspaces(user1, user2)).rejects.toThrow(
37+
AuthorizationError,
38+
);
39+
});
40+
});
41+
42+
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 { UNAUTHORIZED } from '@constants/http-status';
33

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

server/errors/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { INTERNAL_SERVER_ERROR } from '@constants/http-status';
22

3-
export default class CustomError extends Error {
3+
class CustomError extends Error {
44
message!: string;
55
status!: number;
66

@@ -14,3 +14,5 @@ export default class CustomError extends Error {
1414
this.status = status;
1515
}
1616
}
17+
18+
export default CustomError;

server/jest.config.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ module.exports = {
88
'@db': '<rootDir>/db',
99
'@middlewares/(.*)': '<rootDir>/middlewares/$1',
1010
'@utils/(.*)': '<rootDir>/utils/$1',
11-
},
12-
};
13-
module.exports = {
14-
preset: 'ts-jest', // to use typescript
15-
verbose: true,
16-
moduleNameMapper: {
17-
'@apis/(.*)': '<rootDir>/apis/$1',
18-
'@config': '<rootDir>/config',
19-
'@constants/(.*)': '<rootDir>/constants/$1',
20-
'@db': '<rootDir>/db',
21-
'@errors': '<rootDir>/errors',
22-
'@middlewares/(.*)': '<rootDir>/middlewares/$1',
23-
'@utils/(.*)': '<rootDir>/utils/$1',
11+
'@errors/(.*)': '<rootDir>/errors/$1',
2412
},
2513
};

0 commit comments

Comments
 (0)