@@ -26,16 +26,17 @@ const eventResolvers = require('../../src/resolvers/event') as {
2626} ;
2727
2828const bulkUpdateAssignee = jest . fn ( ) ;
29+ const ASSIGNEE_ID = '507f1f77bcf86cd799439012' ;
2930
3031describe ( 'EventsMutations.bulkUpdateAssignee' , ( ) => {
3132 const ctx = {
3233 user : { id : 'u1' } ,
3334 factories : {
3435 usersFactory : {
35- findById : jest . fn ( ) . mockResolvedValue ( { id : 'assignee-1' } ) ,
36+ findById : jest . fn ( ) . mockResolvedValue ( { id : ASSIGNEE_ID } ) ,
3637 dataLoaders : {
3738 userById : {
38- load : jest . fn ( ) . mockResolvedValue ( { id : 'assignee-1' , email : 'a@a.a' } ) ,
39+ load : jest . fn ( ) . mockResolvedValue ( { id : ASSIGNEE_ID , email : 'a@a.a' } ) ,
3940 } ,
4041 } ,
4142 } ,
@@ -44,7 +45,7 @@ describe('EventsMutations.bulkUpdateAssignee', () => {
4445 } ,
4546 workspacesFactory : {
4647 findById : jest . fn ( ) . mockResolvedValue ( {
47- getMemberInfo : jest . fn ( ) . mockResolvedValue ( { userId : 'assignee-1' } ) ,
48+ getMemberInfo : jest . fn ( ) . mockResolvedValue ( { userId : ASSIGNEE_ID } ) ,
4849 } ) ,
4950 } ,
5051 } ,
@@ -66,21 +67,39 @@ describe('EventsMutations.bulkUpdateAssignee', () => {
6667 await expect (
6768 eventResolvers . EventsMutations . bulkUpdateAssignee (
6869 { } ,
69- { input : { projectId : 'p1' , eventIds : [ ] , assignee : 'assignee-1' } } ,
70+ { input : { projectId : 'p1' , eventIds : [ ] , assignee : ASSIGNEE_ID } } ,
7071 ctx
7172 )
7273 ) . rejects . toThrow ( UserInputError ) ;
7374 expect ( bulkUpdateAssignee ) . not . toHaveBeenCalled ( ) ;
7475 } ) ;
7576
77+ it ( 'should throw when assignee id is invalid' , async ( ) => {
78+ await expect (
79+ eventResolvers . EventsMutations . bulkUpdateAssignee (
80+ { } ,
81+ {
82+ input : {
83+ projectId : 'p1' ,
84+ eventIds : [ '507f1f77bcf86cd799439011' ] ,
85+ assignee : 'not-an-object-id' ,
86+ } ,
87+ } ,
88+ ctx
89+ )
90+ ) . rejects . toThrow ( UserInputError ) ;
91+
92+ expect ( bulkUpdateAssignee ) . not . toHaveBeenCalled ( ) ;
93+ } ) ;
94+
7695 it ( 'should call factory for bulk assign' , async ( ) => {
7796 const result = await eventResolvers . EventsMutations . bulkUpdateAssignee (
7897 { } ,
7998 {
8099 input : {
81100 projectId : 'p1' ,
82101 eventIds : [ '507f1f77bcf86cd799439011' ] ,
83- assignee : 'assignee-1' ,
102+ assignee : ASSIGNEE_ID ,
84103 } ,
85104 } ,
86105 ctx
@@ -89,15 +108,15 @@ describe('EventsMutations.bulkUpdateAssignee', () => {
89108 expect ( result . updatedCount ) . toBe ( 1 ) ;
90109 expect ( bulkUpdateAssignee ) . toHaveBeenCalledWith (
91110 [ '507f1f77bcf86cd799439011' ] ,
92- 'assignee-1'
111+ ASSIGNEE_ID
93112 ) ;
94113 expect ( sendPersonalNotification ) . toHaveBeenCalledTimes ( 1 ) ;
95114 expect ( sendPersonalNotification ) . toHaveBeenCalledWith (
96- expect . objectContaining ( { id : 'assignee-1' } ) ,
115+ expect . objectContaining ( { id : ASSIGNEE_ID } ) ,
97116 expect . objectContaining ( {
98117 type : 'assignee' ,
99118 payload : expect . objectContaining ( {
100- assigneeId : 'assignee-1' ,
119+ assigneeId : ASSIGNEE_ID ,
101120 projectId : 'p1' ,
102121 whoAssignedId : 'u1' ,
103122 eventId : '507f1f77bcf86cd799439011' ,
@@ -119,15 +138,15 @@ describe('EventsMutations.bulkUpdateAssignee', () => {
119138 input : {
120139 projectId : 'p1' ,
121140 eventIds : [ '507f1f77bcf86cd799439011' , 'invalid-id' ] ,
122- assignee : 'assignee-1' ,
141+ assignee : ASSIGNEE_ID ,
123142 } ,
124143 } ,
125144 ctx
126145 ) ;
127146
128147 expect ( bulkUpdateAssignee ) . toHaveBeenCalledWith (
129148 [ '507f1f77bcf86cd799439011' ] ,
130- 'assignee-1'
149+ ASSIGNEE_ID
131150 ) ;
132151 expect ( result ) . toEqual ( {
133152 updatedCount : 1 ,
@@ -143,7 +162,7 @@ describe('EventsMutations.bulkUpdateAssignee', () => {
143162 input : {
144163 projectId : 'p1' ,
145164 eventIds : [ 'bad-1' , 'bad-2' ] ,
146- assignee : 'assignee-1' ,
165+ assignee : ASSIGNEE_ID ,
147166 } ,
148167 } ,
149168 ctx
0 commit comments