This repository was archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(billing): create a basic billing module #2528
Open
rsousaj
wants to merge
13
commits into
HospitalRun:master
Choose a base branch
from
rsousaj:2496-billing-module
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c4d0615
feat(billing): created model and repository (w tests) for pricing item
rsousaj dd0b52a
feat(billing): sidebar and routes implementations, also translations …
rsousaj 45e5e3e
feat(billing): hooks implementation
rsousaj 47069ca
feat(billing): created basic billing module
rsousaj 2c8e0ac
feat(billing): correcting useEffect dependecies of AddPricingItem
rsousaj 5eefdcc
feat(billing): improving test coverage
rsousaj 77d598a
Merge branch 'master' into 2496-billing-module
matteovivona bfdb541
Merge branch 'master' into 2496-billing-module
matteovivona 47b4c36
feat(billing): review changes
rsousaj eac27dc
Merge branch 'master' into 2496-billing-module
matteovivona d9788b2
Merge branch 'master' into 2496-billing-module
matteovivona e50badd
Merge branch 'master' into 2496-billing-module
blestab 9a12b4e
Merge branch 'master' into 2496-billing-module
matteovivona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { act } from '@testing-library/react' | ||
import { mount, ReactWrapper } from 'enzyme' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { MemoryRouter } from 'react-router-dom' | ||
import createMockStore from 'redux-mock-store' | ||
|
||
import Billing from '../../billing/Billing' | ||
import AddPricingItem from '../../billing/new/AddPricingItem' | ||
import ViewPricingItem from '../../billing/view/ViewPricingItem' | ||
import ViewPricingItems from '../../billing/view/ViewPricingItems' | ||
import { TitleProvider } from '../../page-header/title/TitleContext' | ||
import Permissions from '../../shared/model/Permissions' | ||
import { RootState } from '../../shared/store' | ||
|
||
const mockStore = createMockStore<RootState, any>() | ||
describe('Billing', () => { | ||
const setup = (route: string, permissions: Permissions[] = []) => { | ||
const store = mockStore({ | ||
user: { | ||
permissions, | ||
}, | ||
} as any) | ||
|
||
let wrapper: any | ||
act(() => { | ||
wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={[route]}> | ||
<TitleProvider> | ||
<Billing /> | ||
</TitleProvider> | ||
</MemoryRouter> | ||
</Provider>, | ||
) | ||
}) | ||
|
||
return { wrapper: wrapper as ReactWrapper } | ||
} | ||
|
||
describe('routing', () => { | ||
describe('/billing/new', () => { | ||
it('should render the AddPricingItem screen when /billing/new is accessed', () => { | ||
const { wrapper } = setup('/billing/new', [Permissions.AddPricingItems]) | ||
|
||
const addPricingItemView = wrapper.find(AddPricingItem) | ||
expect(addPricingItemView.exists()).toBeTruthy() | ||
}) | ||
|
||
it('should not render the AddPricingItem screen if user does not have permissions', () => { | ||
const { wrapper } = setup('/billing/new') | ||
|
||
const addPricingItemView = wrapper.find(AddPricingItem) | ||
expect(addPricingItemView.exists()).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('/billing/:id', () => { | ||
it('should render the ViewPricingItem screen when /billing/:id is accessed', () => { | ||
const { wrapper } = setup('/billing/123', [Permissions.ViewPricingItems]) | ||
|
||
const viewPricingItem = wrapper.find(ViewPricingItem) | ||
expect(viewPricingItem.exists()).toBeTruthy() | ||
}) | ||
|
||
it('should not render the ViewPricingItem if user does not have permissions', () => { | ||
const { wrapper } = setup('/billing/123') | ||
|
||
const viewPricingItem = wrapper.find(ViewPricingItem) | ||
expect(viewPricingItem.exists()).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('/billing', () => { | ||
it('should render the ViewPricingItems screen when /billing/ is accessed', () => { | ||
const { wrapper } = setup('/billing', [Permissions.ViewPricingItems]) | ||
|
||
const viewPricingItems = wrapper.find(ViewPricingItems) | ||
expect(viewPricingItems.exists()).toBeTruthy() | ||
}) | ||
|
||
it('should not render the ViewPricingItems when user does not have permissions', () => { | ||
const { wrapper } = setup('/billing') | ||
|
||
const viewPricingItems = wrapper.find(ViewPricingItems) | ||
expect(viewPricingItems.exists()).toBeFalsy() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { act } from '@testing-library/react-hooks' | ||
|
||
import useAddPricingItem from '../../../billing/hooks/useAddPricingItem' | ||
import { PricingItemError } from '../../../billing/utils/validate-pricingItem' | ||
import * as validatePricingItem from '../../../billing/utils/validate-pricingItem' | ||
import PricingItemRepository from '../../../shared/db/PricingItemRepository' | ||
import { PricingItem } from '../../../shared/model/PricingItem' | ||
import executeMutation from '../../test-utils/use-mutation.util' | ||
|
||
describe('Use Add Pricing Item', () => { | ||
const expectedPricingItem = { | ||
name: 'pricing item', | ||
price: 10, | ||
category: 'ward', | ||
} as PricingItem | ||
|
||
jest.spyOn(PricingItemRepository, 'save').mockResolvedValue(expectedPricingItem) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should save a new pricing item', async () => { | ||
let actualData: any | ||
await act(async () => { | ||
actualData = await executeMutation(() => useAddPricingItem(), expectedPricingItem) | ||
}) | ||
|
||
expect(PricingItemRepository.save).toHaveBeenCalledTimes(1) | ||
expect(PricingItemRepository.save).toHaveBeenCalledWith(expectedPricingItem) | ||
expect(actualData).toEqual(expectedPricingItem) | ||
}) | ||
|
||
it('should fill type if its not filled when category is imaging or lab', async () => { | ||
const expectedPricingItem1 = { | ||
...expectedPricingItem, | ||
category: 'lab', | ||
} as PricingItem | ||
|
||
const expectedPricingItem2 = { | ||
...expectedPricingItem, | ||
category: 'imaging', | ||
} as PricingItem | ||
|
||
await act(async () => { | ||
await executeMutation(() => useAddPricingItem(), expectedPricingItem1) | ||
await executeMutation(() => useAddPricingItem(), expectedPricingItem2) | ||
}) | ||
|
||
expect(PricingItemRepository.save).toHaveBeenCalledTimes(2) | ||
expect(PricingItemRepository.save).toHaveBeenNthCalledWith(1, { | ||
...expectedPricingItem1, | ||
type: 'Lab Procedure', | ||
}) | ||
expect(PricingItemRepository.save).toHaveBeenNthCalledWith(2, { | ||
...expectedPricingItem2, | ||
type: 'Imaging Procedure', | ||
}) | ||
}) | ||
|
||
it('should return errors', async () => { | ||
rsousaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect.hasAssertions() | ||
|
||
const expectedErrors = { | ||
message: 'error message', | ||
name: 'error name', | ||
price: 'error price', | ||
category: 'error category', | ||
} as PricingItemError | ||
|
||
jest.spyOn(validatePricingItem, 'validateNewPricingItem').mockReturnValue(expectedErrors) | ||
|
||
try { | ||
await executeMutation(() => useAddPricingItem(), expectedPricingItem) | ||
} catch (e) { | ||
expect(e).toEqual(expectedErrors) | ||
expect(PricingItemRepository.save).not.toHaveBeenCalled() | ||
} | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { act, renderHook } from '@testing-library/react-hooks' | ||
|
||
import usePricingItem from '../../../billing/hooks/usePricingItem' | ||
import PricingItemRepository from '../../../shared/db/PricingItemRepository' | ||
import { PricingItem } from '../../../shared/model/PricingItem' | ||
import waitUntilQueryIsSuccessful from '../../test-utils/wait-for-query.util' | ||
|
||
describe('Use Pricing Item', () => { | ||
const expectedPricingItemId = 'pricing item id' | ||
const expectedPricingItem = { | ||
id: expectedPricingItemId, | ||
} as PricingItem | ||
|
||
jest.spyOn(PricingItemRepository, 'find').mockResolvedValue(expectedPricingItem) | ||
|
||
it('should return a pricing item by id', async () => { | ||
let actualData: any | ||
await act(async () => { | ||
const renderHookResult = renderHook(() => usePricingItem(expectedPricingItemId)) | ||
const { result } = renderHookResult | ||
await waitUntilQueryIsSuccessful(renderHookResult) | ||
actualData = result.current.data | ||
}) | ||
|
||
expect(PricingItemRepository.find).toHaveBeenCalledTimes(1) | ||
expect(PricingItemRepository.find).toHaveBeenCalledWith(expectedPricingItemId) | ||
expect(actualData).toEqual(expectedPricingItem) | ||
}) | ||
}) |
61 changes: 61 additions & 0 deletions
61
src/__tests__/billing/hooks/usePricingItemsSearch.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { act, renderHook } from '@testing-library/react-hooks' | ||
|
||
import usePricingItemsSearch from '../../../billing/hooks/usePricingItemsSearch' | ||
import PricingItemSearchRequests from '../../../billing/model/PricingItemSearchRequest' | ||
import PricingItemRepository from '../../../shared/db/PricingItemRepository' | ||
import { PricingItem } from '../../../shared/model/PricingItem' | ||
import waitUntilQueryIsSuccessful from '../../test-utils/wait-for-query.util' | ||
|
||
describe('Use Pricing Items Search', () => { | ||
const expectedPricingItem = [ | ||
{ | ||
name: 'pricing item', | ||
}, | ||
] as PricingItem[] | ||
|
||
jest.spyOn(PricingItemRepository, 'findAll').mockResolvedValue(expectedPricingItem) | ||
jest.spyOn(PricingItemRepository, 'search').mockResolvedValue(expectedPricingItem) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should find all if no criteria is provided', async () => { | ||
const pricingItemsSearchRequest = { | ||
text: '', | ||
category: 'all', | ||
} as PricingItemSearchRequests | ||
|
||
let actualData: any | ||
await act(async () => { | ||
const renderHookResult = renderHook(() => usePricingItemsSearch(pricingItemsSearchRequest)) | ||
const { result } = renderHookResult | ||
await waitUntilQueryIsSuccessful(renderHookResult) | ||
actualData = result.current.data | ||
}) | ||
|
||
expect(PricingItemRepository.search).not.toHaveBeenCalled() | ||
expect(PricingItemRepository.findAll).toHaveBeenCalledTimes(1) | ||
expect(actualData).toEqual(expectedPricingItem) | ||
}) | ||
|
||
it('should search for pricing items', async () => { | ||
const pricingItemsSearchRequest = { | ||
text: 'pricing item', | ||
} as PricingItemSearchRequests | ||
|
||
let actualData: any | ||
await act(async () => { | ||
const renderHookResult = renderHook(() => usePricingItemsSearch(pricingItemsSearchRequest)) | ||
const { result } = renderHookResult | ||
await waitUntilQueryIsSuccessful(renderHookResult) | ||
actualData = result.current.data | ||
}) | ||
|
||
expect(PricingItemRepository.findAll).not.toHaveBeenCalled() | ||
expect(PricingItemRepository.search).toHaveBeenCalledWith( | ||
expect.objectContaining(pricingItemsSearchRequest), | ||
) | ||
expect(actualData).toEqual(expectedPricingItem) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { act } from '@testing-library/react-hooks' | ||
|
||
import useUpdatePricingItem from '../../../billing/hooks/useUpdatePricingItem' | ||
import { PricingItemError } from '../../../billing/utils/validate-pricingItem' | ||
import * as validatePricingItem from '../../../billing/utils/validate-pricingItem' | ||
import PricingItemRepository from '../../../shared/db/PricingItemRepository' | ||
import { PricingItem } from '../../../shared/model/PricingItem' | ||
import executeMutation from '../../test-utils/use-mutation.util' | ||
|
||
describe('Use Update Pricing Item', () => { | ||
const expectedPricingItem = { | ||
name: 'pricing item', | ||
category: 'imaging', | ||
price: 100, | ||
} as PricingItem | ||
|
||
jest.spyOn(PricingItemRepository, 'saveOrUpdate').mockResolvedValue(expectedPricingItem) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should update pricing item', async () => { | ||
let actualData: any | ||
|
||
await act(async () => { | ||
actualData = await executeMutation(() => useUpdatePricingItem(), expectedPricingItem) | ||
}) | ||
|
||
expect(PricingItemRepository.saveOrUpdate).toHaveBeenCalledTimes(1) | ||
expect(PricingItemRepository.saveOrUpdate).toHaveBeenCalledWith(expectedPricingItem) | ||
expect(actualData).toEqual(expectedPricingItem) | ||
}) | ||
|
||
it('should return errors', async () => { | ||
rsousaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect.hasAssertions() | ||
|
||
const expectedErrors = { | ||
message: 'error message', | ||
name: 'error name', | ||
price: 'error price', | ||
category: 'error category', | ||
} as PricingItemError | ||
|
||
jest.spyOn(validatePricingItem, 'validateUpdatePricingItem').mockReturnValue(expectedErrors) | ||
|
||
try { | ||
await executeMutation(() => useUpdatePricingItem(), expectedPricingItem) | ||
} catch (e) { | ||
expect(e).toEqual(expectedErrors) | ||
expect(PricingItemRepository.saveOrUpdate).not.toHaveBeenCalled() | ||
} | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.