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