Completed
Push — master ( 597fc8...850b65 )
by Justin
02:13
created

AtomFeed.js ➔ describe(ꞌAtomFeedꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 108

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 108
rs 8.2857

5 Functions

Rating   Name   Duplication   Size   Complexity  
B AtomFeed.js ➔ ... ➔ it(ꞌBuildꞌ) 0 41 1
A AtomFeed.js ➔ ... ➔ it(ꞌCreate plainꞌ) 0 4 1
A AtomFeed.js ➔ ... ➔ it(ꞌCreate with JSONꞌ) 0 3 1
A AtomFeed.js ➔ ... ➔ it(ꞌconstructor does not copy instancesꞌ) 0 5 1
A AtomFeed.js ➔ ... ➔ it(ꞌtoJSONꞌ) 0 3 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('AtomFeed', 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
    generator: {
20
      uri: 'uri',
21
      version: 'version',
22
      value: 'value'
23
    },
24
    icon: 'icon',
25
    id: 'id',
26
    results: 5,
27
    links: {
28
      rel: {
29
        href: 'href'
30
      }
31
    },
32
    logo: 'logo',
33
    rights: 'rights',
34
    subtitle: 'subtitle',
35
    title: 'title',
36
    updated: 123456789,
37
    entries: [
38
      {
39
        title: 'Entry title',
40
        summary: 'Summary'
41
      }
42
    ],
43
    facets: [
44
      {
45
        type: 'fieldType'
46
      }
47
    ]
48
  };
49
  
50
  it('Create plain', function(){
51
    assert.instanceOf(new GedcomX.AtomFeed(), GedcomX.AtomFeed, 'An instance of AtomFeed is not returned when calling the constructor with new.');
52
    assert.instanceOf(GedcomX.AtomFeed(), GedcomX.AtomFeed, 'An instance of AtomFeed is not returned when calling the constructor without new.');
53
  });
54
  
55
  it('Create with JSON', function(){
56
    tests(GedcomX.AtomFeed(json));
57
  });
58
  
59
  it('Build', function(){
60
    tests(GedcomX.AtomFeed()
61
      .addAuthor(
62
        GedcomX.AtomPerson()
63
          .setName('author')
64
          .setEmail('[email protected]')
65
      )
66
      .addContributor(
67
        GedcomX.AtomPerson()
68
          .setName('contributor')
69
          .setEmail('[email protected]')
70
      )
71
      .setGenerator(
72
        GedcomX.AtomGenerator()
73
          .setUri('uri')
74
          .setVersion('version')
75
          .setValue('value')
76
      )
77
      .setIcon('icon')
78
      .setId('id')
79
      .setResults(5)
80
      .addLink(
81
        GedcomX.Link()
82
          .setRel('rel')
83
          .setHref('href')
84
      )
85
      .setLogo('logo')
86
      .setRights('rights')
87
      .setSubtitle('subtitle')
88
      .setTitle('title')
89
      .setUpdated(123456789)
90
      .addEntry(
91
        GedcomX.AtomEntry()
92
          .setTitle('Entry title')
93
          .setSummary('Summary')
94
      )
95
      .addFacet(
96
        GedcomX.Field().setType('fieldType')
97
      )
98
    );
99
  });
100
  
101
  it('toJSON', function(){
102
    assert.deepEqual(GedcomX.AtomFeed(json).toJSON(), json);
103
  });
104
  
105
  it('constructor does not copy instances', function(){
106
    var obj1 = GedcomX.AtomFeed();
107
    var obj2 = GedcomX.AtomFeed(obj1);
108
    assert.strictEqual(obj1, obj2);
109
  });
110
  
111
});
112
113
function tests(feed){
114
  assert.equal(feed.getAuthors().length, 1);
115
  var author = feed.getAuthors()[0];
116
  assert.equal(author.getName(), 'author');
117
  assert.equal(author.getEmail(), '[email protected]');
118
  
119
  assert.equal(feed.getContributors().length, 1);
120
  var contributor = feed.getContributors()[0];
121
  assert.equal(contributor.getName(), 'contributor');
122
  assert.equal(contributor.getEmail(), '[email protected]');
123
  
124
  var generator = feed.getGenerator();
125
  assert.equal(generator.getUri(), 'uri');
126
  assert.equal(generator.getVersion(), 'version');
127
  assert.equal(generator.getValue(), 'value');
128
  
129
  assert.equal(feed.getIcon(), 'icon');
130
  assert.equal(feed.getId(), 'id');
131
  assert.equal(feed.getLinks().length, 1);
132
  assert.equal(feed.getLink('rel').getHref(), 'href');
133
  assert.equal(feed.getLogo(), 'logo');
134
  assert.equal(feed.getRights(), 'rights');
135
  assert.equal(feed.getSubtitle(), 'subtitle');
136
  assert.equal(feed.getTitle(), 'title');
137
  assert.equal(feed.getUpdated().getTime(), 123456789);
138
139
  var entry = feed.getEntries()[0];
140
  assert.equal(entry.getTitle(), 'Entry title');
141
  assert.equal(entry.getSummary(), 'Summary');
142
  
143
  var field = feed.getFacets()[0];
144
  assert.equal(field.getType(), 'fieldType');
145
}