Skip to content

Commit

Permalink
fix: (tests) - enhance tests to include cahpoint logic
Browse files Browse the repository at this point in the history
  • Loading branch information
amosmachora authored and donaldkibet committed Nov 15, 2024
1 parent e177100 commit eb4d339
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 7 deletions.
54 changes: 54 additions & 0 deletions __mocks__/bills.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,57 @@ export const mockPaymentModes = [
},
{ uuid: 'eb6173cb-9678-4614-bbe1-0ccf7ed9d1d4', name: 'Waiver', description: 'Waiver payment', retired: false },
];

export const mockedActiveSheet = {
uuid: 'cbf56e9a-5db1-41d3-8d34-e228aa2e31c0',
display: '14 Nov 2024, 08:11 to open',
voided: false,
voidReason: null,
auditInfo: {
creator: {
uuid: 'e02c40e5-04e7-11e5-ae3c-a0b3cc4f922f',
display: 'admin',
links: [
{
rel: 'self',
uri: 'http://dev.kenyahmis.org/openmrs/ws/rest/v1/user/e02c40e5-04e7-11e5-ae3c-a0b3cc4f922f',
resourceAlias: 'user',
},
],
},
dateCreated: '2024-11-14T08:11:27.000+0300',
changedBy: null,
dateChanged: null,
},
cashier: {
uuid: '48b55692-e061-4ffa-b1f2-fd4aaf506224',
display: 'admin - Barbara Stewart Lopez',
links: [
{
rel: 'self',
uri: 'http://dev.kenyahmis.org/openmrs/ws/rest/v1/provider/48b55692-e061-4ffa-b1f2-fd4aaf506224',
resourceAlias: 'provider',
},
],
},
cashPoint: {
uuid: '65dd568e-4124-4e89-a4f8-0b07c58ec6fe',
name: 'MNCH Pay Point',
description: 'Payment done at the MNCH department',
retired: false,
location: {
uuid: '233de33e-2778-4f9a-a398-fa09da9daa14',
display: 'Wamagana Health Centre',
links: [
{
rel: 'self',
uri: 'http://dev.kenyahmis.org/openmrs/ws/rest/v1/location/233de33e-2778-4f9a-a398-fa09da9daa14',
resourceAlias: 'location',
},
],
},
},
clockIn: '2024-11-14T08:11:27.000+0300',
clockOut: null,
resourceVersion: '1.8',
};
27 changes: 20 additions & 7 deletions packages/esm-billing-app/src/invoice/payments/payments.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { showSnackbar } from '@openmrs/esm-framework';
import { render, screen } from '@testing-library/react';
import Payments from './payments.component';
import { mockBill, mockLineItems, mockPaymentModes } from '../../../../../__mocks__/bills.mock';
import { processBillPayment, usePaymentModes } from '../../billing.resource';
import userEvent from '@testing-library/user-event';
import { showSnackbar } from '@openmrs/esm-framework';

import React from 'react';
import { mockBill, mockedActiveSheet, mockLineItems, mockPaymentModes } from '../../../../../__mocks__/bills.mock';
import { processBillPayment, usePaymentModes } from '../../billing.resource';
import { useClockInStatus } from '../../payment-points/use-clock-in-status';
import Payments from './payments.component';
const mockProcessBillPayment = processBillPayment as jest.MockedFunction<typeof processBillPayment>;
const mockUsePaymentModes = usePaymentModes as jest.MockedFunction<typeof usePaymentModes>;
const mockShowSnackbar = showSnackbar as jest.MockedFunction<typeof showSnackbar>;
Expand All @@ -15,6 +15,9 @@ jest.mock('../../billing.resource', () => ({
usePaymentModes: jest.fn(),
}));

jest.mock('../../payment-points/use-clock-in-status');
const mockedUseClockInStatus = useClockInStatus as jest.Mock;

describe('Payment', () => {
test('should display error when posting payment fails', async () => {
const user = userEvent.setup();
Expand All @@ -35,6 +38,16 @@ describe('Payment', () => {
error: null,
mutate: jest.fn(),
});

mockedUseClockInStatus.mockReturnValue({
globalActiveSheet: mockedActiveSheet,
localActiveSheet: undefined,
isClockedInSomewhere: true,
error: null,
isLoading: false,
isClockedInCurrentPaymentPoint: false,
});

render(<Payments bill={mockBill as any} selectedLineItems={mockLineItems} />);
const addPaymentMethod = screen.getByRole('button', { name: /Add payment option/i });
await user.click(addPaymentMethod);
Expand All @@ -51,7 +64,7 @@ describe('Payment', () => {
expect(mockProcessBillPayment).toHaveBeenCalledTimes(1);
expect(mockProcessBillPayment).toHaveBeenCalledWith(
{
cashPoint: '54065383-b4d4-42d2-af4d-d250a1fd2590',
cashPoint: mockedActiveSheet.cashPoint.uuid,
cashier: 'fe00dd43-4c39-4ce9-9832-bc3620c80c6c',
lineItems: [
{
Expand Down

0 comments on commit eb4d339

Please sign in to comment.