UNPKG

1.91 kBJavaScriptView Raw
1/*eslint no-unused-vars:0 */
2/*global describe, beforeEach, it */
3
4'use strict';
5
6GLOBAL.fetch = require('node-fetch');
7
8const nock = require('nock');
9const expect = require('chai').expect;
10const subject = require('../src/things');
11
12const fixtureFound = require('./fixtures/es-v3-topics-search-found.json');
13const fixtureEmpty = require('./fixtures/es-interface-things-empty');
14
15describe('Things', () => {
16
17 describe('results found', () => {
18
19 let result;
20 let request;
21 let data;
22
23 beforeEach(() => {
24 data = {
25 "identifierValues": ["Mg==-R2VucmVz", "ZWI2YTE0YjgtOTIyYy00OTIyLWExOTYtZmRmNzk0YzA4NGFk-QnJhbmRz", "Mg==-R2VucmVz"]
26 };
27
28 request = nock('https://next-elastic.ft.com')
29 .post('/v3_api_v2/item/_search')
30 .times(3)
31 .reply(200, fixtureFound);
32
33 return subject(data).then(d => result = d);
34 });
35
36 it('returns an array of source terms', () => {
37 expect(result).to.be.an.instanceof(Object);
38 expect(result.items).to.be.an.instanceof(Array);
39
40 result.items.forEach(item => {
41 expect(item).not.to.include.keys('term', 'body');
42 });
43 });
44
45 it('appends total search result count', () => {
46 expect(result.total).to.equal(data.identifierValues.length);
47 });
48
49 });
50
51 describe('results empty', () => {
52
53 let result;
54 let request;
55
56 beforeEach(() => {
57 request = nock('https://ft-next-es-interface-eu.herokuapp.com',{allowUnmocked: true})
58 .post('/things')
59 .reply(200, fixtureEmpty);
60
61 return subject({
62 "identifierValues": ["TnN0ZWluX0dMX0V1cm9wZQ==-R0w=dsdd"],
63 "authority": "http://api.ft.com/system/FT-TME"
64 }).then(data => result = data);
65 });
66
67 it('returns an empty array', () => {
68 expect(result).to.be.an.instanceof(Object);
69 expect(result.items).to.be.an.instanceof(Array);
70 expect(result.items).to.have.length(0);
71 });
72
73 it('appends total search result count', () => {
74 expect(result.total).to.equal(0);
75 });
76
77 });
78
79});