-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UINV-469: Display all invoice versions in change log in fourth pane (#…
…825) * UINV-469: Display all invoice versions in change log in fourth pane * test: update snapshot * test: add test coverages * test: improve test coverage * refactor: improve `useInvoiceVersions` hook
- Loading branch information
1 parent
aefea48
commit 0fe2ff1
Showing
16 changed files
with
491 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 @@ | ||
export { useInvoiceVersions } from './useInvoiceVersions'; |
This file contains 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,34 @@ | ||
import { useQuery } from 'react-query'; | ||
|
||
import { | ||
useNamespace, | ||
useOkapiKy, | ||
} from '@folio/stripes/core'; | ||
|
||
import { AUDIT_INVOICE_API } from '../../constants'; | ||
|
||
const DEFAULT_VALUE = []; | ||
|
||
export const useInvoiceVersions = (invoiceId, options = {}) => { | ||
const ky = useOkapiKy(); | ||
const [namespace] = useNamespace({ key: 'invoice-versions' }); | ||
|
||
const searchParams = { | ||
sortBy: 'event_date', | ||
sortOrder: 'desc', | ||
}; | ||
|
||
const { isLoading, data } = useQuery( | ||
[namespace, invoiceId], | ||
({ signal }) => ky.get(`${AUDIT_INVOICE_API}/${invoiceId}`, { signal, searchParams }).json(), | ||
{ | ||
enabled: Boolean(invoiceId), | ||
...options, | ||
}, | ||
); | ||
|
||
return { | ||
isLoading, | ||
versions: data?.invoiceAuditEvents || DEFAULT_VALUE, | ||
}; | ||
}; |
50 changes: 50 additions & 0 deletions
50
src/common/hooks/useInvoiceVersions/useInvoiceVersions.test.js
This file contains 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,50 @@ | ||
import { | ||
QueryClient, | ||
QueryClientProvider, | ||
} from 'react-query'; | ||
|
||
import { | ||
renderHook, | ||
waitFor, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { useInvoiceVersions } from './useInvoiceVersions'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
const invoiceId = 'invoiceId'; | ||
const invoiceAuditEvents = [ | ||
{ | ||
id: '1', | ||
invoiceId: 'invoiceId', | ||
total: 100, | ||
}, | ||
{ | ||
id: '2', | ||
invoiceId: 'invoiceId', | ||
total: 200, | ||
}, | ||
]; | ||
|
||
describe('useInvoiceVersions', () => { | ||
it('should return invoice versions', async () => { | ||
useOkapiKy.mockClear().mockReturnValue({ | ||
get: () => ({ | ||
json: () => ({ invoiceAuditEvents }), | ||
}), | ||
}); | ||
|
||
const { result } = renderHook(() => useInvoiceVersions(invoiceId), { wrapper }); | ||
|
||
await waitFor(() => expect(result.current.isLoading).toBeFalsy()); | ||
|
||
expect(result.current.versions).toHaveLength(invoiceAuditEvents.length); | ||
}); | ||
}); |
This file contains 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 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 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 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 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
Oops, something went wrong.