| Total Complexity | 4 |
| Complexity/F | 1 |
| Lines of Code | 68 |
| Function Count | 4 |
| Duplicated Lines | 68 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | View Code Duplication | 'use strict'; |
|
|
|
|||
| 2 | |||
| 3 | var test = require( 'tape-catch' ), |
||
| 4 | salutationIsValid = require( '../../../lib/state_aggregation/donation/salutation_is_valid' ) |
||
| 5 | ; |
||
| 6 | |||
| 7 | test( 'Salutation is undetermined for non-private address', function ( t ) { |
||
| 8 | var state = { |
||
| 9 | donationFormContent: { |
||
| 10 | addressType: 'firma', |
||
| 11 | salutation: '' |
||
| 12 | } |
||
| 13 | }, |
||
| 14 | expectedValidation = { |
||
| 15 | isValid: null, |
||
| 16 | dataEntered: false |
||
| 17 | }; |
||
| 18 | t.deepEqual( salutationIsValid( state ), expectedValidation ); |
||
| 19 | t.end(); |
||
| 20 | } ); |
||
| 21 | |||
| 22 | test( 'Salutation is undetermined when no names are given for private address', function ( t ) { |
||
| 23 | var state = { |
||
| 24 | donationFormContent: { |
||
| 25 | addressType: 'person', |
||
| 26 | firstName: '', |
||
| 27 | lastName: '', |
||
| 28 | salutation: '' |
||
| 29 | } |
||
| 30 | }, |
||
| 31 | expectedValidation = { |
||
| 32 | isValid: null, |
||
| 33 | dataEntered: false |
||
| 34 | }; |
||
| 35 | t.deepEqual( salutationIsValid( state ), expectedValidation ); |
||
| 36 | t.end(); |
||
| 37 | } ); |
||
| 38 | |||
| 39 | test( 'Salutation is invalid when names are given for private address and salutation is empty', function ( t ) { |
||
| 40 | var state = { |
||
| 41 | donationFormContent: { |
||
| 42 | addressType: 'person', |
||
| 43 | firstName: 'Kylo', |
||
| 44 | lastName: 'Ren', |
||
| 45 | salutation: '' |
||
| 46 | } |
||
| 47 | }, |
||
| 48 | expectedValidation = { |
||
| 49 | isValid: false, |
||
| 50 | dataEntered: true |
||
| 51 | }; |
||
| 52 | t.deepEqual( salutationIsValid( state ), expectedValidation ); |
||
| 53 | t.end(); |
||
| 54 | } ); |
||
| 55 | |||
| 56 | test( 'Salutation is valid when salutation is given', function ( t ) { |
||
| 57 | var state = { |
||
| 58 | donationFormContent: { |
||
| 59 | salutation: 'Herr' |
||
| 60 | } |
||
| 61 | }, |
||
| 62 | expectedValidation = { |
||
| 63 | isValid: true, |
||
| 64 | dataEntered: true |
||
| 65 | }; |
||
| 66 | t.deepEqual( salutationIsValid( state ), expectedValidation ); |
||
| 67 | t.end(); |
||
| 68 | } ); |