2020-06-04 01:59:57 -05:00
|
|
|
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
|
|
|
import {
|
|
|
|
initialTransactionState,
|
|
|
|
transactionReducer,
|
2021-02-17 23:21:35 -06:00
|
|
|
TransactionState,
|
2020-06-04 01:59:57 -05:00
|
|
|
TransactionStatus,
|
|
|
|
variablesClearTransaction,
|
|
|
|
variablesCompleteTransaction,
|
|
|
|
variablesInitTransaction,
|
|
|
|
} from './transactionReducer';
|
|
|
|
|
|
|
|
describe('transactionReducer', () => {
|
|
|
|
describe('when variablesInitTransaction is dispatched', () => {
|
|
|
|
it('then state should be correct', () => {
|
2021-02-17 23:21:35 -06:00
|
|
|
reducerTester<TransactionState>()
|
2020-06-04 01:59:57 -05:00
|
|
|
.givenReducer(transactionReducer, { ...initialTransactionState })
|
|
|
|
.whenActionIsDispatched(variablesInitTransaction({ uid: 'a uid' }))
|
|
|
|
.thenStateShouldEqual({ ...initialTransactionState, uid: 'a uid', status: TransactionStatus.Fetching });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when variablesCompleteTransaction is dispatched', () => {
|
|
|
|
describe('and transaction uid is the same', () => {
|
|
|
|
it('then state should be correct', () => {
|
2021-02-17 23:21:35 -06:00
|
|
|
reducerTester<TransactionState>()
|
2020-06-04 01:59:57 -05:00
|
|
|
.givenReducer(transactionReducer, {
|
|
|
|
...initialTransactionState,
|
|
|
|
uid: 'before',
|
|
|
|
status: TransactionStatus.Fetching,
|
|
|
|
})
|
|
|
|
.whenActionIsDispatched(variablesCompleteTransaction({ uid: 'before' }))
|
|
|
|
.thenStateShouldEqual({ ...initialTransactionState, uid: 'before', status: TransactionStatus.Completed });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and transaction uid is not the same', () => {
|
|
|
|
it('then state should be correct', () => {
|
2021-02-17 23:21:35 -06:00
|
|
|
reducerTester<TransactionState>()
|
2020-06-04 01:59:57 -05:00
|
|
|
.givenReducer(transactionReducer, {
|
|
|
|
...initialTransactionState,
|
|
|
|
uid: 'before',
|
|
|
|
status: TransactionStatus.Fetching,
|
|
|
|
})
|
|
|
|
.whenActionIsDispatched(variablesCompleteTransaction({ uid: 'after' }))
|
|
|
|
.thenStateShouldEqual({ ...initialTransactionState, uid: 'before', status: TransactionStatus.Fetching });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when variablesClearTransaction is dispatched', () => {
|
|
|
|
it('then state should be correct', () => {
|
2021-02-17 23:21:35 -06:00
|
|
|
reducerTester<TransactionState>()
|
2020-06-04 01:59:57 -05:00
|
|
|
.givenReducer(transactionReducer, {
|
|
|
|
...initialTransactionState,
|
|
|
|
uid: 'before',
|
|
|
|
status: TransactionStatus.Completed,
|
|
|
|
})
|
|
|
|
.whenActionIsDispatched(variablesClearTransaction())
|
|
|
|
.thenStateShouldEqual({ ...initialTransactionState });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|