Skip to content

Commit

Permalink
Fixes the failing test: Missing jembi/openhim-core-api module
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsMurumba committed Sep 5, 2024
1 parent f91121e commit 336ec6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 7 additions & 1 deletion packages/transaction-log/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path')

module.exports = {
rootDir: 'src',
testEnvironment: 'jsdom',
Expand All @@ -6,7 +8,11 @@ module.exports = {
},
moduleNameMapper: {
'\\.(css)$': 'identity-obj-proxy',
'single-spa-react/parcel': 'single-spa-react/lib/cjs/parcel.cjs'
'single-spa-react/parcel': 'single-spa-react/lib/cjs/parcel.cjs',
'^@jembi/openhim-core-api$': path.resolve(
__dirname,
'../openhim-core-api/src/jembi-openhim-core-api.ts'
)
},
setupFilesAfterEnv: ['@testing-library/jest-dom']
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const RerunTransactionsConfirmationModal: React.FC<Props> = ({
<InputLabel>Batch size</InputLabel>
<Select
value={taskSetup.batchSize}
// onChange={handleBatchSizeChange}
// onChange={handleBatchSizeChange}
label="Batch size"
>
{batchSizes.map(batch => (
Expand Down
21 changes: 12 additions & 9 deletions packages/transaction-log/src/services/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import {
} from '@jembi/openhim-core-api'
import {Client, Channel} from '../types'

jest.mock('@jembi/openhim-core-api')
jest.mock('@jembi/openhim-core-api', () => ({
fetchClients: jest.fn(),
fetchClientById: jest.fn(),
fetchChannels: jest.fn(),
fetchChannelById: jest.fn(),
fetchTransactions: jest.fn()
}))

describe('API Service Tests', () => {
afterEach(() => {
Expand Down Expand Up @@ -120,23 +126,20 @@ describe('API Service Tests', () => {

const transactions = await getTransactions({})
expect(transactions).toEqual(mockTransactions)
expect(fetchTransactions).toHaveBeenCalledWith({
filters: {}
})

expect(fetchTransactions).toHaveBeenCalledWith({})
})

it('should throw an error if fetchTransactions fails', async () => {
const errorMessage = 'Failed to fetch transactions'

;(fetchTransactions as jest.Mock).mockRejectedValue(
new Error(errorMessage)
)

await expect(getTransactions({})).rejects.toThrow(errorMessage)
expect(fetchTransactions).toHaveBeenCalledWith({
filterLimit: 10,
filterPage: 1,
filters: {}
})

expect(fetchTransactions).toHaveBeenCalledWith({})
})
})
})

0 comments on commit 336ec6e

Please sign in to comment.