-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(add contacts metadata reducers and selectors tests)
- Loading branch information
1 parent
8325f88
commit 532b125
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/blockchain-wallet-v4/src/redux/kvStore/contacts/reducers.spec.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,47 @@ | ||
import { set } from 'ramda' | ||
import Remote from '../../../remote' | ||
import { KVStoreEntry } from '../../../types' | ||
import { derivationMap, CONTACTS } from '../config' | ||
import reducer from './reducers' | ||
import * as actions from './actions' | ||
|
||
const INITIAL_STATE = Remote.NotAsked | ||
|
||
describe('kvStore contacts reducers', () => { | ||
const typeId = derivationMap[CONTACTS] | ||
|
||
const contactsMetadata = set(KVStoreEntry.value, | ||
{/* Enter mock contacts objects here */}, | ||
KVStoreEntry.createEmpty(typeId)) | ||
|
||
const contactsMetadataSuccess = Remote.Success(contactsMetadata) | ||
|
||
it('should return the initial state', () => { | ||
expect(reducer(undefined, {})).toEqual(INITIAL_STATE) | ||
}) | ||
|
||
it('should handle FETCH_METADATA_CONTACTS_LOADING', () => { | ||
const action = actions.fetchMetadataContactsLoading() | ||
const expectedState = Remote.Loading | ||
expect(reducer(undefined, action)).toEqual(expectedState) | ||
}) | ||
|
||
it('should handle FETCH_METADATA_CONTACTS_FAILURE', () => { | ||
const error = 'Cannot load contacts metadata' | ||
const action = actions.fetchMetadataContactsFailure(error) | ||
const expectedState = Remote.Failure(error) | ||
expect(reducer(undefined, action)).toEqual(expectedState) | ||
}) | ||
|
||
it('should handle FETCH_METADATA_CONTACTS_SUCCESS', () => { | ||
const action = actions.fetchMetadataContactsSuccess(contactsMetadata) | ||
const expectedState = contactsMetadataSuccess | ||
expect(reducer(undefined, action)).toEqual(expectedState) | ||
}) | ||
|
||
it('should handle CREATE_METADATA_CONTACTS', () => { | ||
const action = actions.createMetadataContacts(contactsMetadata) | ||
const expectedState = contactsMetadataSuccess | ||
expect(reducer(undefined, action)).toEqual(expectedState) | ||
}) | ||
}) |
41 changes: 41 additions & 0 deletions
41
packages/blockchain-wallet-v4/src/redux/kvStore/contacts/selectors.spec.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,41 @@ | ||
import { assocPath } from 'ramda' | ||
import Remote from '../../../remote' | ||
import * as selectors from './selectors' | ||
|
||
describe('kvstore contacts selectors', () => { | ||
const contactsMetadata = {} | ||
|
||
const successState = { | ||
kvStorePath: { | ||
contacts: Remote.Success(contactsMetadata) | ||
} | ||
} | ||
|
||
it('getMetadata should return success of metadata', () => { | ||
const expectedResult = Remote.Success(contactsMetadata) | ||
expect(selectors.getMetadata(successState)).toEqual(expectedResult) | ||
}) | ||
|
||
const loadingState = assocPath( | ||
['kvStorePath', 'contacts'], | ||
Remote.Loading, | ||
successState | ||
) | ||
|
||
it('getMetadata should return metadata loading', () => { | ||
const expectedResult = Remote.Loading | ||
expect(selectors.getMetadata(loadingState)).toEqual(expectedResult) | ||
}) | ||
|
||
const failureState = assocPath( | ||
['kvStorePath', 'contacts'], | ||
Remote.Failure('Failure in contacts metadata'), | ||
successState | ||
) | ||
|
||
it('getMetadata should return metadata failure', () => { | ||
const error = 'Failure in contacts metadata' | ||
const expectedResult = Remote.Failure(error) | ||
expect(selectors.getMetadata(failureState)).toEqual(expectedResult) | ||
}) | ||
}) |