1
|
|
|
var assert = require('chai').assert, |
2
|
|
|
GedcomX = require('../'); |
3
|
|
|
|
4
|
|
|
describe('Attribution', function(){ |
5
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
7
|
|
|
var newAttr = new GedcomX.Attribution(), |
8
|
|
|
attr = GedcomX.Attribution(); |
9
|
|
|
assert.instanceOf(newAttr, GedcomX.Attribution, 'An instance of Attribution is not returned when calling the constructor with new.'); |
10
|
|
|
assert.instanceOf(attr, GedcomX.Attribution, 'An instance of Attribution is not returned when calling the constructor without new.'); |
11
|
|
|
}); |
12
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
14
|
|
|
var attr = GedcomX.Attribution({ |
15
|
|
|
changeMessage: 'It changed', |
16
|
|
|
contributor: { resource: 'https://myapp.com/contributor'}, |
17
|
|
|
created: 1111338494969, |
18
|
|
|
creator: { resource: 'https://myapp.com/creator'}, |
19
|
|
|
modified: 1111338494969 |
20
|
|
|
}); |
21
|
|
|
assert.equal(attr.getChangeMessage(), 'It changed', 'Change message not saved properly when created with JSON'); |
22
|
|
|
assert.equal(attr.getContributor().getResource(), 'https://myapp.com/contributor', 'Contributor not saved when created with JSON'); |
23
|
|
|
assert.equal(attr.getCreated().getTime(), 1111338494969, 'Created date not saved when created with JSON'); |
24
|
|
|
assert.equal(attr.getCreator().getResource(), 'https://myapp.com/creator', 'Creator not saved when created with JSON'); |
25
|
|
|
assert.equal(attr.getModified().getTime(), 1111338494969, 'Modified date not saved when created with JSON'); |
26
|
|
|
}); |
27
|
|
|
|
28
|
|
|
it('Create with mixed data', function(){ |
29
|
|
|
var attr = GedcomX.Attribution({ |
30
|
|
|
changeMessage: 'It changed', |
31
|
|
|
contributor: GedcomX.ResourceReference({ resource: 'https://myapp.com/contributor'}), |
32
|
|
|
created: new Date(1111338494969), |
33
|
|
|
creator: GedcomX.ResourceReference({ resource: 'https://myapp.com/creator'}), |
34
|
|
|
modified: new Date(1111338494969) |
35
|
|
|
}); |
36
|
|
|
assert.equal(attr.getChangeMessage(), 'It changed', 'Change message not saved properly when created with mixed data'); |
37
|
|
|
assert.equal(attr.getContributor().getResource(), 'https://myapp.com/contributor', 'Contributor not saved when created with mixed data'); |
38
|
|
|
assert.equal(attr.getCreated().getTime(), 1111338494969, 'Created date not saved when created with mixed data'); |
39
|
|
|
assert.equal(attr.getCreator().getResource(), 'https://myapp.com/creator', 'Creator not saved when created with mixed data'); |
40
|
|
|
assert.equal(attr.getModified().getTime(), 1111338494969, 'Modified date not saved when created with mixed data'); |
41
|
|
|
}); |
42
|
|
|
|
43
|
|
|
it('Build', function(){ |
44
|
|
|
var attr = GedcomX.Attribution() |
45
|
|
|
.setChangeMessage('It changed') |
46
|
|
|
.setContributor({ resource: 'https://myapp.com/contributor'}) |
47
|
|
|
.setCreated(1111338494969) |
48
|
|
|
.setCreator({ resource: 'https://myapp.com/creator'}) |
49
|
|
|
.setModified(1111338494969); |
50
|
|
|
assert.equal(attr.getChangeMessage(), 'It changed', 'Change message not saved properly when created with mixed data'); |
51
|
|
|
assert.equal(attr.getContributor().getResource(), 'https://myapp.com/contributor', 'Contributor not saved when created with mixed data'); |
52
|
|
|
assert.equal(attr.getCreated().getTime(), 1111338494969, 'Created date not saved when created with mixed data'); |
53
|
|
|
assert.equal(attr.getCreator().getResource(), 'https://myapp.com/creator', 'Creator not saved when created with mixed data'); |
54
|
|
|
assert.equal(attr.getModified().getTime(), 1111338494969, 'Modified date not saved when created with mixed data'); |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
it('toJSON', function(){ |
58
|
|
|
var attrData = { |
59
|
|
|
id: 'attr-id', |
60
|
|
|
changeMessage: 'It changed', |
61
|
|
|
contributor: { resource: 'https://myapp.com/contributor'}, |
62
|
|
|
created: 1111338494969, |
63
|
|
|
creator: { resource: 'https://myapp.com/creator'}, |
64
|
|
|
modified: 1111338494969 |
65
|
|
|
}, |
66
|
|
|
attr = GedcomX.Attribution(attrData); |
67
|
|
|
assert.deepEqual(attr.toJSON(), attrData, 'toJSON export does not equal original data.'); |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
it('constructor does not copy instances', function(){ |
71
|
|
|
var obj1 = GedcomX.Attribution(); |
72
|
|
|
var obj2 = GedcomX.Attribution(obj1); |
73
|
|
|
assert.strictEqual(obj1, obj2); |
74
|
|
|
}); |
75
|
|
|
|
76
|
|
|
}); |