1 |
|
2 | 'use strict';
|
3 |
|
4 | GLOBAL.fetch = require('node-fetch');
|
5 |
|
6 | const api = require('../main');
|
7 | const nock = require('nock');
|
8 | const expect = require('chai').expect;
|
9 |
|
10 | nock('http://api.ft.com')
|
11 | .get('/content?isAnnotatedBy=http://api.ft.com/things/5c7592a8-1f0c-11e4-b0cb-b2227cce2b54')
|
12 | .reply(200, require('./fixtures/capi-v2-is-annotated-by'))
|
13 |
|
14 | .get('/content/12dc0348-d780-11e4-94b1-00144feab7de')
|
15 | .reply(200, require('./fixtures/capi-v2-article'))
|
16 |
|
17 | .get('/content/a0d9ce37-f3f0-3999-8be1-342d3988438c')
|
18 | .times(2)
|
19 | .reply(200, require('./fixtures/capi-v2-article-a0d9ce37'))
|
20 |
|
21 | .get('/content/24d3b305-9f9d-3fb8-9ddc-f33a22eeb248')
|
22 | .times(2)
|
23 | .reply(200, require('./fixtures/capi-v2-article-24d3b305'))
|
24 |
|
25 | .get('/lists/3c99c2ba-a6ae-11e2-95b1-00144feabdc0')
|
26 | .reply(200, require('./fixtures/capi-v2-lists'))
|
27 |
|
28 | .get('/organisations/89a11e71-2651-3ded-bd99-cbf02cddcfb4')
|
29 | .reply(200, require('./fixtures/capi-v2-organisation'))
|
30 |
|
31 | .get('/hui/content/last-1-day?user-sector=http://api.ft.com/things/96486956-8505-312b-bbaa-20926a9fd790')
|
32 | .reply(200, require('./fixtures/hui'))
|
33 |
|
34 | .get('/hui/content/last-1-week?user-industry=http://api.ft.com/things/077bea1d-01ca-328e-aa0b-d7dc92796030&user-position=http://api.ft.com/things/7a402527-0737-3d7a-8f29-13779eaa4e18')
|
35 | .reply(200, require('./fixtures/hui'));
|
36 |
|
37 | nock('https://next-elastic.ft.com')
|
38 | .post('/v3_api_v2/item/_mget', {
|
39 | docs: [
|
40 | { _id: '12dc0348-d780-11e4-94b1-00144feab7de', _source: true }
|
41 | ]
|
42 | })
|
43 | .reply(200, require('./fixtures/elastic-v3-article'))
|
44 | .post('/v3_api_v2/item/_mget', {
|
45 | docs: [
|
46 | { _id: 'a0d9ce37-f3f0-3999-8be1-342d3988438c', _source: true },
|
47 | { _id: '24d3b305-9f9d-3fb8-9ddc-f33a22eeb248', _source: true }
|
48 | ]
|
49 | })
|
50 | .reply(200, require('./fixtures/elastic-v3-article-multiple'));
|
51 |
|
52 | describe('content', function () {
|
53 | it('should optionally get content from elastic search', function () {
|
54 | return api.content({ uuid: '12dc0348-d780-11e4-94b1-00144feab7de' })
|
55 | .then(function (article) {
|
56 | expect(article.title).to.be.a.string;
|
57 | });
|
58 | });
|
59 |
|
60 | it('should support mgets with elastic search', function () {
|
61 | return api.content({
|
62 | uuid: ['a0d9ce37-f3f0-3999-8be1-342d3988438c', '24d3b305-9f9d-3fb8-9ddc-f33a22eeb248']
|
63 | });
|
64 | });
|
65 |
|
66 | it('should just return nothing if requested nothing', function () {
|
67 | return api.content({
|
68 | uuid: []
|
69 | })
|
70 | .then(result => {
|
71 | expect(result).to.eql([]);
|
72 | });
|
73 | });
|
74 | });
|
75 |
|
76 | describe('organisation', function () {
|
77 | it('should return content', function () {
|
78 | return api.organisations({ uuid: '89a11e71-2651-3ded-bd99-cbf02cddcfb4' })
|
79 | .then(function (article) {
|
80 | expect(article.title).to.be.a.string;
|
81 | });
|
82 | });
|
83 | });
|
84 |
|
85 | describe('lists', function () {
|
86 | it('should return content', function () {
|
87 | return api.lists({ uuid: '3c99c2ba-a6ae-11e2-95b1-00144feabdc0' })
|
88 | .then(function (list) {
|
89 | expect(list.title).to.be.a.string;
|
90 | expect(list.items.length).to.equal(3);
|
91 | });
|
92 | });
|
93 | });
|
94 |
|
95 | describe('is-annotated-by', function () {
|
96 | it('should return content', function () {
|
97 | return api.contentAnnotatedBy({ uuid: '5c7592a8-1f0c-11e4-b0cb-b2227cce2b54' })
|
98 | .then(function (articles) {
|
99 | expect(articles.length).to.equal(2);
|
100 | });
|
101 | });
|
102 | });
|
103 |
|
104 | describe('hui', function () {
|
105 | it('should return content', function () {
|
106 | return api.hui({
|
107 | sector: 'http://api.ft.com/things/96486956-8505-312b-bbaa-20926a9fd790',
|
108 | count: 10
|
109 | })
|
110 | .then(function (articles) {
|
111 | expect(articles.length).to.equal(10);
|
112 | });
|
113 | });
|
114 |
|
115 | it('can combine parameters', function () {
|
116 | return api.hui({
|
117 | industry: 'http://api.ft.com/things/077bea1d-01ca-328e-aa0b-d7dc92796030',
|
118 | position: 'http://api.ft.com/things/7a402527-0737-3d7a-8f29-13779eaa4e18',
|
119 | period: 'last-1-week'
|
120 | })
|
121 | .then(function (articles) {
|
122 | expect(articles.length).to.equal(10);
|
123 | });
|
124 | });
|
125 | });
|