-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from docknetwork/DCKW-642-i-os-771-unable-to-…
…fetch-issuers-echosystem-message-is-displayed-on-credential-details-screen fixing issues with ecosystem fetch
- Loading branch information
Showing
2 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
packages/react-native/lib/ecosystem-tools/ecosystemHooks.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,74 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useEcosystems } from './ecosystemHooks'; | ||
import { getEcosystems } from '@docknetwork/wallet-sdk-core/src/ecosystem-tools'; | ||
import { getWallet } from '../wallet'; | ||
import { captureException } from '@docknetwork/wallet-sdk-core/src/helpers'; | ||
|
||
jest.mock('@docknetwork/wallet-sdk-core/src/ecosystem-tools', () => ({ | ||
getEcosystems: jest.fn(), | ||
})); | ||
|
||
jest.mock('../wallet', () => ({ | ||
getWallet: jest.fn(), | ||
})); | ||
|
||
jest.mock('@docknetwork/wallet-sdk-core/src/helpers', () => ({ | ||
captureException: jest.fn(), | ||
})); | ||
|
||
const mockEcosystems = { | ||
eco1: { govFramework: 'hex-url-1' }, | ||
eco2: { govFramework: 'hex-url-2' }, | ||
}; | ||
|
||
const mockWallet = { | ||
getNetworkId: jest.fn(() => 'test-network'), | ||
}; | ||
|
||
getWallet.mockReturnValue(mockWallet); | ||
|
||
describe('useEcosystems', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should fetch and format ecosystem data', async () => { | ||
getEcosystems.mockResolvedValue(mockEcosystems); | ||
|
||
const { result, waitForNextUpdate } = renderHook(() => | ||
useEcosystems({ issuer: 'issuerId', verifier: 'verifierId', schemaId: 'schemaId' }) | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitForNextUpdate(); | ||
|
||
expect(getEcosystems).toHaveBeenCalledWith({ | ||
issuerDID: 'issuerId', | ||
verifierDID: 'verifierId', | ||
schemaId: 'schemaId', | ||
networkId: 'test-network', | ||
}); | ||
|
||
expect(result.current.isLoading).toBe(false); | ||
expect(result.current.isError).toBe(false); | ||
expect(result.current.ecosystems).toEqual(expect.any(Array)); | ||
}); | ||
|
||
it('should handle error while fetching ecosystems', async () => { | ||
const error = new Error('Error fetching ecosystems'); | ||
getEcosystems.mockRejectedValue(error); | ||
|
||
const { result, waitForNextUpdate } = renderHook(() => | ||
useEcosystems({ issuer: 'issuerId', verifier: 'verifierId', schemaId: 'schemaId' }) | ||
); | ||
|
||
expect(result.current.isLoading).toBe(true); | ||
|
||
await waitForNextUpdate(); | ||
|
||
expect(result.current.isLoading).toBe(false); | ||
expect(result.current.isError).toBe(true); | ||
expect(captureException).toHaveBeenCalledWith(error); | ||
}); | ||
}); |
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