1
|
|
|
var assert = require('chai').assert, |
2
|
|
|
GedcomX = require('../../'); |
3
|
|
|
|
4
|
|
|
describe('Collection', function(){ |
5
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
7
|
|
|
assert.instanceOf(new GedcomX.Collection(), GedcomX.Collection, 'An instance of Collection is not returned when calling the constructor with new.'); |
8
|
|
|
assert.instanceOf(GedcomX.Collection(), GedcomX.Collection, 'An instance of Collection is not returned when calling the constructor without new.'); |
9
|
|
|
}); |
10
|
|
|
|
11
|
|
|
it('Create with JSON', function(){ |
12
|
|
|
var collection = GedcomX.Collection({ |
13
|
|
|
id: 'collection', |
14
|
|
|
lang: 'en-US', |
15
|
|
|
content: [{ |
16
|
|
|
resourceType: 'http://gedcomx.org/Record', |
17
|
|
|
count: 183429102, |
18
|
|
|
completeness: .8237 |
19
|
|
|
}], |
20
|
|
|
title: 'Collection Title', |
21
|
|
|
size: 183429102, |
22
|
|
|
attribution: { |
23
|
|
|
contributor: { resource: 'https://myapp.com/contributor'}, |
24
|
|
|
created: 1111338494969, |
25
|
|
|
creator: { resource: 'https://myapp.com/creator'}, |
26
|
|
|
modified: 1111338494969 |
27
|
|
|
} |
28
|
|
|
}); |
29
|
|
|
assert.equal(collection.getId(), 'collection'); |
30
|
|
|
assert.equal(collection.getLang(), 'en-US'); |
31
|
|
|
assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record'); |
32
|
|
|
assert.equal(collection.getTitle(), 'Collection Title'); |
33
|
|
|
assert.equal(collection.getSize(), 183429102); |
34
|
|
|
assert(GedcomX.Attribution.isInstance(collection.getAttribution())); |
35
|
|
|
}); |
36
|
|
|
|
37
|
|
|
it('Build', function(){ |
38
|
|
|
var collection = GedcomX.Collection() |
39
|
|
|
.setId('collection') |
40
|
|
|
.setLang('en-US') |
41
|
|
|
.addContent({ |
42
|
|
|
resourceType: 'http://gedcomx.org/Record', |
43
|
|
|
count: 183429102, |
44
|
|
|
completeness: .8237 |
45
|
|
|
}) |
46
|
|
|
.setTitle('Collection Title') |
47
|
|
|
.setSize(183429102) |
48
|
|
|
.setAttribution({ |
49
|
|
|
contributor: { resource: 'https://myapp.com/contributor'}, |
50
|
|
|
created: 1111338494969, |
51
|
|
|
creator: { resource: 'https://myapp.com/creator'}, |
52
|
|
|
modified: 1111338494969 |
53
|
|
|
}); |
54
|
|
|
assert.equal(collection.getId(), 'collection'); |
55
|
|
|
assert.equal(collection.getLang(), 'en-US'); |
56
|
|
|
assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record'); |
57
|
|
|
assert.equal(collection.getTitle(), 'Collection Title'); |
58
|
|
|
assert.equal(collection.getSize(), 183429102); |
59
|
|
|
assert(GedcomX.Attribution.isInstance(collection.getAttribution())); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
it('toJSON', function(){ |
63
|
|
|
var data = { |
64
|
|
|
id: 'collection', |
65
|
|
|
lang: 'en-US', |
66
|
|
|
content: [{ |
67
|
|
|
resourceType: 'http://gedcomx.org/Record', |
68
|
|
|
count: 183429102, |
69
|
|
|
completeness: .8237 |
70
|
|
|
}], |
71
|
|
|
title: 'Collection Title', |
72
|
|
|
size: 183429102, |
73
|
|
|
attribution: { |
74
|
|
|
contributor: { resource: 'https://myapp.com/contributor'}, |
75
|
|
|
created: 1111338494969, |
76
|
|
|
creator: { resource: 'https://myapp.com/creator'}, |
77
|
|
|
modified: 1111338494969 |
78
|
|
|
} |
79
|
|
|
}, collection = GedcomX.Collection(data); |
80
|
|
|
assert.deepEqual(collection.toJSON(), data); |
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
it('constructor does not copy instances', function(){ |
84
|
|
|
var obj1 = GedcomX.Collection(); |
85
|
|
|
var obj2 = GedcomX.Collection(obj1); |
86
|
|
|
assert.strictEqual(obj1, obj2); |
87
|
|
|
}); |
88
|
|
|
|
89
|
|
|
}); |