Skip to content

Commit

Permalink
test(add contacts metadata reducers and selectors tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
sixtedemaupeou committed Jun 28, 2018
1 parent 8325f88 commit 532b125
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
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)
})
})
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)
})
})

0 comments on commit 532b125

Please sign in to comment.