|
1
|
|
|
var assert = require('chai').assert, |
|
2
|
|
|
GedcomX = require('../../'); |
|
3
|
|
|
|
|
4
|
|
|
describe('Link', function(){ |
|
5
|
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
|
7
|
|
|
assert.instanceOf(new GedcomX.Link(), GedcomX.Link, 'An instance of Link is not returned when calling the constructor with new.'); |
|
8
|
|
|
assert.instanceOf(GedcomX.Link(), GedcomX.Link, 'An instance of Link is not returned when calling the constructor without new.'); |
|
9
|
|
|
}); |
|
10
|
|
|
|
|
11
|
|
|
it('Create with JSON', function(){ |
|
12
|
|
|
var link = GedcomX.Link({ |
|
13
|
|
|
rel: 'relationship', |
|
14
|
|
|
href: '/relationship', |
|
15
|
|
|
template: '/relationship/{}', |
|
16
|
|
|
type: 'application/x-gedcomx-v1+json', |
|
17
|
|
|
accept: 'application/x-gedcomx-v1+json', |
|
18
|
|
|
allow: 'GET', |
|
19
|
|
|
hreflang: 'en', |
|
20
|
|
|
title: 'Relationship' |
|
21
|
|
|
}); |
|
22
|
|
|
assert.equal(link.getRel(), 'relationship'); |
|
23
|
|
|
assert.equal(link.getHref(), '/relationship'); |
|
24
|
|
|
assert.equal(link.getTemplate(), '/relationship/{}'); |
|
25
|
|
|
assert.equal(link.getType(), 'application/x-gedcomx-v1+json'); |
|
26
|
|
|
assert.equal(link.getAccept(), 'application/x-gedcomx-v1+json'); |
|
27
|
|
|
assert.equal(link.getAllow(), 'GET'); |
|
28
|
|
|
assert.equal(link.getHrefLang(), 'en'); |
|
29
|
|
|
assert.equal(link.getTitle(), 'Relationship'); |
|
30
|
|
|
}); |
|
31
|
|
|
|
|
32
|
|
|
it('Build', function(){ |
|
33
|
|
|
var link = GedcomX.Link() |
|
34
|
|
|
.setRel('relationship') |
|
35
|
|
|
.setHref('/relationship') |
|
36
|
|
|
.setTemplate('/relationship/{}') |
|
37
|
|
|
.setType('application/x-gedcomx-v1+json') |
|
38
|
|
|
.setAccept('application/x-gedcomx-v1+json') |
|
39
|
|
|
.setAllow('GET') |
|
40
|
|
|
.setHrefLang('en') |
|
41
|
|
|
.setTitle('Relationship'); |
|
42
|
|
|
assert.equal(link.getRel(), 'relationship'); |
|
43
|
|
|
assert.equal(link.getHref(), '/relationship'); |
|
44
|
|
|
assert.equal(link.getTemplate(), '/relationship/{}'); |
|
45
|
|
|
assert.equal(link.getType(), 'application/x-gedcomx-v1+json'); |
|
46
|
|
|
assert.equal(link.getAccept(), 'application/x-gedcomx-v1+json'); |
|
47
|
|
|
assert.equal(link.getAllow(), 'GET'); |
|
48
|
|
|
assert.equal(link.getHrefLang(), 'en'); |
|
49
|
|
|
assert.equal(link.getTitle(), 'Relationship'); |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
it('toJSON', function(){ |
|
53
|
|
|
var data = { |
|
54
|
|
|
rel: 'relationship', |
|
55
|
|
|
href: '/relationship', |
|
56
|
|
|
template: '/relationship/{}', |
|
57
|
|
|
type: 'application/x-gedcomx-v1+json', |
|
58
|
|
|
accept: 'application/x-gedcomx-v1+json', |
|
59
|
|
|
allow: 'GET', |
|
60
|
|
|
hreflang: 'en', |
|
61
|
|
|
title: 'Relationship' |
|
62
|
|
|
}, link = GedcomX.Link(data); |
|
63
|
|
|
assert.deepEqual(link.toJSON(), data); |
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
it('constructor does not copy instances', function(){ |
|
67
|
|
|
var obj1 = GedcomX.Link(); |
|
68
|
|
|
var obj2 = GedcomX.Link(obj1); |
|
69
|
|
|
assert.strictEqual(obj1, obj2); |
|
70
|
|
|
}); |
|
71
|
|
|
|
|
72
|
|
|
}); |