@@ -122,13 +122,14 @@ describe('useGetCaseUserActions', () => {
122122 ...basicPush ,
123123 firstPushIndex : 3 ,
124124 lastPushIndex : 3 ,
125+ commentsToUpdate : [ ] ,
125126 hasDataToPush : false ,
126127 } ,
127128 } ,
128129 } ) ;
129130 } ) ;
130131
131- it ( 'Correctly marks first/last index - hasDataToPush: true' , ( ) => {
132+ it ( 'Correctly marks first/last index and comment id - hasDataToPush: true' , ( ) => {
132133 const userActions = [
133134 ...caseUserActions ,
134135 getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
@@ -142,6 +143,83 @@ describe('useGetCaseUserActions', () => {
142143 ...basicPush ,
143144 firstPushIndex : 3 ,
144145 lastPushIndex : 3 ,
146+ commentsToUpdate : [ userActions [ userActions . length - 1 ] . commentId ] ,
147+ hasDataToPush : true ,
148+ } ,
149+ } ,
150+ } ) ;
151+ } ) ;
152+
153+ it ( 'Correctly marks first/last index and multiple comment ids, both needs push' , ( ) => {
154+ const userActions = [
155+ ...caseUserActions ,
156+ getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
157+ getUserAction ( [ 'comment' ] , 'create' ) ,
158+ { ...getUserAction ( [ 'comment' ] , 'create' ) , commentId : 'muahaha' } ,
159+ ] ;
160+ const result = getPushedInfo ( userActions , '123' ) ;
161+ expect ( result ) . toEqual ( {
162+ hasDataToPush : true ,
163+ caseServices : {
164+ '123' : {
165+ ...basicPush ,
166+ firstPushIndex : 3 ,
167+ lastPushIndex : 3 ,
168+ commentsToUpdate : [
169+ userActions [ userActions . length - 2 ] . commentId ,
170+ userActions [ userActions . length - 1 ] . commentId ,
171+ ] ,
172+ hasDataToPush : true ,
173+ } ,
174+ } ,
175+ } ) ;
176+ } ) ;
177+
178+ it ( 'Correctly marks first/last index and multiple comment ids, one needs push' , ( ) => {
179+ const userActions = [
180+ ...caseUserActions ,
181+ getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
182+ getUserAction ( [ 'comment' ] , 'create' ) ,
183+ getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
184+ { ...getUserAction ( [ 'comment' ] , 'create' ) , commentId : 'muahaha' } ,
185+ ] ;
186+ const result = getPushedInfo ( userActions , '123' ) ;
187+ expect ( result ) . toEqual ( {
188+ hasDataToPush : true ,
189+ caseServices : {
190+ '123' : {
191+ ...basicPush ,
192+ firstPushIndex : 3 ,
193+ lastPushIndex : 5 ,
194+ commentsToUpdate : [ userActions [ userActions . length - 1 ] . commentId ] ,
195+ hasDataToPush : true ,
196+ } ,
197+ } ,
198+ } ) ;
199+ } ) ;
200+
201+ it ( 'Correctly marks first/last index and multiple comment ids, one needs push and one needs update' , ( ) => {
202+ const userActions = [
203+ ...caseUserActions ,
204+ getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
205+ getUserAction ( [ 'comment' ] , 'create' ) ,
206+ getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
207+ { ...getUserAction ( [ 'comment' ] , 'create' ) , commentId : 'muahaha' } ,
208+ getUserAction ( [ 'comment' ] , 'update' ) ,
209+ getUserAction ( [ 'comment' ] , 'update' ) ,
210+ ] ;
211+ const result = getPushedInfo ( userActions , '123' ) ;
212+ expect ( result ) . toEqual ( {
213+ hasDataToPush : true ,
214+ caseServices : {
215+ '123' : {
216+ ...basicPush ,
217+ firstPushIndex : 3 ,
218+ lastPushIndex : 5 ,
219+ commentsToUpdate : [
220+ userActions [ userActions . length - 3 ] . commentId ,
221+ userActions [ userActions . length - 1 ] . commentId ,
222+ ] ,
145223 hasDataToPush : true ,
146224 } ,
147225 } ,
@@ -162,6 +240,7 @@ describe('useGetCaseUserActions', () => {
162240 ...basicPush ,
163241 firstPushIndex : 3 ,
164242 lastPushIndex : 3 ,
243+ commentsToUpdate : [ ] ,
165244 hasDataToPush : false ,
166245 } ,
167246 } ,
@@ -182,11 +261,34 @@ describe('useGetCaseUserActions', () => {
182261 ...basicPush ,
183262 firstPushIndex : 3 ,
184263 lastPushIndex : 5 ,
264+ commentsToUpdate : [ ] ,
185265 hasDataToPush : false ,
186266 } ,
187267 } ,
188268 } ) ;
189269 } ) ;
270+ it ( 'Correctly handles comment update with multiple push actions' , ( ) => {
271+ const userActions = [
272+ ...caseUserActions ,
273+ getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
274+ getUserAction ( [ 'comment' ] , 'create' ) ,
275+ getUserAction ( [ 'pushed' ] , 'push-to-service' ) ,
276+ getUserAction ( [ 'comment' ] , 'update' ) ,
277+ ] ;
278+ const result = getPushedInfo ( userActions , '123' ) ;
279+ expect ( result ) . toEqual ( {
280+ hasDataToPush : true ,
281+ caseServices : {
282+ '123' : {
283+ ...basicPush ,
284+ firstPushIndex : 3 ,
285+ lastPushIndex : 5 ,
286+ commentsToUpdate : [ userActions [ userActions . length - 1 ] . commentId ] ,
287+ hasDataToPush : true ,
288+ } ,
289+ } ,
290+ } ) ;
291+ } ) ;
190292
191293 it ( 'Multiple connector tracking - hasDataToPush: true' , ( ) => {
192294 const pushAction123 = getUserAction ( [ 'pushed' ] , 'push-to-service' ) ;
@@ -215,6 +317,7 @@ describe('useGetCaseUserActions', () => {
215317 ...basicPush ,
216318 firstPushIndex : 3 ,
217319 lastPushIndex : 3 ,
320+ commentsToUpdate : [ userActions [ userActions . length - 2 ] . commentId ] ,
218321 hasDataToPush : true ,
219322 } ,
220323 '456' : {
@@ -224,6 +327,7 @@ describe('useGetCaseUserActions', () => {
224327 externalId : 'other_external_id' ,
225328 firstPushIndex : 5 ,
226329 lastPushIndex : 5 ,
330+ commentsToUpdate : [ ] ,
227331 hasDataToPush : false ,
228332 } ,
229333 } ,
@@ -257,6 +361,7 @@ describe('useGetCaseUserActions', () => {
257361 ...basicPush ,
258362 firstPushIndex : 3 ,
259363 lastPushIndex : 3 ,
364+ commentsToUpdate : [ userActions [ userActions . length - 2 ] . commentId ] ,
260365 hasDataToPush : true ,
261366 } ,
262367 '456' : {
@@ -266,6 +371,7 @@ describe('useGetCaseUserActions', () => {
266371 externalId : 'other_external_id' ,
267372 firstPushIndex : 5 ,
268373 lastPushIndex : 5 ,
374+ commentsToUpdate : [ ] ,
269375 hasDataToPush : false ,
270376 } ,
271377 } ,
0 commit comments