Completed
Push — master ( a4cfd2...abd258 )
by Justin
01:45
created

SourceDescription.js ➔ ... ➔ it(ꞌBuildꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 31
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
nop 0
dl 31
loc 31
rs 8.8571
1 View Code Duplication
var assert = require('chai').assert,
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    GedcomX = require('../../');
3
4
describe('SourceDescription', function(){
5
  
6
  var fullJSON = {
7
    resourceType: 'http://some/type',
8
    citations: [
9
      {
10
        lang: 'en',
11
        value: 'Long source citation'
12
      }
13
    ],
14
    mediaType: 'book',
15
    about: 'http://a/resource',
16
    mediator: {
17
      resource: 'http://mediator'
18
    },
19
    sources: [
20
      {
21
        description: 'http://source/reference'
22
      }
23
    ],
24
    analysis: {
25
      resource: 'http://analysis'
26
    },
27
    componentOf: {
28
      description: 'http://container'
29
    },
30
    titles: [
31
      {
32
        lang: 'en',
33
        value: 'Title'
34
      },
35
      {
36
        lang: 'es',
37
        value: 'Titulo'
38
      }
39
    ],
40
    notes: [
41
      {
42
        subject: 'Note',
43
        text: 'Some note text'
44
      }
45
    ],
46
    attribution: {
47
      created: 1234578129
48
    },
49
    rights: [
50
      {
51
        resource: 'https://some/right'
52
      }
53
    ],
54
    coverage: [{
55
      temporal: {
56
        formal: '+2015'
57
      },
58
      spatial: {
59
        original: 'A place'
60
      }
61
    }],
62
    descriptions: [
63
      {
64
        value: 'A description'
65
      }
66
    ],
67
    identifiers: {
68
      $: 'identifier'
69
    },
70
    created: 1000000,
71
    modified: 11111111,
72
    sortKey: '123456',
73
    version: '123',
74
    repository: {
75
      resource: 'http://repository'
76
    }
77
  };
78
  
79
  it('Create with JSON', function(){
80
    var description = GedcomX.SourceDescription(fullJSON);
81
    tests(description);
82
  });
83
  
84
  it('Build', function(){
85
    var description = GedcomX.SourceDescription()
86
      .setResourceType('http://some/type')
87
      .addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation'))
88
      .setMediaType('book')
89
      .setAbout('http://a/resource')
90
      .setMediator(GedcomX.ResourceReference().setResource('http://mediator'))
91
      .addSource(GedcomX.SourceReference().setDescription('http://source/reference'))
92
      .setAnalysis(GedcomX.ResourceReference().setResource('http://analysis'))
93
      .setComponentOf(GedcomX.SourceReference().setDescription('http://container'))
94
      .addTitle(GedcomX.TextValue().setLang('en').setValue('Title'))
95
      .addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo'))
96
      .addNote(GedcomX.Note().setSubject('Note').setText('Some note text'))
97
      .setAttribution(GedcomX.Attribution().setCreated(1234578129))
98
      .addRight(GedcomX.ResourceReference().setResource('https://some/right'))
99
      .addCoverage(
100
        GedcomX.Coverage()
101
          .setTemporal(GedcomX.Date().setFormal('+2015'))
102
          .setSpatial(GedcomX.PlaceReference().setOriginal('A place'))
103
      )
104
      .addDescription(GedcomX.TextValue().setValue('A description'))
105
      .setIdentifiers(GedcomX.Identifiers({
106
        $: 'identifier'
107
      }))
108
      .setCreated(1000000)
109
      .setModified(11111111)
110
      .setSortKey('123456')
111
      .setVersion('123')
112
      .setRepository(GedcomX.ResourceReference().setResource('http://repository'));
113
    tests(description);
114
  });
115
  
116
  it('toJSON', function(){
117
    var description = GedcomX.SourceDescription(fullJSON);
118
    assert.deepEqual(description.toJSON(), fullJSON);
119
  });
120
  
121
});
122
123
function tests(description){
124
  assert.equal(description.getResourceType(), 'http://some/type');
125
  assert.equal(description.getCitations().length, 1);
126
  assert.equal(description.getCitations()[0].getLang(), 'en');
127
  assert.equal(description.getCitations()[0].getValue(), 'Long source citation');
128
  assert.equal(description.getMediaType(), 'book');
129
  assert.equal(description.getAbout(), 'http://a/resource');
130
  assert.equal(description.getMediator().getResource(), 'http://mediator');
131
  assert.equal(description.getSources().length, 1);
132
  assert.equal(description.getSources()[0].getDescription(), 'http://source/reference');
133
  assert.equal(description.getAnalysis().getResource(), 'http://analysis');
134
  assert.equal(description.getComponentOf().getDescription(), 'http://container');
135
  assert.equal(description.getTitles().length, 2);
136
  assert.equal(description.getTitles()[0].getLang(), 'en');
137
  assert.equal(description.getTitles()[0].getValue(), 'Title');
138
  assert.equal(description.getTitles()[1].getLang(), 'es');
139
  assert.equal(description.getTitles()[1].getValue(), 'Titulo');
140
  assert.equal(description.getNotes().length, 1);
141
  assert.equal(description.getNotes()[0].getSubject(), 'Note');
142
  assert.equal(description.getNotes()[0].getText(), 'Some note text');
143
  assert.equal(description.getAttribution().getCreated().getTime(), 1234578129);
144
  assert.equal(description.getRights().length, 1);
145
  assert.equal(description.getRights()[0].getResource(), 'https://some/right');
146
  assert.equal(description.getCoverage().length, 1);
147
  assert.equal(description.getCoverage()[0].getTemporal().getFormal(), '+2015');
148
  assert.equal(description.getCoverage()[0].getSpatial().getOriginal(), 'A place');
149
  assert.equal(description.getDescriptions().length, 1);
150
  assert.equal(description.getDescriptions()[0].getValue(), 'A description');
151
  assert.equal(description.getIdentifiers().identifiers.$, 'identifier');
152
  assert.equal(description.getCreated(), 1000000);
153
  assert.equal(description.getModified(), 11111111);
154
  assert.equal(description.getSortKey(), '123456');
155
  assert.equal(description.getVersion(), '123');
156
  assert.equal(description.getRepository().getResource(), 'http://repository');
157
}