1
|
|
|
var assert = require('chai').assert, |
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
|
|
|
repository: { |
73
|
|
|
resource: 'http://repository' |
74
|
|
|
} |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
it('Create plain', function(){ |
78
|
|
|
assert.instanceOf(new GedcomX.SourceDescription(), GedcomX.SourceDescription, 'An instance of SourceDescription is not returned when calling the constructor with new.'); |
79
|
|
|
assert.instanceOf(GedcomX.SourceDescription(), GedcomX.SourceDescription, 'An instance of SourceDescription is not returned when calling the constructor without new.'); |
80
|
|
|
}); |
81
|
|
|
|
82
|
|
|
it('Create with JSON', function(){ |
83
|
|
|
var description = GedcomX.SourceDescription(fullJSON); |
84
|
|
|
tests(description); |
85
|
|
|
}); |
86
|
|
|
|
87
|
|
|
it('Create with mixed', function(){ |
88
|
|
|
var description = GedcomX.SourceDescription({ |
89
|
|
|
resourceType: 'http://some/type', |
90
|
|
|
citations: [ |
91
|
|
|
GedcomX.SourceCitation({ |
92
|
|
|
lang: 'en', |
93
|
|
|
value: 'Long source citation' |
94
|
|
|
}) |
95
|
|
|
], |
96
|
|
|
mediaType: 'book', |
97
|
|
|
about: 'http://a/resource', |
98
|
|
|
mediator: { |
99
|
|
|
resource: 'http://mediator' |
100
|
|
|
}, |
101
|
|
|
sources: [ |
102
|
|
|
GedcomX.SourceReference({ |
103
|
|
|
description: 'http://source/reference' |
104
|
|
|
}) |
105
|
|
|
], |
106
|
|
|
analysis: { |
107
|
|
|
resource: 'http://analysis' |
108
|
|
|
}, |
109
|
|
|
componentOf: { |
110
|
|
|
description: 'http://container' |
111
|
|
|
}, |
112
|
|
|
titles: [ |
113
|
|
|
GedcomX.TextValue({ |
114
|
|
|
lang: 'en', |
115
|
|
|
value: 'Title' |
116
|
|
|
}), |
117
|
|
|
{ |
118
|
|
|
lang: 'es', |
119
|
|
|
value: 'Titulo' |
120
|
|
|
} |
121
|
|
|
], |
122
|
|
|
notes: [ |
123
|
|
|
GedcomX.Note({ |
124
|
|
|
subject: 'Note', |
125
|
|
|
text: 'Some note text' |
126
|
|
|
}) |
127
|
|
|
], |
128
|
|
|
attribution: { |
129
|
|
|
created: 1234578129 |
130
|
|
|
}, |
131
|
|
|
rights: [ |
132
|
|
|
GedcomX.ResourceReference({ |
133
|
|
|
resource: 'https://some/right' |
134
|
|
|
}) |
135
|
|
|
], |
136
|
|
|
coverage: [GedcomX.Coverage({ |
137
|
|
|
temporal: { |
138
|
|
|
formal: '+2015' |
139
|
|
|
}, |
140
|
|
|
spatial: { |
141
|
|
|
original: 'A place' |
142
|
|
|
} |
143
|
|
|
})], |
144
|
|
|
descriptions: [ |
145
|
|
|
{ |
146
|
|
|
value: 'A description' |
147
|
|
|
} |
148
|
|
|
], |
149
|
|
|
identifiers: { |
150
|
|
|
$: 'identifier' |
151
|
|
|
}, |
152
|
|
|
created: 1000000, |
153
|
|
|
modified: 11111111, |
154
|
|
|
repository: GedcomX.ResourceReference({ |
155
|
|
|
resource: 'http://repository' |
156
|
|
|
}) |
157
|
|
|
}); |
158
|
|
|
tests(description); |
159
|
|
|
}); |
160
|
|
|
|
161
|
|
|
it('Build', function(){ |
162
|
|
|
var description = GedcomX.SourceDescription() |
163
|
|
|
.setResourceType('http://some/type') |
164
|
|
|
.addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation')) |
165
|
|
|
.setMediaType('book') |
166
|
|
|
.setAbout('http://a/resource') |
167
|
|
|
.setMediator(GedcomX.ResourceReference().setResource('http://mediator')) |
168
|
|
|
.addSource(GedcomX.SourceReference().setDescription('http://source/reference')) |
169
|
|
|
.setAnalysis(GedcomX.ResourceReference().setResource('http://analysis')) |
170
|
|
|
.setComponentOf(GedcomX.SourceReference().setDescription('http://container')) |
171
|
|
|
.addTitle(GedcomX.TextValue().setLang('en').setValue('Title')) |
172
|
|
|
.addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo')) |
173
|
|
|
.addNote(GedcomX.Note().setSubject('Note').setText('Some note text')) |
174
|
|
|
.setAttribution(GedcomX.Attribution().setCreated(1234578129)) |
175
|
|
|
.addRight(GedcomX.ResourceReference().setResource('https://some/right')) |
176
|
|
|
.addCoverage( |
177
|
|
|
GedcomX.Coverage() |
178
|
|
|
.setTemporal(GedcomX.Date().setFormal('+2015')) |
179
|
|
|
.setSpatial(GedcomX.PlaceReference().setOriginal('A place')) |
180
|
|
|
) |
181
|
|
|
.addDescription(GedcomX.TextValue().setValue('A description')) |
182
|
|
|
.setIdentifiers(GedcomX.Identifiers({ |
183
|
|
|
$: 'identifier' |
184
|
|
|
})) |
185
|
|
|
.setCreated(1000000) |
186
|
|
|
.setModified(11111111) |
187
|
|
|
.setRepository(GedcomX.ResourceReference().setResource('http://repository')); |
188
|
|
|
tests(description); |
189
|
|
|
}); |
190
|
|
|
|
191
|
|
|
it('toJSON', function(){ |
192
|
|
|
var description = GedcomX.SourceDescription(fullJSON); |
193
|
|
|
assert.deepEqual(description.toJSON(), fullJSON); |
194
|
|
|
}); |
195
|
|
|
|
196
|
|
|
it('constructor does not copy instances', function(){ |
197
|
|
|
var obj1 = GedcomX.SourceDescription(); |
198
|
|
|
var obj2 = GedcomX.SourceDescription(obj1); |
199
|
|
|
assert.strictEqual(obj1, obj2); |
200
|
|
|
}); |
201
|
|
|
|
202
|
|
|
}); |
203
|
|
|
|
204
|
|
|
function tests(description){ |
205
|
|
|
assert.equal(description.getResourceType(), 'http://some/type'); |
206
|
|
|
assert.equal(description.getCitations().length, 1); |
207
|
|
|
assert.equal(description.getCitations()[0].getLang(), 'en'); |
208
|
|
|
assert.equal(description.getCitations()[0].getValue(), 'Long source citation'); |
209
|
|
|
assert.equal(description.getMediaType(), 'book'); |
210
|
|
|
assert.equal(description.getAbout(), 'http://a/resource'); |
211
|
|
|
assert.equal(description.getMediator().getResource(), 'http://mediator'); |
212
|
|
|
assert.equal(description.getSources().length, 1); |
213
|
|
|
assert.equal(description.getSources()[0].getDescription(), 'http://source/reference'); |
214
|
|
|
assert.equal(description.getAnalysis().getResource(), 'http://analysis'); |
215
|
|
|
assert.equal(description.getComponentOf().getDescription(), 'http://container'); |
216
|
|
|
assert.equal(description.getTitles().length, 2); |
217
|
|
|
assert.equal(description.getTitles()[0].getLang(), 'en'); |
218
|
|
|
assert.equal(description.getTitles()[0].getValue(), 'Title'); |
219
|
|
|
assert.equal(description.getTitles()[1].getLang(), 'es'); |
220
|
|
|
assert.equal(description.getTitles()[1].getValue(), 'Titulo'); |
221
|
|
|
assert.equal(description.getNotes().length, 1); |
222
|
|
|
assert.equal(description.getNotes()[0].getSubject(), 'Note'); |
223
|
|
|
assert.equal(description.getNotes()[0].getText(), 'Some note text'); |
224
|
|
|
assert.equal(description.getAttribution().getCreated().getTime(), 1234578129); |
225
|
|
|
assert.equal(description.getRights().length, 1); |
226
|
|
|
assert.equal(description.getRights()[0].getResource(), 'https://some/right'); |
227
|
|
|
assert.equal(description.getCoverage().length, 1); |
228
|
|
|
assert.equal(description.getCoverage()[0].getTemporal().getFormal(), '+2015'); |
229
|
|
|
assert.equal(description.getCoverage()[0].getSpatial().getOriginal(), 'A place'); |
230
|
|
|
assert.equal(description.getDescriptions().length, 1); |
231
|
|
|
assert.equal(description.getDescriptions()[0].getValue(), 'A description'); |
232
|
|
|
assert.equal(description.getIdentifiers().identifiers.$, 'identifier'); |
233
|
|
|
assert.equal(description.getCreated(), 1000000); |
234
|
|
|
assert.equal(description.getModified(), 11111111); |
235
|
|
|
assert.equal(description.getRepository().getResource(), 'http://repository'); |
236
|
|
|
} |