@@ -49,11 +49,43 @@ describe('EventsFactory.bulkToggleEventMark', () => {
4949 } ) ;
5050 } ) ;
5151
52- it ( 'should throw when mark is not resolved or ignored ' , async ( ) => {
52+ it ( 'should throw when mark is unsupported ' , async ( ) => {
5353 const factory = new EventsFactory ( projectId ) ;
5454
55- await expect ( factory . bulkToggleEventMark ( [ ] , 'starred' as any ) ) . rejects . toThrow (
56- 'bulkToggleEventMark: mark must be resolved or ignored'
55+ await expect ( factory . bulkToggleEventMark ( [ ] , 'some-unknown-mark' as any ) ) . rejects . toThrow (
56+ 'bulkToggleEventMark: mark must be resolved, ignored or starred'
57+ ) ;
58+ } ) ;
59+
60+ it ( 'should support starred mark' , async ( ) => {
61+ const factory = new EventsFactory ( projectId ) ;
62+ const id = new ObjectId ( ) ;
63+
64+ collectionMock . find . mockReturnValue ( {
65+ toArray : ( ) =>
66+ Promise . resolve ( [
67+ {
68+ _id : id ,
69+ marks : { } ,
70+ } ,
71+ ] ) ,
72+ } ) ;
73+ collectionMock . bulkWrite . mockResolvedValue ( {
74+ modifiedCount : 1 ,
75+ upsertedCount : 0 ,
76+ } ) ;
77+
78+ const result = await factory . bulkToggleEventMark ( [ id . toString ( ) ] , 'starred' ) ;
79+
80+ expect ( result . updatedCount ) . toBe ( 1 ) ;
81+ expect ( result . updatedEventIds ) . toEqual ( [ id . toString ( ) ] ) ;
82+ const ops = collectionMock . bulkWrite . mock . calls [ 0 ] [ 0 ] ;
83+
84+ expect ( ops ) . toHaveLength ( 1 ) ;
85+ expect ( ops [ 0 ] . updateOne . update ) . toEqual (
86+ expect . objectContaining ( {
87+ $set : { 'marks.starred' : expect . any ( Number ) } ,
88+ } )
5789 ) ;
5890 } ) ;
5991
@@ -99,6 +131,7 @@ describe('EventsFactory.bulkToggleEventMark', () => {
99131 const result = await factory . bulkToggleEventMark ( [ 'not-a-valid-id' ] , 'resolved' ) ;
100132
101133 expect ( result . updatedCount ) . toBe ( 0 ) ;
134+ expect ( result . updatedEventIds ) . toEqual ( [ ] ) ;
102135 expect ( result . failedEventIds ) . toContain ( 'not-a-valid-id' ) ;
103136 expect ( collectionMock . bulkWrite ) . not . toHaveBeenCalled ( ) ;
104137 } ) ;
@@ -114,6 +147,7 @@ describe('EventsFactory.bulkToggleEventMark', () => {
114147 const result = await factory . bulkToggleEventMark ( [ missing . toString ( ) ] , 'ignored' ) ;
115148
116149 expect ( result . updatedCount ) . toBe ( 0 ) ;
150+ expect ( result . updatedEventIds ) . toEqual ( [ ] ) ;
117151 expect ( result . failedEventIds ) . toContain ( missing . toString ( ) ) ;
118152 expect ( collectionMock . bulkWrite ) . not . toHaveBeenCalled ( ) ;
119153 } ) ;
@@ -138,6 +172,7 @@ describe('EventsFactory.bulkToggleEventMark', () => {
138172 const result = await factory . bulkToggleEventMark ( [ a . toString ( ) , b . toString ( ) ] , 'ignored' ) ;
139173
140174 expect ( result . updatedCount ) . toBe ( 1 ) ;
175+ expect ( result . updatedEventIds ) . toEqual ( [ b . toString ( ) ] ) ;
141176 const ops = collectionMock . bulkWrite . mock . calls [ 0 ] [ 0 ] ;
142177
143178 expect ( ops ) . toHaveLength ( 1 ) ;
@@ -169,6 +204,7 @@ describe('EventsFactory.bulkToggleEventMark', () => {
169204 const result = await factory . bulkToggleEventMark ( [ a . toString ( ) , b . toString ( ) ] , 'resolved' ) ;
170205
171206 expect ( result . updatedCount ) . toBe ( 2 ) ;
207+ expect ( result . updatedEventIds ) . toEqual ( [ a . toString ( ) , b . toString ( ) ] ) ;
172208 const ops = collectionMock . bulkWrite . mock . calls [ 0 ] [ 0 ] ;
173209
174210 expect ( ops ) . toHaveLength ( 2 ) ;
@@ -196,6 +232,7 @@ describe('EventsFactory.bulkToggleEventMark', () => {
196232 const result = await factory . bulkToggleEventMark ( [ a . toString ( ) , b . toString ( ) ] , 'ignored' ) ;
197233
198234 expect ( result . updatedCount ) . toBe ( 1 ) ;
235+ expect ( result . updatedEventIds ) . toEqual ( [ b . toString ( ) ] ) ;
199236 const ops = collectionMock . bulkWrite . mock . calls [ 0 ] [ 0 ] ;
200237
201238 expect ( ops ) . toHaveLength ( 1 ) ;
0 commit comments