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

app/js/tests/reducers/test_async_requests.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 61
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 61
rs 10
c 1
b 0
f 0
wmc 4
mnd 0
bc 4
fnc 4
bpm 1
cpm 1
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_async_requests.js ➔ test(ꞌFINISH_XXX_VALIDATION actions decrease counter and change isValidating ꞌ) 0 19 1
A test_async_requests.js ➔ test(ꞌthere are no asynchronous processes when starting outꞌ) 0 7 1
A test_async_requests.js ➔ test(ꞌBEGIN_XXX_VALIDATION actions increase counter and change isValidating ꞌ) 0 14 1
A test_async_requests.js ➔ test(ꞌAdditional FINISH_XXX_VALIDATION actions do not modify stateꞌ) 0 12 1
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