File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 1- const userModel = require ( '@apis/user/model' ) ;
21const workspaceModel = require ( './model' ) ;
32const workspaceService = require ( './service' ) ;
43const { default : InvalidJoinError } = require ( '@errors/invalid-join-error' ) ;
@@ -69,7 +68,8 @@ describe('join', () => {
6968 users : [ ] ,
7069 moms : [ ] ,
7170 } ) ;
72- userModel . find . mockResolvedValueOnce ( [ { workspaces : [ ] } ] ) ;
71+
72+ workspaceModel . updateOne . mockResolvedValueOnce ( { modifiedCount : 1 } ) ;
7373
7474 expect ( workspaceService . join ( USER_ID , VALID_CODE ) ) . resolves . toEqual ( {
7575 id : WORKSPACE_ID ,
@@ -100,7 +100,8 @@ describe('join', () => {
100100 users : [ ] ,
101101 moms : [ ] ,
102102 } ) ;
103- userModel . find . mockResolvedValueOnce ( [ { workspaces : [ WORKSPACE_ID ] } ] ) ;
103+
104+ workspaceModel . updateOne . mockResolvedValueOnce ( { modifiedCount : 0 } ) ;
104105
105106 expect ( ( ) => workspaceService . join ( USER_ID , VALID_CODE ) ) . rejects . toThrow (
106107 InvalidJoinError ,
Original file line number Diff line number Diff line change @@ -27,15 +27,15 @@ export const join = async (userId: number, code: string) => {
2727
2828 const { id, name } = workspace ;
2929
30- const userWorkspaces = (
31- await userModel . find ( { id : userId } , { workspaces : 1 , _id : 0 } )
32- ) [ 0 ] . workspaces ;
30+ const res = await workspaceModel . updateOne (
31+ { id } ,
32+ { $addToSet : { users : userId } } ,
33+ ) ;
3334
34- if ( userWorkspaces . includes ( id ) ) {
35+ if ( ! res . modifiedCount ) {
3536 throw new InvalidJoinError ( '이미 참여한 워크스페이스에요 ^^' ) ;
3637 }
3738
38- await workspaceModel . updateOne ( { id } , { $addToSet : { users : userId } } ) ;
3939 await userModel . updateOne ( { id : userId } , { $addToSet : { workspaces : id } } ) ;
4040
4141 return { id, name, code } ;
You can’t perform that action at this time.
0 commit comments