11const workspaceModel = require ( './model' ) ;
22const workspaceService = require ( './service' ) ;
33const { default : InvalidJoinError } = require ( '@errors/invalid-join-error' ) ;
4+ const {
5+ default : InvalidWorkspaceError ,
6+ } = require ( '@errors/invalid-workspace-error' ) ;
47
58jest . mock ( './model' , ( ) => {
69 return {
@@ -12,10 +15,15 @@ jest.mock('./model', () => {
1215
1316jest . mock ( '@apis/user/model' , ( ) => {
1417 return {
18+ find : jest . fn ( ) ,
1519 updateOne : jest . fn ( ) ,
1620 } ;
1721} ) ;
1822
23+ jest . mock ( '@apis/mom/model' , ( ) => {
24+ return { find : jest . fn ( ) } ;
25+ } ) ;
26+
1927const VALID_CODE = 'wab-0000-0000-0000' ;
2028
2129jest . mock ( 'uuid' , ( ) => {
@@ -91,4 +99,49 @@ describe('join', () => {
9199 } ) ;
92100} ) ;
93101
102+ describe ( 'info' , ( ) => {
103+ const WORKSPACE_ID = 1 ;
104+ const INVALID_WORKSPACE_ID = - 1 ;
105+
106+ it ( '์ํฌ์คํ์ด์ค ID๊ฐ DB์ ์กด์ฌํ ๊ฒฝ์ฐ ์กฐํ์ ์ฑ๊ณตํ๋ค.' , async ( ) => {
107+ const WORKSPACE_NAME = 'Wab' ;
108+
109+ workspaceModel . findOne . mockResolvedValueOnce ( {
110+ id : WORKSPACE_ID ,
111+ name : WORKSPACE_NAME ,
112+ code : VALID_CODE ,
113+ users : [ ] ,
114+ moms : [ ] ,
115+ } ) ;
116+
117+ expect ( workspaceService . info ( WORKSPACE_ID ) ) . resolves . toEqual ( {
118+ name : WORKSPACE_NAME ,
119+ users : [ ] ,
120+ moms : [ ] ,
121+ } ) ;
122+ } ) ;
123+
124+ it ( '์ํฌ์คํ์ด์ค Id๊ฐ ์๋ ๊ฒฝ์ฐ ์คํจํ๋ค.' , async ( ) => {
125+ expect ( ( ) => workspaceService . info ( ) ) . rejects . toThrow (
126+ InvalidWorkspaceError ,
127+ ) ;
128+ } ) ;
129+
130+ it ( '์ํฌ์คํ์ด์ค Id๊ฐ DB์ ์กด์ฌํ์ง ์๋ ๊ฒฝ์ฐ ์คํจํ๋ค.' , async ( ) => {
131+ workspaceModel . findOne . mockResolvedValueOnce ( null ) ;
132+
133+ expect ( ( ) => workspaceService . info ( INVALID_WORKSPACE_ID ) ) . rejects . toThrow (
134+ InvalidWorkspaceError ,
135+ ) ;
136+ } ) ;
137+
138+ it ( '์ํฌ์คํ์ด์ค ์ ๋ณด ํ๋ ์คํจ ์ ์๋ฌ๋ฅผ ๋์ง๋ค.' , async ( ) => {
139+ workspaceModel . findOne . mockRejectedValueOnce (
140+ new Error ( 'Some error in database operation' ) ,
141+ ) ;
142+
143+ expect ( ( ) => workspaceService . info ( WORKSPACE_ID ) ) . rejects . toThrow ( ) ;
144+ } ) ;
145+ } ) ;
146+
94147export { } ;
0 commit comments