@@ -116,19 +116,12 @@ class MockRoutingService implements Partial<RoutingService> {
116
116
go = ( ) => Promise . resolve ( true ) ;
117
117
}
118
118
119
- // class MockMultiCartFacade implements Partial<MultiCartFacade> {
120
- // loadCart = () => {};
121
- // removeEntry = () => {};
122
- // addEntries = () => {};
123
- // getCart = () => of(mockCart);
124
- // isStable = () => of(true);
125
- // }
126
-
127
119
class MockMultiCartFacade implements Partial < MultiCartFacade > {
128
- getCart = createSpy ( ) . and . returnValue ( of ( mockCart ) ) ;
129
- addEntry = createSpy ( ) ;
130
- removeEntry = createSpy ( ) ;
131
- isStable = createSpy ( ) . and . returnValue ( of ( true ) ) ;
120
+ loadCart = ( ) => { } ;
121
+ removeEntry = ( ) => { } ;
122
+ addEntries = ( ) => { } ;
123
+ getCart = ( ) => of ( mockCart ) ;
124
+ isStable = ( ) => of ( true ) ;
132
125
}
133
126
134
127
class MockUserIdService implements Partial < UserIdService > {
@@ -335,7 +328,7 @@ describe('Punchoutservice', () => {
335
328
} ) ;
336
329
} ) ;
337
330
338
- it ( 'should closePunchoutSession ' , ( done ) => {
331
+ it ( 'should closePunchoutSession revertToInitialCart in EDIT operation ' , ( done ) => {
339
332
const mockState : PunchoutState = {
340
333
...mockPunchoutState ,
341
334
punchoutInitialCart : mockInitialCart ,
@@ -351,11 +344,85 @@ describe('Punchoutservice', () => {
351
344
// spyOn(multiCartFacade, 'deleteCart').and.callThrough();
352
345
spyOn ( punchoutStoreService , 'updatePunchoutState' ) . and . callThrough ( ) ;
353
346
spyOn ( multiCartFacade , 'addEntries' ) . and . callThrough ( ) ;
354
- spyOn ( multiCartFacade , 'isStable' ) . and . callThrough ( ) ;
347
+ spyOn ( multiCartFacade , 'removeEntry' ) . and . callThrough ( ) ;
348
+ spyOn ( multiCartFacade , 'isStable' ) . and . returnValue ( of ( true ) ) ;
349
+ spyOn ( multiCartFacade , 'getCart' ) . and . returnValue ( of ( mockCart ) ) ;
355
350
356
351
service . closePunchoutSession ( ) . subscribe ( {
357
352
next : ( ) => {
358
353
expect ( punchoutStoreService . updatePunchoutState ) . toHaveBeenCalled ( ) ;
354
+ expect ( multiCartFacade . removeEntry ) . toHaveBeenCalledTimes (
355
+ mockCart . entries . length
356
+ ) ;
357
+ expect ( multiCartFacade . isStable ) . toHaveBeenCalledTimes ( 2 ) ;
358
+ expect ( multiCartFacade . addEntries ) . toHaveBeenCalledWith (
359
+ mockState . punchoutSession ?. customerId as string ,
360
+ mockState . punchoutSession ?. cartId as string ,
361
+ mockState . punchoutInitialCart ?. entries as {
362
+ productCode : string ;
363
+ quantity : number ;
364
+ } [ ]
365
+ ) ;
366
+ done ( ) ;
367
+ } ,
368
+ } ) ;
369
+ } ) ;
370
+
371
+ it ( 'should closePunchoutSession set cancelRequisition in CREATE operation ' , ( done ) => {
372
+ const mockState : PunchoutState = {
373
+ ...mockPunchoutState ,
374
+ punchoutInitialCart : mockInitialCart ,
375
+ punchoutSession : {
376
+ ...mockPunchoutSession ,
377
+ punchOutOperation : PunchOutOperation . CREATE ,
378
+ } ,
379
+ } ;
380
+ spyOn ( routingService , 'go' ) . and . returnValue ( Promise . resolve ( true ) ) ;
381
+ spyOn ( punchoutStoreService , 'getPunchoutState' ) . and . returnValue (
382
+ of ( mockState )
383
+ ) ;
384
+
385
+ spyOn ( punchoutStoreService , 'updatePunchoutState' ) . and . callThrough ( ) ;
386
+ spyOn ( multiCartFacade , 'addEntries' ) . and . callThrough ( ) ;
387
+ spyOn ( multiCartFacade , 'removeEntry' ) . and . callThrough ( ) ;
388
+
389
+ service . closePunchoutSession ( ) . subscribe ( {
390
+ next : ( ) => {
391
+ expect ( punchoutStoreService . updatePunchoutState ) . toHaveBeenCalledWith ( {
392
+ cancelRequisition : true ,
393
+ } ) ;
394
+ expect ( multiCartFacade . addEntries ) . not . toHaveBeenCalled ( ) ;
395
+ expect ( multiCartFacade . removeEntry ) . not . toHaveBeenCalled ( ) ;
396
+ expect ( routingService . go ) . toHaveBeenCalled ( ) ;
397
+ done ( ) ;
398
+ } ,
399
+ } ) ;
400
+ } ) ;
401
+
402
+ it ( 'should closePunchoutSession only go to requisition page in INSPECT operation ' , ( done ) => {
403
+ const mockState : PunchoutState = {
404
+ ...mockPunchoutState ,
405
+ punchoutInitialCart : mockInitialCart ,
406
+ punchoutSession : {
407
+ ...mockPunchoutSession ,
408
+ punchOutOperation : PunchOutOperation . INSPECT ,
409
+ } ,
410
+ } ;
411
+ spyOn ( routingService , 'go' ) . and . returnValue ( Promise . resolve ( true ) ) ;
412
+ spyOn ( punchoutStoreService , 'getPunchoutState' ) . and . returnValue (
413
+ of ( mockState )
414
+ ) ;
415
+
416
+ spyOn ( punchoutStoreService , 'updatePunchoutState' ) . and . callThrough ( ) ;
417
+ spyOn ( multiCartFacade , 'addEntries' ) . and . callThrough ( ) ;
418
+ spyOn ( multiCartFacade , 'removeEntry' ) . and . callThrough ( ) ;
419
+
420
+ service . closePunchoutSession ( ) . subscribe ( {
421
+ next : ( ) => {
422
+ expect ( punchoutStoreService . updatePunchoutState ) . not . toHaveBeenCalled ( ) ;
423
+ expect ( multiCartFacade . addEntries ) . not . toHaveBeenCalled ( ) ;
424
+ expect ( multiCartFacade . removeEntry ) . not . toHaveBeenCalled ( ) ;
425
+ expect ( routingService . go ) . toHaveBeenCalled ( ) ;
359
426
done ( ) ;
360
427
} ,
361
428
} ) ;
0 commit comments