Completed
Push — master ( e193d1...415e1b )
by Justin
01:32
created

AtomEntry.js ➔ describe(ꞌAtomEntryꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 128

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 128
rs 8.2857

5 Functions

Rating   Name   Duplication   Size   Complexity  
A AtomEntry.js ➔ ... ➔ it(ꞌtoJSONꞌ) 0 3 1
A AtomEntry.js ➔ ... ➔ it(ꞌCreate with JSONꞌ) 0 3 1
A AtomEntry.js ➔ ... ➔ it(ꞌCreate plainꞌ) 0 4 1
A AtomEntry.js ➔ ... ➔ it(ꞌconstructor does not copy instancesꞌ) 0 5 1
A AtomEntry.js ➔ ... ➔ it(ꞌBuildꞌ) 0 52 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('AtomEntry', function(){
5
  
6
  var json = {
7
    authors: [
8
      {
9
        name: 'author',
10
        email: '[email protected]'
11
      }  
12
    ],
13
    contributors: [
14
      {
15
        name: 'contributor',
16
        email: '[email protected]'
17
      }  
18
    ],
19
    categories: [
20
      {
21
        scheme: 'scheme',
22
        term: 'term',
23
        label: 'label'
24
      }
25
    ],
26
    generator: {
27
      uri: 'uri',
28
      version: 'version',
29
      value: 'value'
30
    },
31
    icon: 'icon',
32
    id: 'id',
33
    links: {
34
      rel: {
35
        href: 'href'
36
      }
37
    },
38
    logo: 'logo',
39
    rights: 'rights',
40
    subtitle: 'subtitle',
41
    title: 'title',
42
    updated: 123456789,
43
    content: {
44
      gedcomx: {
45
        description: '#root'
46
      }
47
    },
48
    confidence: 4,
49
    published: 123456780,
50
    source: {
51
      logo: 'logo',
52
      rights: 'rights',
53
      subtitle: 'subtitle'
54
    },
55
    summary: 'summary',
56
    score: 122.32
57
  };
58
  
59
  it('Create plain', function(){
60
    assert.instanceOf(new GedcomX.AtomEntry(), GedcomX.AtomEntry, 'An instance of AtomEntry is not returned when calling the constructor with new.');
61
    assert.instanceOf(GedcomX.AtomEntry(), GedcomX.AtomEntry, 'An instance of AtomEntry is not returned when calling the constructor without new.');
62
  });
63
  
64
  it('Create with JSON', function(){
65
    tests(GedcomX.AtomEntry(json));
66
  });
67
  
68
  it('Build', function(){
69
    tests(GedcomX.AtomEntry()
70
      .addAuthor(
71
        GedcomX.AtomPerson()
72
          .setName('author')
73
          .setEmail('[email protected]')
74
      )
75
      .addContributor(
76
        GedcomX.AtomPerson()
77
          .setName('contributor')
78
          .setEmail('[email protected]')
79
      )
80
      .addCategory(
81
        GedcomX.AtomCategory()
82
          .setScheme('scheme')
83
          .setTerm('term')
84
          .setLabel('label')
85
      )
86
      .setGenerator(
87
        GedcomX.AtomGenerator()
88
          .setUri('uri')
89
          .setVersion('version')
90
          .setValue('value')
91
      )
92
      .setIcon('icon')
93
      .setId('id')
94
      .addLink(
95
        GedcomX.Link()
96
          .setRel('rel')
97
          .setHref('href')
98
      )
99
      .setLogo('logo')
100
      .setRights('rights')
101
      .setSubtitle('subtitle')
102
      .setTitle('title')
103
      .setUpdated(123456789)
104
      .setConfidence(4)
105
      .setPublished(123456780)
106
      .setSummary('summary')
107
      .setScore(122.32)
108
      .setContent({
109
        gedcomx: {
110
          description: '#root'
111
        }
112
      })
113
      .setSource({
114
        logo: 'logo',
115
        rights: 'rights',
116
        subtitle: 'subtitle'
117
      })
118
    );
119
  });
120
  
121
  it('toJSON', function(){
122
    assert.deepEqual(GedcomX.AtomEntry(json).toJSON(), json);
123
  });
124
  
125
  it('constructor does not copy instances', function(){
126
    var obj1 = GedcomX.AtomEntry();
127
    var obj2 = GedcomX.AtomEntry(obj1);
128
    assert.strictEqual(obj1, obj2);
129
  });
130
  
131
});
132
133
function tests(entry){
134
  assert.equal(entry.getAuthors().length, 1);
135
  var author = entry.getAuthors()[0];
136
  assert.equal(author.getName(), 'author');
137
  assert.equal(author.getEmail(), '[email protected]');
138
  
139
  assert.equal(entry.getContributors().length, 1);
140
  var contributor = entry.getContributors()[0];
141
  assert.equal(contributor.getName(), 'contributor');
142
  assert.equal(contributor.getEmail(), '[email protected]');
143
  
144
  assert.equal(entry.getCategories().length, 1);
145
  var category = entry.getCategories()[0];
146
  assert.equal(category.getScheme(), 'scheme');
147
  assert.equal(category.getTerm(), 'term');
148
  assert.equal(category.getLabel(), 'label');
149
  
150
  var generator = entry.getGenerator();
151
  assert.equal(generator.getUri(), 'uri');
152
  assert.equal(generator.getVersion(), 'version');
153
  assert.equal(generator.getValue(), 'value');
154
  
155
  assert.equal(entry.getIcon(), 'icon');
156
  assert.equal(entry.getId(), 'id');
157
  assert.equal(entry.getLinks().length, 1);
158
  assert.equal(entry.getLink('rel').getHref(), 'href');
159
  assert.equal(entry.getLogo(), 'logo');
160
  assert.equal(entry.getRights(), 'rights');
161
  assert.equal(entry.getSubtitle(), 'subtitle');
162
  assert.equal(entry.getTitle(), 'title');
163
  assert.equal(entry.getUpdated().getTime(), 123456789);
164
  assert.equal(entry.getConfidence(), 4);
165
  assert.equal(entry.getPublished().getTime(), 123456780);
166
  assert.equal(entry.getSummary(), 'summary');
167
  assert.equal(entry.getScore(), 122.32);
168
  
169
  var content = entry.getContent();
170
  assert.equal(content.getGedcomX().getDescription(), '#root');
171
  
172
  var source = entry.getSource();
173
  assert.equal(source.getLogo(), 'logo');
174
  assert.equal(source.getRights(), 'rights');
175
  assert.equal(source.getSubtitle(), 'subtitle');
176
}