import apiFetch from '@wordpress/api-fetch'; import { markOrderAsPaid } from '../features/order-ship/utils/shippingStatus'; import type { OrderPickupPoint } from '../types'; jest.mock( '@wordpress/api-fetch', () => jest.fn() ); jest.mock( '../shared/sentry', () => ( { addBreadcrumb: jest.fn(), captureException: jest.fn(), captureMessage: jest.fn(), setContext: jest.fn(), withSpan: ( _name: string, _op: string, fn: () => unknown ) => fn(), } ) ); const mockedFetch = apiFetch as unknown as jest.Mock; const locker: OrderPickupPoint = { id: 222, provider: 'INPOST', name: 'Locker B', address1: '2 Street', address2: 'Leeds', postcode: 'LS2 7BB', isLocker: true, }; const payment = { orderId: 'P2G1', completeHash: 'hash' }; describe( 'markOrderAsPaid', () => { beforeEach( () => mockedFetch.mockResolvedValue( { success: true } ) ); afterEach( () => jest.clearAllMocks() ); it( 'sends the booked locker or shop so the order keeps it', async () => { await markOrderAsPaid( [ '407' ], payment, null, locker ); expect( mockedFetch ).toHaveBeenCalledWith( expect.objectContaining( { path: '/parcel2go-shipping/v1/orders/407/shipping-status', data: expect.objectContaining( { status: 'Paid', pickupPoint: locker } ), } ) ); } ); it( 'sends no place for home delivery', async () => { await markOrderAsPaid( [ '409' ], payment, null, null ); expect( mockedFetch.mock.calls[ 0 ][ 0 ].data ).not.toHaveProperty( 'pickupPoint' ); } ); } );