Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

test/records/Root.js   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 558
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 558
rs 10
wmc 5
mnd 0
bc 5
fnc 5
bpm 1
cpm 1
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B Root.js ➔ describe(ꞌRootꞌ) 0 420 1
B Root.js ➔ tests 0 129 1
1
var chai = require('chai');
2
chai.use(require('chai-json-schema'));
3
chai.tv4.banUnknown = true;
4
5
var assert = chai.assert,
6
    GedcomXSchema = require('gedcomx-json-schema'),
7
    GedcomX = require('../../');
8
9
describe('Root', function(){
10
  
11
  var fullJSON = {
12
    id: 'gedcomx',
13
    lang: 'en',
14
    description: '#sd1',
15
    attribution: { 
16
      changeMessage: 'It changed',
17
      contributor: { resource: 'https://myapp.com/contributor'},
18
      created: 1111338494969,
19
      creator: { resource: 'https://myapp.com/creator'},
20
      modified: 1111338494969
21
    },
22
    persons: [
23
      {
24
        private: false,
25
        gender: {
26
          type: 'http://gedcomx.org/Female'
27
        },
28
        names: [
29
          {
30
            type: 'http://gedcomx.org/BirthName',
31
            nameForms: [
32
              {
33
                fullText: 'Joanna Hopkins'
34
              }
35
            ]
36
          }  
37
        ],
38
        facts: [
39
          {
40
            type: 'http://gedcomx.org/Birth',
41
            date: {
42
              formal: '+2001-04-09'
43
            },
44
            place: {
45
              original: 'Farm house'
46
            }
47
          }  
48
        ]
49
      } 
50
    ],
51
    relationships: [
52
      {
53
        type: 'http://gedcomx.org/Couple',
54
        person1: {
55
          resource: 'http://identifier/for/person/1'
56
        },
57
        person2: {
58
          resource: 'http://identifier/for/person/2'
59
        },
60
        facts: [
61
          {
62
            type: 'http://gedcomx.org/Marriage'
63
          }
64
        ]
65
      }  
66
    ],
67
    sourceDescriptions: [
68
      {
69
        id: 'sd1',
70
        resourceType: 'http://some/type',
71
        citations: [
72
          {
73
            lang: 'en',
74
            value: 'Long source citation'
75
          }
76
        ],
77
        mediaType: 'book',
78
        about: 'http://a/resource',
79
        mediator: {
80
          resource: 'http://mediator'
81
        },
82
        sources: [
83
          {
84
            description: 'http://source/reference'
85
          }
86
        ],
87
        analysis: {
88
          resource: 'http://analysis'
89
        },
90
        componentOf: {
91
          description: 'http://container'
92
        },
93
        titles: [
94
          {
95
            lang: 'en',
96
            value: 'Title'
97
          },
98
          {
99
            lang: 'es',
100
            value: 'Titulo'
101
          }
102
        ],
103
        notes: [
104
          {
105
            subject: 'Note',
106
            text: 'Some note text'
107
          }
108
        ],
109
        attribution: {
110
          created: 1234578129
111
        },
112
        rights: [
113
          {
114
            resource: 'https://some/right'
115
          }
116
        ],
117
        coverage: {
118
          temporal: {
119
            formal: '+2015'
120
          },
121
          spatial: {
122
            original: 'A place'
123
          }
124
        },
125
        descriptions: [
126
          {
127
            value: 'A description'
128
          }
129
        ],
130
        identifiers: {
131
          $: 'identifier'
132
        },
133
        created: 1000000,
134
        modified: 11111111,
135
        repository: {
136
          resource: 'http://repository'
137
        }
138
      }
139
    ],
140
    agents: [
141
      {
142
        id: 'agent',
143
        identifiers: {
144
          $: 'ident'
145
        },
146
        names: [
147
          {
148
            lang: 'en',
149
            value: 'Name'
150
          }  
151
        ],
152
        homepage: {
153
          resource: 'http://homepage'
154
        },
155
        openid: {
156
          resource: 'http://openid'
157
        },
158
        accounts: [
159
          {
160
            accountName: 'jimbo'
161
          }  
162
        ],
163
        emails: [
164
          {
165
            resource: 'http://email'
166
          }  
167
        ],
168
        phones: [
169
          {
170
            resource: 'http://phone'
171
          }  
172
        ],
173
        addresses: [
174
          {
175
            value: 'big long address',
176
            postalCode: '123456'
177
          }  
178
        ],
179
        person: {
180
          resource: 'http://person'
181
        }
182
      }  
183
    ],
184
    events: [
185
      {
186
        type: 'http://gedcomx.org/Marriage',
187
        date: {
188
          formal: '+2002-06-06'
189
        },
190
        place: {
191
          original: 'Her town, MN'
192
        },
193
        roles: [
194
          {
195
            person: {
196
              resource: 'http://groom'
197
            },
198
            type: 'http://gedcomx.org/Participant'
199
          }
200
        ]
201
      }  
202
    ],
203
    documents: [
204
      {
205
        type: 'http://gedcomx.org/Abstract',
206
        extracted: false,
207
        textType: 'plain',
208
        text: 'Lots of text',
209
        attribution: {
210
          created: 123456789
211
        }
212
      }  
213
    ],
214
    places: [
215
      {
216
        names : [ 
217
          {
218
            lang : 'en',
219
            value : 'Pope\'s Creek, Westmoreland, Virginia, United States'
220
          }
221
        ],
222
        type : 'http://identifier/for/the/place/type',
223
        place : { resource : 'http://place' },
224
        jurisdiction : { resource : 'http://jurisdiction' },
225
        latitude : 27.9883575,
226
        longitude : 86.9252014,
227
        temporalDescription : { 
228
          formal: '+1899-01-04'
229
        },
230
        spatialDescription : {
231
          resource : 'http://uri/for/KML/document'
232
        }
233
      }
234
    ],
235
    recordDescriptors: [
236
      {
237
        id: 'rd',
238
        lang: 'en-US',
239
        fields: [{
240
          originalLabel: 'Name',
241
          descriptions: [
242
            { lang: 'en-US', value: 'Full Name' }
243
          ],
244
          values: [{
245
            optional: true,
246
            type: 'http://gedcomx.org/Original',
247
            labelId: 'name',
248
            displayLabels: [
249
              { lang: 'en-US', value: 'Name' }
250
            ]
251
          }]
252
        }]
253
      }
254
    ],
255
    collections: [
256
      {
257
        id: 'collection',
258
        lang: 'en-US',
259
        content: [{
260
          resourceType: 'http://gedcomx.org/Record',
261
          count: 183429102,
262
          completeness: .8237
263
        }],
264
        title: 'Collection Title',
265
        size: 183429102,
266
        attribution: { 
267
          contributor: { resource: 'https://myapp.com/contributor'},
268
          created: 1111338494969,
269
          creator: { resource: 'https://myapp.com/creator'},
270
          modified: 1111338494969
271
        }
272
      }  
273
    ]
274
  };
275
  
276
  it('Create with JSON', function(){
277
    var gedx = GedcomX(fullJSON);
278
    tests(gedx);
279
  });
280
  
281
  it('Build', function(){
282
    var gedx = GedcomX()
283
      .setId('gedcomx')
284
      .setLang('en')
285
      .setDescription('#sd1')
286
      .setAttribution(GedcomX.Attribution()
287
        .setChangeMessage('It changed')
288
        .setContributor({ resource: 'https://myapp.com/contributor'})
289
        .setCreated(1111338494969)
290
        .setCreator({ resource: 'https://myapp.com/creator'})
291
        .setModified(1111338494969))
292
      .addPerson(
293
        GedcomX.Person()
294
          .setId('testPerson')
295
          .setPrivate(true)
296
          .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female'))
297
          .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins')))
298
          .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house')))
299
      )
300
      .addRelationship(
301
        GedcomX.Relationship()
302
          .setType('http://gedcomx.org/Couple')
303
          .setPerson1(GedcomX.ResourceReference().setResource('http://identifier/for/person/1'))
304
          .setPerson2(GedcomX.ResourceReference().setResource('http://identifier/for/person/2'))
305
          .addFact(GedcomX.Fact().setType('http://gedcomx.org/Marriage'))  
306
      )
307
      .addSourceDescription(
308
        GedcomX.SourceDescription()
309
          .setId('sd1')
310
          .setResourceType('http://some/type')
311
          .addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation'))
312
          .setMediaType('book')
313
          .setAbout('http://a/resource')
314
          .setMediator(GedcomX.ResourceReference().setResource('http://mediator'))
315
          .addSource(GedcomX.SourceReference().setDescription('http://source/reference'))
316
          .setAnalysis(GedcomX.ResourceReference().setResource('http://analysis'))
317
          .setComponentOf(GedcomX.SourceReference().setDescription('http://container'))
318
          .addTitle(GedcomX.TextValue().setLang('en').setValue('Title'))
319
          .addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo'))
320
          .addNote(GedcomX.Note().setSubject('Note').setText('Some note text'))
321
          .setAttribution(GedcomX.Attribution().setCreated(1234578129))
322
          .addRight(GedcomX.ResourceReference().setResource('https://some/right'))
323
          .setCoverage(
324
            GedcomX.Coverage()
325
              .setTemporal(GedcomX.Date().setFormal('+2015'))
326
              .setSpatial(GedcomX.PlaceReference().setOriginal('A place'))
327
          )
328
          .addDescription(GedcomX.TextValue().setValue('A description'))
329
          .setIdentifiers(GedcomX.Identifiers({
330
            $: 'identifier'
331
          }))
332
          .setCreated(1000000)
333
          .setModified(11111111)
334
          .setRepository(GedcomX.ResourceReference().setResource('http://repository'))  
335
      )
336
      .addAgent(
337
        GedcomX.Agent()
338
          .setId('agent')
339
          .setIdentifiers(GedcomX.Identifiers({$:'ident'}))
340
          .addName(GedcomX.TextValue().setLang('en').setValue('Name'))
341
          .setHomepage(GedcomX.ResourceReference().setResource('http://homepage'))
342
          .setOpenid(GedcomX.ResourceReference().setResource('http://openid'))
343
          .addAccount(GedcomX.OnlineAccount().setAccountName('jimbo'))
344
          .addEmail(GedcomX.ResourceReference().setResource('http://email'))
345
          .addPhone(GedcomX.ResourceReference().setResource('http://phone'))
346
          .addAddress(GedcomX.Address().setValue('big long address').setPostalCode('123456'))
347
          .setPerson(GedcomX.ResourceReference().setResource('http://person'))  
348
      )
349
      .addEvent(
350
        GedcomX.Event()
351
          .setType('http://gedcomx.org/Marriage')
352
          .setDate(GedcomX.Date().setFormal('+2002-06-06'))
353
          .setPlace(GedcomX.PlaceReference().setOriginal('Her town, MN'))
354
          .addRole(GedcomX.EventRole()
355
            .setType('http://gedcomx.org/Participant')
356
            .setPerson(GedcomX.ResourceReference().setResource('http://groom')))  
357
      )
358
      .addDocument(
359
        GedcomX.Document()
360
        .setType('http://gedcomx.org/Abstract')
361
        .setExtracted(false)
362
        .setTextType('plain')
363
        .setText('Lots of text')
364
        .setAttribution(GedcomX.Attribution().setCreated(123456789))          
365
      )
366
      .addPlace(
367
        GedcomX.PlaceDescription()
368
          .addName(GedcomX.TextValue().setLang('en').setValue('Pope\'s Creek, Westmoreland, Virginia, United States'))
369
          .setType('http://identifier/for/the/place/type')
370
          .setPlace(GedcomX.ResourceReference({ resource : 'http://place' }))
371
          .setJurisdiction(GedcomX.ResourceReference({ resource : 'http://jurisdiction' }))
372
          .setLatitude(27.9883575)
373
          .setLongitude(86.9252014)
374
          .setTemporalDescription(GedcomX.Date({ 
375
            formal: '+1899-01-04'
376
          }))
377
          .setSpatialDescription(GedcomX.ResourceReference({
378
            resource : 'http://uri/for/KML/document'
379
          }))
380
      )
381
      .addRecordDescriptor(
382
        GedcomX.RecordDescriptor()
383
          .setId('rd')
384
          .setLang('en-US')
385
          .addField(
386
            GedcomX.FieldDescriptor()
387
              .setOriginalLabel('Name')
388
              .addDescription({ lang: 'en-US', value: 'Full Name' })
389
              .addValue(
390
                GedcomX.FieldValueDescriptor()
391
                  .setOptional(true)
392
                  .setType('http://gedcomx.org/Original')
393
                  .setLabelId('name')
394
                  .addDisplayLabel({ lang: 'en-US', value: 'Name' })
395
              )
396
          )
397
      )
398
      .addCollection(
399
        GedcomX.Collection()
400
          .setId('collection')
401
          .setLang('en-US')
402
          .addContent(
403
            GedcomX.CollectionContent()
404
              .setResourceType('http://gedcomx.org/Record')
405
              .setCount(183429102)
406
              .setCompleteness(.8237)  
407
          )
408
          .setTitle('Collection Title')
409
          .setSize(183429102)
410
          .setAttribution(
411
            GedcomX.Attribution()
412
              .setContributor({ resource: 'https://myapp.com/contributor'})
413
              .setCreated(1111338494969)
414
              .setCreator({ resource: 'https://myapp.com/creator'})
415
              .setModified(1111338494969)  
416
          )  
417
      );
418
    
419
    tests(gedx);
420
  });
421
  
422
  it('toJSON', function(){
423
    var gedx = GedcomX(fullJSON);
424
    assert.deepEqual(gedx.toJSON(), fullJSON);
425
    assert.jsonSchema(gedx.toJSON(), GedcomXSchema);
426
  });
427
  
428
});
429
430
function tests(gedx){
431
  assert.equal(gedx.getId(), 'gedcomx');
432
  assert.equal(gedx.getLang(), 'en');
433
  assert.equal(gedx.getDescription(), '#sd1');
434
  
435
  var attribution = gedx.getAttribution();
436
  assert.equal(attribution.getChangeMessage(), 'It changed', 'Change message not saved properly when created with JSON');
437
  assert.equal(attribution.getContributor().getResource(), 'https://myapp.com/contributor', 'Contributor not saved when created with JSON');
438
  assert.equal(attribution.getCreated().getTime(), 1111338494969, 'Created date not saved when created with JSON');
439
  assert.equal(attribution.getCreator().getResource(), 'https://myapp.com/creator', 'Creator not saved when created with JSON');
440
  assert.equal(attribution.getModified().getTime(), 1111338494969, 'Modified date not saved when created with JSON');
441
  
442
  assert.equal(gedx.getPersons().length, 1);
443
  var person = gedx.getPersons()[0];
444
  assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female');
445
  assert.equal(person.getNames().length, 1);
446
  assert.equal(person.getFacts().length, 1);
447
  
448
  assert.equal(gedx.getRelationships().length, 1);
449
  var relationship = gedx.getRelationships()[0];
450
  assert.equal(relationship.getType(), 'http://gedcomx.org/Couple');
451
  assert.equal(relationship.getPerson1().getResource(), 'http://identifier/for/person/1');
452
  assert.equal(relationship.getPerson2().getResource(), 'http://identifier/for/person/2');
453
  assert.equal(relationship.getFacts().length, 1);
454
  assert.equal(relationship.getFacts()[0].getType(), 'http://gedcomx.org/Marriage');
455
  
456
  assert.equal(gedx.getSourceDescriptions().length, 1);
457
  var description = gedx.getSourceDescriptions()[0];
458
  assert.equal(description.getId(), 'sd1');
459
  assert.equal(description.getResourceType(), 'http://some/type');
460
  assert.equal(description.getCitations().length, 1);
461
  assert.equal(description.getCitations()[0].getLang(), 'en');
462
  assert.equal(description.getCitations()[0].getValue(), 'Long source citation');
463
  assert.equal(description.getMediaType(), 'book');
464
  assert.equal(description.getAbout(), 'http://a/resource');
465
  assert.equal(description.getMediator().getResource(), 'http://mediator');
466
  assert.equal(description.getSources().length, 1);
467
  assert.equal(description.getSources()[0].getDescription(), 'http://source/reference');
468
  assert.equal(description.getAnalysis().getResource(), 'http://analysis');
469
  assert.equal(description.getComponentOf().getDescription(), 'http://container');
470
  assert.equal(description.getTitles().length, 2);
471
  assert.equal(description.getTitles()[0].getLang(), 'en');
472
  assert.equal(description.getTitles()[0].getValue(), 'Title');
473
  assert.equal(description.getTitles()[1].getLang(), 'es');
474
  assert.equal(description.getTitles()[1].getValue(), 'Titulo');
475
  assert.equal(description.getNotes().length, 1);
476
  assert.equal(description.getNotes()[0].getSubject(), 'Note');
477
  assert.equal(description.getNotes()[0].getText(), 'Some note text');
478
  assert.equal(description.getAttribution().getCreated().getTime(), 1234578129);
479
  assert.equal(description.getRights().length, 1);
480
  assert.equal(description.getRights()[0].getResource(), 'https://some/right');
481
  assert.equal(description.getCoverage().getTemporal().getFormal(), '+2015');
482
  assert.equal(description.getCoverage().getSpatial().getOriginal(), 'A place');
483
  assert.equal(description.getDescriptions().length, 1);
484
  assert.equal(description.getDescriptions()[0].getValue(), 'A description');
485
  assert.equal(description.getIdentifiers().identifiers.$, 'identifier');
486
  assert.equal(description.getCreated(), 1000000);
487
  assert.equal(description.getModified(), 11111111);
488
  assert.equal(description.getRepository().getResource(), 'http://repository');
489
  
490
  assert.equal(gedx.getAgents().length, 1);
491
  var agent = gedx.getAgents()[0];
492
  assert.equal(agent.getId(), 'agent');
493
  assert.equal(agent.getIdentifiers().identifiers.$, 'ident');
494
  assert.equal(agent.getNames().length, 1);
495
  assert.equal(agent.getNames()[0].getLang(), 'en');
496
  assert.equal(agent.getNames()[0].getValue(), 'Name');
497
  assert.equal(agent.getHomepage().getResource(), 'http://homepage');
498
  assert.equal(agent.getOpenid().getResource(), 'http://openid');
499
  assert.equal(agent.getAccounts().length, 1);
500
  assert.equal(agent.getAccounts()[0].getAccountName(), 'jimbo');
501
  assert.equal(agent.getEmails().length, 1);
502
  assert.equal(agent.getEmails()[0].getResource(), 'http://email');
503
  assert.equal(agent.getPhones().length, 1);
504
  assert.equal(agent.getPhones()[0].getResource(), 'http://phone');
505
  assert.equal(agent.getAddresses().length, 1);
506
  assert.equal(agent.getAddresses()[0].getValue(), 'big long address');
507
  assert.equal(agent.getAddresses()[0].getPostalCode(), '123456');
508
  assert.equal(agent.getPerson().getResource(), 'http://person');
509
  
510
  assert.equal(gedx.getEvents().length, 1);
511
  var event = gedx.getEvents()[0];
512
  assert.equal(event.getType(), 'http://gedcomx.org/Marriage');
513
  assert.equal(event.getDate().getFormal(), '+2002-06-06');
514
  assert.equal(event.getPlace().getOriginal(), 'Her town, MN');
515
  assert.equal(event.getRoles().length, 1);
516
  assert.equal(event.getRoles()[0].getPerson().getResource(), 'http://groom');
517
  assert.equal(event.getRoles()[0].getType(), 'http://gedcomx.org/Participant');
518
  
519
  assert.equal(gedx.getDocuments().length, 1);
520
  var doc = gedx.getDocuments()[0];
521
  assert.equal(doc.getType(), 'http://gedcomx.org/Abstract');
522
  assert.equal(doc.getExtracted(), false);
523
  assert.equal(doc.getTextType(), 'plain');
524
  assert.equal(doc.getText(), 'Lots of text');
525
  assert.equal(doc.getAttribution().getCreated().getTime(), 123456789);
526
  
527
  assert.equal(gedx.getPlaces().length, 1);
528
  var place = gedx.getPlaces()[0];
529
  assert.equal(place.getNames().length, 1);
530
  assert.equal(place.getNames()[0].getLang(), 'en');
531
  assert.equal(place.getNames()[0].getValue(), 'Pope\'s Creek, Westmoreland, Virginia, United States');
532
  assert.equal(place.getType(), 'http://identifier/for/the/place/type');
533
  assert.equal(place.getPlace().getResource(), 'http://place');
534
  assert.equal(place.getJurisdiction().getResource(), 'http://jurisdiction');
535
  assert.equal(place.getLatitude(), 27.9883575);
536
  assert.equal(place.getLongitude(), 86.9252014);
537
  assert.equal(place.getTemporalDescription().getFormal(), '+1899-01-04');
538
  assert.equal(place.getSpatialDescription().getResource(), 'http://uri/for/KML/document');
539
  
540
  assert.equal(gedx.getRecordDescriptors().length, 1);
541
  var rd = gedx.getRecordDescriptors()[0];
542
  assert.equal(rd.getId(), 'rd');
543
  assert.equal(rd.getLang(), 'en-US');
544
  assert.equal(rd.getFields().length, 1);
545
  assert.equal(rd.getFields()[0].getOriginalLabel(), 'Name');
546
  assert.equal(rd.getFields()[0].getValues().length, 1);
547
  
548
  assert.equal(gedx.getCollections().length, 1);
549
  var collection = gedx.getCollections()[0];
550
  assert.equal(collection.getId(), 'collection');
551
  assert.equal(collection.getLang(), 'en-US');
552
  assert.equal(collection.getContent()[0].getResourceType(), 'http://gedcomx.org/Record');
553
  assert.equal(collection.getTitle(), 'Collection Title');
554
  assert.equal(collection.getSize(), 183429102);
555
  assert(GedcomX.Attribution.isInstance(collection.getAttribution()));
556
  
557
  assert.jsonSchema(gedx.toJSON(), GedcomXSchema);
558
}