Skip to content

Commit

Permalink
test: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 19, 2024
1 parent 18048bc commit e259bb5
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ import { getFullName } from '@folio/stripes/util';
import {
ACQUISITIONS_UNITS_API,
CONFIG_API,
ORDERS_API,
useUsersBatch,
VENDORS_API,
} from '@folio/stripes-acq-components';
import {
acqUnit,
address,
orderAuditEvent,
vendor,
} from '@folio/stripes-acq-components/test/jest/fixtures';

import { invoiceVersions, invoice } from 'fixtures';
import { useInvoice } from '../useInvoice';
import { useSelectedInvoiceVersion } from './useSelectedInvoiceVersion';


Check failure on line 25 in src/common/hooks/useSelectedInvoiceVersion/useSelectedInvoiceVersion.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

More than 1 blank line not allowed

Check failure on line 25 in src/common/hooks/useSelectedInvoiceVersion/useSelectedInvoiceVersion.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

More than 1 blank line not allowed
jest.mock('@folio/stripes-acq-components/lib/hooks/useUsersBatch', () => ({
useUsersBatch: jest.fn(() => ({ users: [], isLoading: false })),
}));

const order = {
...orderAuditEvent.orderSnapshot,
jest.mock('../useInvoice', () => ({
useInvoice: jest.fn(),
}))

Check failure on line 32 in src/common/hooks/useSelectedInvoiceVersion/useSelectedInvoiceVersion.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing semicolon

Check failure on line 32 in src/common/hooks/useSelectedInvoiceVersion/useSelectedInvoiceVersion.test.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing semicolon

const invoiceData = {
...invoice,
};

const user = {
id: '58edf8c3-89e4-559c-9aed-aae637a3f40b',
id: 'd7b3f1f2-0d1b-4b3f-8e1b-3f1d7b3f1b3f',
personal: { firstName: 'Galt', lastName: 'John' },
};

Expand All @@ -46,9 +52,6 @@ const kyMock = {
if (url.startsWith(VENDORS_API)) {
return { organizations: [vendor] };
}
if (url.startsWith(ORDERS_API)) {
return { ...order };
}

return {};
},
Expand All @@ -68,6 +71,10 @@ describe('useSelectedInvoiceVersion', () => {
beforeEach(() => {
kyMock.get.mockClear();
useOkapiKy.mockClear().mockReturnValue(kyMock);
useInvoice.mockClear().mockReturnValue({
invoice: invoiceData,
isLoading: false,
});
useUsersBatch.mockClear().mockReturnValue({
isLoading: false,
users: [user],
Expand All @@ -76,17 +83,9 @@ describe('useSelectedInvoiceVersion', () => {

it('should return Invoice version data', async () => {
const { result } = renderHook(() => useSelectedInvoiceVersion({
versionId: orderAuditEvent.id,
versions: [{
...orderAuditEvent,
orderSnapshot: {
...orderAuditEvent.orderSnapshot,
acqUnitIds: ['acqUnitId'],
billTo: address.id,
vendor: vendor.id,
},
}],
snapshotPath: 'orderSnapshot',
versionId: '4',
versions: invoiceVersions,
snapshotPath: 'invoiceSnapshot.map',
}), { wrapper });

await waitFor(() => expect(result.current.isLoading).toBeFalsy());
Expand All @@ -95,14 +94,12 @@ describe('useSelectedInvoiceVersion', () => {
id,
billTo,
createdByUser,
shipTo,
vendor: vendorField,
} = result.current.selectedVersion;

expect(id).toEqual(order.id);
expect(id).toEqual(invoiceData.id);
expect(vendorField).toEqual(vendor.name);
expect(billTo).toEqual('stripes-acq-components.versionHistory.deletedRecord');
expect(shipTo).toEqual('stripes-acq-components.versionHistory.deletedRecord');
expect(createdByUser).toEqual(getFullName(user));
});
});
3 changes: 1 addition & 2 deletions src/invoices/VersionHistory/VersionHistory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jest.mock('../../common/hooks', () => ({
...jest.requireActual('../../common/hooks'),
useInvoiceVersions: jest.fn(() => {}),
}));
jest.mock('./VersionView', () => jest.fn().mockReturnValue('VersionView'));

const auditEvent = {
'id': '037cab35-9a01-4d9f-88b4-e5bcdf3e1efb',
Expand Down Expand Up @@ -132,7 +131,7 @@ describe('VersionHistory', () => {

await user.click(versionBtns[0]);

expect(screen.queryByText('VersionView')).toBeInTheDocument();
expect(screen.queryByText('ui-invoice.invoice.details.paneTitle')).toBeInTheDocument();
});

it('should close version view when \'Version close\' button was clicked', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/jest/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './batchVoucherLine';
export * from './exportReport';
export * from './invoice';
export * from './invoiceLine';
export * from './invoiceVersions';
export * from './orderLine';
export * from './router';
export * from './vendor';
155 changes: 155 additions & 0 deletions test/jest/fixtures/invoiceVersions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
export const invoiceVersions = [
{
'id': '4',
'action': 'Edit',
'invoiceId': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'userId': '6a5b1863-cee1-5abd-b8df-7eb82c67134b',
'eventDate': '2024-11-19T10:43:39.309+00:00',
'actionDate': '2024-11-19T10:43:39.302+00:00',
'invoiceSnapshot': {
'map': {
'id': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'total': 28.95,
'billTo': '1',
'source': 'User',
'status': 'Open',
'currency': 'USD',
'subTotal': 28.95,
'vendorId': '11fb627a-cdf1-11e8-a8d5-f2801f1b9fd1',
'lockTotal': 22,
'poNumbers': [
'pref10000',
'10014',
],
'acqUnitIds': [],
'paymentDue': '2024-11-19T00:00:00.000+00:00',
'adjustments': [],
'invoiceDate': '2024-11-19T00:00:00.000+00:00',
'batchGroupId': '2a2cb998-1437-41d1-88ad-01930aaeadd5',
'fiscalYearId': '7a4c4d30-3b63-4102-8e2d-3ee5792d7d02',
'paymentMethod': 'Credit Card',
'accountingCode': 'G64758-74834',
'folioInvoiceNo': '10001',
'enclosureNeeded': false,
'vendorInvoiceNo': '2',
'adjustmentsTotal': 0,
'exportToAccounting': true,
'nextInvoiceLineNumber': 3,
'chkSubscriptionOverlap': true,
},
'empty': false,
},
},
{
'id': '3',
'action': 'Edit',
'invoiceId': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'userId': '6a5b1863-cee1-5abd-b8df-7eb82c67134b',
'eventDate': '2024-11-19T08:39:52.380+00:00',
'actionDate': '2024-11-19T08:39:52.374+00:00',
'invoiceSnapshot': {
'map': {
'id': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'total': 28.95,
'source': 'User',
'status': 'Open',
'currency': 'USD',
'subTotal': 28.95,
'vendorId': '11fb627a-cdf1-11e8-a8d5-f2801f1b9fd1',
'poNumbers': [
'pref10000',
'10014',
],
'acqUnitIds': [],
'paymentDue': '2024-11-19T00:00:00.000+00:00',
'adjustments': [],
'invoiceDate': '2024-11-19T00:00:00.000+00:00',
'batchGroupId': '2a2cb998-1437-41d1-88ad-01930aaeadd5',
'fiscalYearId': '7a4c4d30-3b63-4102-8e2d-3ee5792d7d02',
'paymentMethod': 'Credit Card',
'accountingCode': 'G64758-74834',
'folioInvoiceNo': '10001',
'enclosureNeeded': false,
'vendorInvoiceNo': '2',
'adjustmentsTotal': 0,
'exportToAccounting': true,
'nextInvoiceLineNumber': 3,
'chkSubscriptionOverlap': true,
},
'empty': false,
},
},
{
'id': '2',
'action': 'Edit',
'invoiceId': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'userId': '6a5b1863-cee1-5abd-b8df-7eb82c67134b',
'eventDate': '2024-11-19T05:25:34.676+00:00',
'actionDate': '2024-11-19T05:25:34.668+00:00',
'invoiceSnapshot': {
'map': {
'id': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'total': 1,
'source': 'User',
'status': 'Open',
'currency': 'USD',
'subTotal': 1,
'vendorId': '11fb627a-cdf1-11e8-a8d5-f2801f1b9fd1',
'poNumbers': [
'pref10000',
],
'acqUnitIds': [],
'paymentDue': '2024-11-19T00:00:00.000+00:00',
'adjustments': [],
'invoiceDate': '2024-11-19T00:00:00.000+00:00',
'batchGroupId': '2a2cb998-1437-41d1-88ad-01930aaeadd5',
'fiscalYearId': '7a4c4d30-3b63-4102-8e2d-3ee5792d7d02',
'paymentMethod': 'Credit Card',
'accountingCode': 'G64758-74834',
'folioInvoiceNo': '10001',
'enclosureNeeded': false,
'vendorInvoiceNo': '2',
'adjustmentsTotal': 0,
'exportToAccounting': true,
'nextInvoiceLineNumber': 2,
'chkSubscriptionOverlap': true,
},
'empty': false,
},
},
{
'id': '1',
'action': 'Create',
'invoiceId': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'userId': '6a5b1863-cee1-5abd-b8df-7eb82c67134b',
'eventDate': '2024-11-19T05:25:15.237+00:00',
'actionDate': '2024-11-19T05:25:15.229+00:00',
'invoiceSnapshot': {
'map': {
'id': '2e5067cd-2dc8-4d99-900d-b4518bb6407f',
'total': 0,
'source': 'User',
'status': 'Open',
'currency': 'USD',
'subTotal': 0,
'vendorId': '11fb627a-cdf1-11e8-a8d5-f2801f1b9fd1',
'poNumbers': [],
'acqUnitIds': [],
'paymentDue': '2024-11-19T00:00:00.000+00:00',
'adjustments': [],
'invoiceDate': '2024-11-19T00:00:00.000+00:00',
'batchGroupId': '2a2cb998-1437-41d1-88ad-01930aaeadd5',
'paymentMethod': 'Credit Card',
'accountingCode': 'G64758-74834',
'folioInvoiceNo': '10001',
'enclosureNeeded': false,
'vendorInvoiceNo': '2',
'adjustmentsTotal': 0,
'exportToAccounting': true,
'nextInvoiceLineNumber': 1,
'chkSubscriptionOverlap': true,
},
'empty': false,
},
},
];

0 comments on commit e259bb5

Please sign in to comment.