Completed
Push — master ( ebbfd2...019445 )
by Jeroen De
62:46
created

NISH_XXX_VALIDATION actions do not modify stateꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 12
rs 9.4285
c 1
b 0
f 0
1
'use strict';
2
3
var test = require( 'tape' ),
4
	deepFreeze = require( 'deep-freeze' ),
5
	asyncRequests = require( '../../lib/reducers/async_requests' );
6
7
test( 'there are no asynchronous processes when starting out', function ( t ) {
8
	var expectedState = { isValidating: false, runningValidations: 0 },
9
		action = { type: 'DUMMY_ACTION' };
10
11
	t.deepEqual( asyncRequests( undefined, action ), expectedState );
12
	t.end();
13
} );
14
15
test( 'BEGIN_XXX_VALIDATION actions increase counter and change isValidating ', function ( t ) {
16
17
	var stateBefore = { isValidating: false, runningValidations: 0 },
18
		expectedStateAfterFirstAction = { isValidating: true, runningValidations: 1 },
19
		expectedStateAfterSecondAction = { isValidating: true, runningValidations: 2 },
20
		action = { type: 'BEGIN_PAYMENT_DATA_VALIDATION', payload: { amount: '25,00', paymentType: 'BEZ' } };
21
22
	deepFreeze( stateBefore );
23
	t.deepEqual( asyncRequests( stateBefore, action ), expectedStateAfterFirstAction );
24
	deepFreeze( expectedStateAfterFirstAction );
25
	t.deepEqual( asyncRequests( expectedStateAfterFirstAction, action ), expectedStateAfterSecondAction );
26
	t.end();
27
28
} );
29
30
test( 'FINISH_XXX_VALIDATION actions decrease counter and change isValidating ', function ( t ) {
31
32
	var initialState = { isValidating: false, runningValidations: 0 },
33
		expectedStateAfterFirstAction = { isValidating: true, runningValidations: 1 },
34
		expectedStateAfterSecondAction = { isValidating: false, runningValidations: 0 },
35
		beginAction = { type: 'BEGIN_PAYMENT_DATA_VALIDATION', payload: { amount: '25,00', paymentType: 'BEZ' } },
36
		finishAction = { type: 'FINISH_PAYMENT_DATA_VALIDATION', payload: { status: 'OK' } },
37
		stateBefore, stateAfterOneFinishAction;
38
39
	stateBefore = asyncRequests( asyncRequests( initialState, beginAction ), beginAction );
40
	deepFreeze( stateBefore );
41
42
	stateAfterOneFinishAction = asyncRequests( stateBefore, finishAction );
43
	t.deepEqual( stateAfterOneFinishAction, expectedStateAfterFirstAction );
44
	deepFreeze( expectedStateAfterFirstAction );
45
	t.deepEqual( asyncRequests( expectedStateAfterFirstAction, finishAction ), expectedStateAfterSecondAction );
46
	t.end();
47
48
} );
49
50
test( 'Additional FINISH_XXX_VALIDATION actions do not modify state', function ( t ) {
51
52
	var initialState = { isValidating: false, runningValidations: 0 },
53
		action = { type: 'FINISH_PAYMENT_DATA_VALIDATION', payload: { status: 'OK' } };
54
55
	deepFreeze( initialState );
56
57
	t.equal( asyncRequests( initialState, action ), initialState  );
58
59
	t.end();
60
61
} );
62