-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelated-items.test.js
51 lines (47 loc) · 1.99 KB
/
related-items.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const test = require('tape');
const config = require('../config');
const buildJSONResponse = require('../lib/jsonapi-response.js');
const buildHTMLData = require('../lib/transforms/json-to-html-data');
const sortRelated = require('../lib/sort-related-items');
let JSONAPIResponse;
let HTMLData;
const person = require('./fixtures/elastic-responses/example-get-response-person.json');
const relatedItems = sortRelated(require('./fixtures/elastic-responses/database.json').related.cp2735.response.hits.hits, 'cp2735');
test('Response is built succesfully', (t) => {
t.plan(1);
t.doesNotThrow(() => {
JSONAPIResponse = buildJSONResponse(person, config, relatedItems);
}, 'Building response does not throw an error');
t.end();
});
test('HTML Response is built succesfully', (t) => {
t.plan(2);
t.doesNotThrow(() => {
JSONAPIResponse = buildJSONResponse(person, config, relatedItems);
}, 'Building JSON response does not throw an error');
t.doesNotThrow(() => {
HTMLData = buildHTMLData(JSONAPIResponse);
}, 'Building HTML response does not throw an error');
t.end();
});
test('JSON Response should contain related items', (t) => {
t.plan(3);
t.doesNotThrow(() => {
JSONAPIResponse = buildJSONResponse(person, config, relatedItems);
}, 'Building response does not throw an error');
t.ok(JSONAPIResponse.data.relationships.objects, 'contains related objects');
t.ok(JSONAPIResponse.included.find(el => el.type === 'objects'), 'contains related object info');
t.end();
});
test('HTML Response should contain related items', (t) => {
t.plan(4);
t.doesNotThrow(() => {
JSONAPIResponse = buildJSONResponse(person, config, relatedItems);
}, 'Building JSON response does not throw an error');
t.doesNotThrow(() => {
HTMLData = buildHTMLData(JSONAPIResponse);
}, 'Building HTML response does not throw an error');
t.ok(HTMLData.related.objects, 'contains related objects');
t.ok(HTMLData.related.objects.find(el => el.role === 'maker'), 'related object has role');
t.end();
});