File tree Expand file tree Collapse file tree 4 files changed +57
-10
lines changed Expand file tree Collapse file tree 4 files changed +57
-10
lines changed Original file line number Diff line number Diff line change 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 { } ;
Original file line number Diff line number Diff line change 11import CustomError from '.' ;
22import { 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 ;
Original file line number Diff line number Diff line change 11import { 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 ;
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ module.exports = {
22 preset : 'ts-jest' , // to use typescript
33 verbose : true ,
44 moduleNameMapper : {
5- "@apis/(.*)" : "<rootDir>/apis/$1" ,
6- "@config" : "<rootDir>/config" ,
7- "@constants/(.*)" : "<rootDir>/constants/$1" ,
8- "@db" : "<rootDir>/db" ,
9- "@middlewares/(.*)" : "<rootDir>/middlewares/$1" ,
10- "@utils/(.*)" : "<rootDir>/utils/$1"
11- }
12- }
5+ '@apis/(.*)' : '<rootDir>/apis/$1' ,
6+ '@config' : '<rootDir>/config' ,
7+ '@constants/(.*)' : '<rootDir>/constants/$1' ,
8+ '@db' : '<rootDir>/db' ,
9+ '@middlewares/(.*)' : '<rootDir>/middlewares/$1' ,
10+ '@utils/(.*)' : '<rootDir>/utils/$1' ,
11+ '@errors/(.*)' : '<rootDir>/errors/$1' ,
12+ } ,
13+ } ;
You can’t perform that action at this time.
0 commit comments