-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.test.js
159 lines (123 loc) · 4.46 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'use strict';
const _ = require('lodash'),
filename = __filename.split('/').pop().split('.').shift(),
lib = require('./' + filename),
{ expect } = require('chai'),
sinon = require('sinon');
describe(_.startCase(filename), function () {
let sandbox, logSpy;
beforeEach(function () {
sandbox = sinon.sandbox.create();
logSpy = sandbox.spy();
lib.setLog(logSpy);
});
afterEach(function () {
sandbox.restore();
});
function makeFakeRes() {
return {
type: sandbox.spy(),
send: sandbox.spy(),
status: sandbox.spy(),
json: sandbox.spy()
};
}
describe('render', function () {
const fn = lib[this.title];
it('returns an object with `output` and `type` properties', function () {
const fakeRes = {
type: sandbox.spy(),
send: sandbox.spy()
},
result = fn({
feed: [],
meta: {
title: 'foo',
description: 'bar',
link: 'foobar'
}
}, {}, fakeRes);
return result.then(function () {
sinon.assert.calledWith(fakeRes.type, 'text/rss+xml');
sinon.assert.calledOnce(fakeRes.send);
});
});
it('works', function () {
const res = makeFakeRes(),
result = fn({
feed: [],
meta: {}
}, {}, res);
result.then(function () {
sinon.assert.calledWith(res.json, {status: 500, message: 'No data send to XML renderer, cannot respond'});
});
});
});
describe('wrapInItem', function () {
const fn = lib[this.title];
it('returns a passed in value as the value for an `item` property', function () {
sinon.assert.match(fn('foo'), { item: 'foo' });
});
});
describe('cleanNullValues', function () {
const fn = lib[this.title];
it('filters out falsy values from an object', function () {
expect(fn({ foo: 'bar', baz: false, barbaz: null, bazfoo: undefined, foobaz: ''}))
.to.eql({ foo: 'bar' });
});
});
describe('wrapInTopLevel', function () {
const fn = lib[this.title],
val = fn('foo'),
customAttr = {bar: 'http://bar.com'},
valWithAttr = fn('foo', customAttr);
it('wraps the passed in value in an object with and rss array', function () {
expect(Array.isArray(val.rss)).to.be.true;
});
it('has an object with an `_attr` property as the first object of the `rss` Array', function () {
expect(val.rss[0]._attr).to.not.be.undefined;
});
it('merges attr instance data into the default _attr properties', function () {
expect(valWithAttr.rss[0]._attr).to.have.property('bar', 'http://bar.com');
});
it('has an object with a `channel` property as the second object of the `rss` Array', function () {
expect(val.rss[1].channel).to.not.be.undefined;
});
it('the value passed into the function is assigned to the `channel` property', function () {
expect(val.rss[1].channel).to.eql('foo');
});
});
describe('feedMetaTags', function () {
const fn = lib[this.title];
it('returns a function', function () {
const result = fn({title:'foo', description: 'bar', link: 'foobar'});
expect(result).to.be.an('function');
});
it('its callback returns an array', function () {
const result = fn({title:'foo', description: 'bar', link: 'foobar'});
expect(result([])).to.be.an('array');
});
it('its callback assigns passed in values to the return array', function () {
const [ one, two, three ] = fn({title:'foo', description: 'bar', link: 'foobar'})([]);
expect(one.title).to.eql('foo');
expect(two.description).to.eql('bar');
expect(three.link).to.eql('foobar');
});
it('accepts an `opt` object with additional meta tags', function () {
const language = {language: 'en-US'},
result = fn({title:'foo', description: 'bar', link: 'foobar', opt: language})([]);
expect(result).have.to.deep.include(language);
});
});
describe('elevateCategory', function () {
const fn = lib[this.title];
it('returns strings of category tags from each item\'s categories', function () {
var result = fn([{item: [{ category: 'foo'}, { category: 'bar'}]}]);
expect(result).to.eql([ { category: 'foo,bar' } ]);
});
it('returns an empty array if none of the items have categories', function () {
var result = fn([{item: [{ notCategory: 'foo'}, { notCategory: 'bar'}]}]);
expect(result).to.eql([]);
});
});
});