11import { extractResponse } from '@pagopa/selfcare-common-frontend/utils/api-utils' ;
22import { createClient } from '../generated/merchants/client' ;
3+ import { store } from '../../redux/store' ;
34
45jest . mock ( '@pagopa/selfcare-common-frontend/utils/storage' , ( ) => ( {
56 storageTokenOps : { read : jest . fn ( ) . mockReturnValue ( 'mocked-token' ) } ,
67} ) ) ;
78
89jest . mock ( '@pagopa/selfcare-common-frontend/redux/slices/appStateSlice' , ( ) => ( {
910 appStateActions : { addError : jest . fn ( ( e ) => e ) } ,
10- appStateReducer : ( state = { } , action : any ) => state ,
11+ } ) ) ;
12+
13+ jest . mock ( '../../redux/store' , ( ) => ( {
14+ store : { dispatch : jest . fn ( ) } ,
1115} ) ) ;
1216
1317jest . mock ( '@pagopa/selfcare-common-frontend/utils/api-utils' , ( ) => ( {
@@ -21,6 +25,8 @@ jest.mock('../generated/merchants/client', () => ({
2125
2226let mockApiClient : any ;
2327
28+ store . dispatch = jest . fn ( ) ;
29+
2430describe ( 'MerchantApi' , ( ) => {
2531 beforeEach ( ( ) => {
2632 mockApiClient = {
@@ -35,6 +41,7 @@ describe('MerchantApi', () => {
3541 putPointOfSales : jest . fn ( ) ,
3642 getPointOfSales : jest . fn ( ) ,
3743 getPointOfSale : jest . fn ( ) ,
44+ getPointOfSalesWithTransactions : jest . fn ( ) ,
3845 getPointOfSaleTransactionsProcessed : jest . fn ( ) ,
3946 downloadInvoiceFile : jest . fn ( ) ,
4047 getReportedUser : jest . fn ( ) ,
@@ -43,6 +50,7 @@ describe('MerchantApi', () => {
4350 sendRewardBatches : jest . fn ( ) ,
4451 postponeTransaction : jest . fn ( ) ,
4552 approveDownloadRewardBatch : jest . fn ( ) ,
53+ getAllRewardBatches : jest . fn ( )
4654 } ;
4755
4856 ( createClient as jest . Mock ) . mockReturnValue ( mockApiClient ) ;
@@ -272,6 +280,42 @@ describe('MerchantApi', () => {
272280 expect ( result ) . toBe ( 'extracted' ) ;
273281 } ) ;
274282
283+ it ( 'getMerchantPointOfSalesWithTransactions resolved' , async ( ) => {
284+ const json = jest . fn ( ) . mockResolvedValue ( "test" ) ;
285+ global . fetch = jest . fn ( ) . mockResolvedValue ( { ok : true , json} ) ;
286+
287+ const MerchantApi = loadApi ( ) ;
288+
289+ const resolvedResult = await MerchantApi . getMerchantPointOfSalesWithTransactions ( 'batch-id' ) ;
290+
291+ expect ( global . fetch ) . toHaveBeenCalledWith ( expect . any ( String ) , {
292+ method : 'GET' ,
293+ headers : {
294+ Authorization : `Bearer mocked-token` ,
295+ Accept : 'application/json' ,
296+ } ,
297+ } ) ;
298+ expect ( json ) . toHaveBeenCalled ( )
299+ expect ( resolvedResult ) . toBe ( "test" )
300+ } ) ;
301+
302+ it ( 'getMerchantPointOfSalesWithTransactions rejected' , async ( ) => {
303+ global . fetch = jest . fn ( ) . mockResolvedValue ( { ok : false } ) ;
304+
305+ const MerchantApi = loadApi ( ) ;
306+
307+ const rejectedResult = await MerchantApi . getMerchantPointOfSalesWithTransactions ( 'batch-id' ) ;
308+
309+ expect ( global . fetch ) . toHaveBeenCalledWith ( expect . any ( String ) , {
310+ method : 'GET' ,
311+ headers : {
312+ Authorization : `Bearer mocked-token` ,
313+ Accept : 'application/json' ,
314+ } ,
315+ } ) ;
316+ expect ( rejectedResult ) . toStrictEqual ( [ ] )
317+ } ) ;
318+
275319 it ( 'getMerchantPointOfSaleTransactionsProcessed' , async ( ) => {
276320 mockApiClient . getPointOfSaleTransactionsProcessed . mockResolvedValue ( { right : 'data' } ) ;
277321 const MerchantApi = loadApi ( ) ;
@@ -437,17 +481,15 @@ describe('MerchantApi', () => {
437481 expect ( result ) . toBe ( 'extracted' ) ;
438482 } ) ;
439483
440- it . skip ( 'sendRewardBatches - error with REWARD_BATCH_PREVIOUS_NOT_SENT' , async ( ) => {
484+ it ( 'sendRewardBatches - error with REWARD_BATCH_PREVIOUS_NOT_SENT' , async ( ) => {
441485 mockApiClient . sendRewardBatches . mockResolvedValue ( {
442- left : [ { value : 'REWARD_BATCH_PREVIOUS_NOT_SENT' } ] ,
486+ right : { value : { code : 'REWARD_BATCH_PREVIOUS_NOT_SENT' } , status : 400 } ,
443487 } ) ;
444488 const MerchantApi = loadApi ( ) ;
445489
446490 const result = await MerchantApi . sendRewardBatches ( 'init1' , 'batch1' ) ;
447491
448- expect ( result ) . toEqual ( {
449- code : 'REWARD_BATCH_PREVIOUS_NOT_SENT' ,
450- } ) ;
492+ expect ( result ) . toBe ( 'REWARD_BATCH_PREVIOUS_NOT_SENT' ) ;
451493 } ) ;
452494
453495 it ( 'sendRewardBatches - error with other code' , async ( ) => {
0 commit comments