@@ 1-183 (lines=183) @@ | ||
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 | 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 | assert.equal(description.getResourceType(), 'http://some/type'); |
|
82 | assert.equal(description.getCitations().length, 1); |
|
83 | assert.equal(description.getCitations()[0].getLang(), 'en'); |
|
84 | assert.equal(description.getCitations()[0].getValue(), 'Long source citation'); |
|
85 | assert.equal(description.getMediaType(), 'book'); |
|
86 | assert.equal(description.getAbout(), 'http://a/resource'); |
|
87 | assert.equal(description.getMediator().getResource(), 'http://mediator'); |
|
88 | assert.equal(description.getSources().length, 1); |
|
89 | assert.equal(description.getSources()[0].getDescription(), 'http://source/reference'); |
|
90 | assert.equal(description.getAnalysis().getResource(), 'http://analysis'); |
|
91 | assert.equal(description.getComponentOf().getDescription(), 'http://container'); |
|
92 | assert.equal(description.getTitles().length, 2); |
|
93 | assert.equal(description.getTitles()[0].getLang(), 'en'); |
|
94 | assert.equal(description.getTitles()[0].getValue(), 'Title'); |
|
95 | assert.equal(description.getTitles()[1].getLang(), 'es'); |
|
96 | assert.equal(description.getTitles()[1].getValue(), 'Titulo'); |
|
97 | assert.equal(description.getNotes().length, 1); |
|
98 | assert.equal(description.getNotes()[0].getSubject(), 'Note'); |
|
99 | assert.equal(description.getNotes()[0].getText(), 'Some note text'); |
|
100 | assert.equal(description.getAttribution().getCreated().getTime(), 1234578129); |
|
101 | assert.equal(description.getRights().length, 1); |
|
102 | assert.equal(description.getRights()[0].getResource(), 'https://some/right'); |
|
103 | assert.equal(description.getCoverage().getTemporal().getFormal(), '+2015'); |
|
104 | assert.equal(description.getCoverage().getSpatial().getOriginal(), 'A place'); |
|
105 | assert.equal(description.getDescriptions().length, 1); |
|
106 | assert.equal(description.getDescriptions()[0].getValue(), 'A description'); |
|
107 | assert.equal(description.getIdentifiers().identifiers.$, 'identifier'); |
|
108 | assert.equal(description.getCreated(), 1000000); |
|
109 | assert.equal(description.getModified(), 11111111); |
|
110 | assert.equal(description.getSortKey(), '123456'); |
|
111 | assert.equal(description.getVersion(), '123'); |
|
112 | assert.equal(description.getRepository().getResource(), 'http://repository'); |
|
113 | }); |
|
114 | ||
115 | it('Build', function(){ |
|
116 | var description = GedcomX.SourceDescription() |
|
117 | .setResourceType('http://some/type') |
|
118 | .addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation')) |
|
119 | .setMediaType('book') |
|
120 | .setAbout('http://a/resource') |
|
121 | .setMediator(GedcomX.ResourceReference().setResource('http://mediator')) |
|
122 | .addSource(GedcomX.SourceReference().setDescription('http://source/reference')) |
|
123 | .setAnalysis(GedcomX.ResourceReference().setResource('http://analysis')) |
|
124 | .setComponentOf(GedcomX.SourceReference().setDescription('http://container')) |
|
125 | .addTitle(GedcomX.TextValue().setLang('en').setValue('Title')) |
|
126 | .addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo')) |
|
127 | .addNote(GedcomX.Note().setSubject('Note').setText('Some note text')) |
|
128 | .setAttribution(GedcomX.Attribution().setCreated(1234578129)) |
|
129 | .addRight(GedcomX.ResourceReference().setResource('https://some/right')) |
|
130 | .setCoverage( |
|
131 | GedcomX.Coverage() |
|
132 | .setTemporal(GedcomX.Date().setFormal('+2015')) |
|
133 | .setSpatial(GedcomX.PlaceReference().setOriginal('A place')) |
|
134 | ) |
|
135 | .addDescription(GedcomX.TextValue().setValue('A description')) |
|
136 | .setIdentifiers(GedcomX.Identifiers({ |
|
137 | $: 'identifier' |
|
138 | })) |
|
139 | .setCreated(1000000) |
|
140 | .setModified(11111111) |
|
141 | .setSortKey('123456') |
|
142 | .setVersion('123') |
|
143 | .setRepository(GedcomX.ResourceReference().setResource('http://repository')); |
|
144 | assert.equal(description.getResourceType(), 'http://some/type'); |
|
145 | assert.equal(description.getCitations().length, 1); |
|
146 | assert.equal(description.getCitations()[0].getLang(), 'en'); |
|
147 | assert.equal(description.getCitations()[0].getValue(), 'Long source citation'); |
|
148 | assert.equal(description.getMediaType(), 'book'); |
|
149 | assert.equal(description.getAbout(), 'http://a/resource'); |
|
150 | assert.equal(description.getMediator().getResource(), 'http://mediator'); |
|
151 | assert.equal(description.getSources().length, 1); |
|
152 | assert.equal(description.getSources()[0].getDescription(), 'http://source/reference'); |
|
153 | assert.equal(description.getAnalysis().getResource(), 'http://analysis'); |
|
154 | assert.equal(description.getComponentOf().getDescription(), 'http://container'); |
|
155 | assert.equal(description.getTitles().length, 2); |
|
156 | assert.equal(description.getTitles()[0].getLang(), 'en'); |
|
157 | assert.equal(description.getTitles()[0].getValue(), 'Title'); |
|
158 | assert.equal(description.getTitles()[1].getLang(), 'es'); |
|
159 | assert.equal(description.getTitles()[1].getValue(), 'Titulo'); |
|
160 | assert.equal(description.getNotes().length, 1); |
|
161 | assert.equal(description.getNotes()[0].getSubject(), 'Note'); |
|
162 | assert.equal(description.getNotes()[0].getText(), 'Some note text'); |
|
163 | assert.equal(description.getAttribution().getCreated().getTime(), 1234578129); |
|
164 | assert.equal(description.getRights().length, 1); |
|
165 | assert.equal(description.getRights()[0].getResource(), 'https://some/right'); |
|
166 | assert.equal(description.getCoverage().getTemporal().getFormal(), '+2015'); |
|
167 | assert.equal(description.getCoverage().getSpatial().getOriginal(), 'A place'); |
|
168 | assert.equal(description.getDescriptions().length, 1); |
|
169 | assert.equal(description.getDescriptions()[0].getValue(), 'A description'); |
|
170 | assert.equal(description.getIdentifiers().identifiers.$, 'identifier'); |
|
171 | assert.equal(description.getCreated(), 1000000); |
|
172 | assert.equal(description.getModified(), 11111111); |
|
173 | assert.equal(description.getSortKey(), '123456'); |
|
174 | assert.equal(description.getVersion(), '123'); |
|
175 | assert.equal(description.getRepository().getResource(), 'http://repository'); |
|
176 | }); |
|
177 | ||
178 | it('toJSON', function(){ |
|
179 | var description = GedcomX.SourceDescription(fullJSON); |
|
180 | assert.deepEqual(description.toJSON(), fullJSON); |
|
181 | }); |
|
182 | ||
183 | }); |
@@ 1-159 (lines=159) @@ | ||
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 | titleLabel: 'Title', |
|
76 | sortKey: '123456', |
|
77 | descriptorRef: '#dref' |
|
78 | }; |
|
79 | ||
80 | it('Create with JSON', function(){ |
|
81 | var description = GedcomX.SourceDescription(fullJSON); |
|
82 | tests(description); |
|
83 | }); |
|
84 | ||
85 | it('Build', function(){ |
|
86 | var description = GedcomX.SourceDescription() |
|
87 | .setResourceType('http://some/type') |
|
88 | .addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation')) |
|
89 | .setMediaType('book') |
|
90 | .setAbout('http://a/resource') |
|
91 | .setMediator(GedcomX.ResourceReference().setResource('http://mediator')) |
|
92 | .addSource(GedcomX.SourceReference().setDescription('http://source/reference')) |
|
93 | .setAnalysis(GedcomX.ResourceReference().setResource('http://analysis')) |
|
94 | .setComponentOf(GedcomX.SourceReference().setDescription('http://container')) |
|
95 | .addTitle(GedcomX.TextValue().setLang('en').setValue('Title')) |
|
96 | .addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo')) |
|
97 | .addNote(GedcomX.Note().setSubject('Note').setText('Some note text')) |
|
98 | .setAttribution(GedcomX.Attribution().setCreated(1234578129)) |
|
99 | .addRight(GedcomX.ResourceReference().setResource('https://some/right')) |
|
100 | .setTitleLabel('Title') |
|
101 | .setSortKey('123456') |
|
102 | .setDescriptorRef('#dref') |
|
103 | .setCoverage( |
|
104 | GedcomX.Coverage() |
|
105 | .setTemporal(GedcomX.Date().setFormal('+2015')) |
|
106 | .setSpatial(GedcomX.PlaceReference().setOriginal('A place')) |
|
107 | ) |
|
108 | .addDescription(GedcomX.TextValue().setValue('A description')) |
|
109 | .setIdentifiers(GedcomX.Identifiers({ |
|
110 | $: 'identifier' |
|
111 | })) |
|
112 | .setCreated(1000000) |
|
113 | .setModified(11111111) |
|
114 | .setRepository(GedcomX.ResourceReference().setResource('http://repository')); |
|
115 | tests(description); |
|
116 | }); |
|
117 | ||
118 | it('toJSON', function(){ |
|
119 | var description = GedcomX.SourceDescription(fullJSON); |
|
120 | assert.deepEqual(description.toJSON(), fullJSON); |
|
121 | }); |
|
122 | ||
123 | }); |
|
124 | ||
125 | function tests(description){ |
|
126 | assert.equal(description.getResourceType(), 'http://some/type'); |
|
127 | assert.equal(description.getCitations().length, 1); |
|
128 | assert.equal(description.getCitations()[0].getLang(), 'en'); |
|
129 | assert.equal(description.getCitations()[0].getValue(), 'Long source citation'); |
|
130 | assert.equal(description.getMediaType(), 'book'); |
|
131 | assert.equal(description.getAbout(), 'http://a/resource'); |
|
132 | assert.equal(description.getMediator().getResource(), 'http://mediator'); |
|
133 | assert.equal(description.getSources().length, 1); |
|
134 | assert.equal(description.getSources()[0].getDescription(), 'http://source/reference'); |
|
135 | assert.equal(description.getAnalysis().getResource(), 'http://analysis'); |
|
136 | assert.equal(description.getComponentOf().getDescription(), 'http://container'); |
|
137 | assert.equal(description.getTitles().length, 2); |
|
138 | assert.equal(description.getTitles()[0].getLang(), 'en'); |
|
139 | assert.equal(description.getTitles()[0].getValue(), 'Title'); |
|
140 | assert.equal(description.getTitles()[1].getLang(), 'es'); |
|
141 | assert.equal(description.getTitles()[1].getValue(), 'Titulo'); |
|
142 | assert.equal(description.getNotes().length, 1); |
|
143 | assert.equal(description.getNotes()[0].getSubject(), 'Note'); |
|
144 | assert.equal(description.getNotes()[0].getText(), 'Some note text'); |
|
145 | assert.equal(description.getAttribution().getCreated().getTime(), 1234578129); |
|
146 | assert.equal(description.getRights().length, 1); |
|
147 | assert.equal(description.getRights()[0].getResource(), 'https://some/right'); |
|
148 | assert.equal(description.getCoverage().getTemporal().getFormal(), '+2015'); |
|
149 | assert.equal(description.getCoverage().getSpatial().getOriginal(), 'A place'); |
|
150 | assert.equal(description.getDescriptions().length, 1); |
|
151 | assert.equal(description.getDescriptions()[0].getValue(), 'A description'); |
|
152 | assert.equal(description.getIdentifiers().identifiers.$, 'identifier'); |
|
153 | assert.equal(description.getCreated(), 1000000); |
|
154 | assert.equal(description.getModified(), 11111111); |
|
155 | assert.equal(description.getRepository().getResource(), 'http://repository'); |
|
156 | assert.equal(description.getTitleLabel(), 'Title'); |
|
157 | assert.equal(description.getSortKey(), '123456'); |
|
158 | assert.equal(description.getDescriptorRef(), '#dref'); |
|
159 | } |