-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
224 lines (185 loc) · 6.95 KB
/
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* eslint prefer-arrow-callback: 0 */
'use strict';
const assert = require('assert');
const turbasen = require('.');
process.env.NODE_ENV = 'test';
describe('conf', function describe() {
it('sets default config from environment', function it() {
assert.equal(turbasen.conf.API_KEY, process.env.NTB_API_KEY);
assert.equal(turbasen.conf.API_ENV, process.env.NTB_API_ENV);
assert.equal(turbasen.conf.USER_AGENT, process.env.NTB_USER_AGENT);
});
});
describe('configure()', function describe() {
afterEach(function afterEach() {
turbasen.configure({
API_KEY: process.env.NTB_API_KEY,
API_ENV: process.env.NTB_API_ENV,
USER_AGENT: process.env.NTB_USER_AGENT,
});
});
it('updates conf variables', function it() {
turbasen.configure({
API_KEY: 'foo',
API_ENV: 'bar',
USER_AGENT: 'baz',
});
assert.equal(turbasen.conf.API_KEY, 'foo');
assert.equal(turbasen.conf.API_ENV, 'bar');
assert.equal(turbasen.conf.USER_AGENT, 'baz');
});
it('regenares request object');
});
describe('_requestDefaults()', function describe() {
it('returns request object', function it() {
assert.equal(typeof turbasen._requestDefaults(), 'function');
});
});
describe('api', function describe() {
it('exposes data types functions', function it() {
[
'aktiviteter',
'bilder',
'grupper',
'områder',
'steder',
'turer',
].forEach(function forEach(type) {
assert.equal(typeof turbasen[type], 'function');
assert.equal(typeof turbasen[type].each, 'function');
assert.equal(typeof turbasen[type].post, 'function');
assert.equal(typeof turbasen[type].get, 'function');
assert.equal(typeof turbasen[type].delete, 'function');
assert.equal(typeof turbasen[type].put, 'function');
assert.equal(typeof turbasen[type].patch, 'function');
});
});
it('exposes each document itterator function', function it(done) {
this.timeout(10000);
let counter = 0;
const opts = {
status: 'Offentlig',
tags: 'Bretur',
limit: 10,
};
turbasen.turer.each(opts, function eachItem(item, next) {
counter++;
process.nextTick(next);
}, function eachDone(err) {
assert.ifError(err);
assert.equal(counter, 30);
done();
});
});
});
describe('steder-near.js', function describe() {
it('returns cabins near coornidate', function it(done) {
require('./examples/steder-near').on('data', function on(data) {
assert.equal(data.documents[0].navn, 'Selhamar');
assert.equal(data.documents[1].navn, 'Åsedalen');
assert.equal(data.documents[2].navn, 'Torvedalshytta');
assert.equal(data.documents[3].navn, 'Vatnane');
assert.equal(data.documents[4].navn, 'Solrenningen');
done();
});
});
});
describe('grupper-cache.js', function describe() {
it('reutrns a Map of all groups with name and url', function it(done) {
this.timeout(15000);
const grupper = require('./examples/grupper-cache');
grupper({}, (err, groups) => {
assert.ifError(err);
for (const g of groups) {
assert.equal(typeof g[0], 'string');
assert.equal(typeof g[1], 'object');
assert.equal(typeof g[1].navn, 'string');
assert.equal(typeof g[1].url, 'string');
}
done();
});
});
});
describe('turer-title-with-year.js', function describe() {
it('returns trips with year in the title', function it(done) {
this.timeout(15000);
require('./examples/turer-title-with-year').on('data', data => {
assert(/201[0-9]/.test(data.navn));
}).on('done', done);
});
});
describe('municipality-users.js', function describe() {
it('returns trips created by municipality users', function it(done) {
this.timeout(15000);
require('./examples/municipality-users').on('data', tur => {
assert(
/kommune/.test(tur.privat.opprettet_av.epost) ||
/kommune/.test(tur.privat.endret_av.epost)
);
}).on('done', done);
});
});
describe('util.attribution()', function describe() {
let type;
let doc;
let authors;
let license;
beforeEach(function beforeEach() {
type = 'tur';
doc = { _id: 'abc', navn: 'Foo Bar' };
authors = [
{ navn: 'Foo', url: 'http://foo.bar' },
];
license = 'CC BY-SA 4.0';
});
it('returns attribution for single author group', function it() {
assert.equal(turbasen.util.attribution(type, doc, authors, license), [
'"<a href="http://www.ut.no/tur/abc/">Foo Bar</a>"',
'av <a href="http://foo.bar">Foo</a>',
'er lisensiert under <a href="http://creativecommons.org/licenses/by-sa/4.0/deed.no">CC BY-SA 4.0</a>.',
].join(' '));
});
it('returns attribution for multiple author groups', function it() {
authors.push({ navn: 'Bar', url: 'http://bar.foo' });
assert.equal(turbasen.util.attribution(type, doc, authors, license), [
'"<a href="http://www.ut.no/tur/abc/">Foo Bar</a>"',
'av <a href="http://foo.bar">Foo</a> og <a href="http://bar.foo">Bar</a>',
'er lisensiert under <a href="http://creativecommons.org/licenses/by-sa/4.0/deed.no">CC BY-SA 4.0</a>.',
].join(' '));
authors.push({ navn: 'Baz', url: 'http://baz.foo' });
assert.equal(turbasen.util.attribution(type, doc, authors, license), [
'"<a href="http://www.ut.no/tur/abc/">Foo Bar</a>"',
'av <a href="http://foo.bar">Foo</a>, <a href="http://bar.foo">Bar</a> og <a href="http://baz.foo">Baz</a>',
'er lisensiert under <a href="http://creativecommons.org/licenses/by-sa/4.0/deed.no">CC BY-SA 4.0</a>.',
].join(' '));
});
it('returns attribution for named author', function it() {
assert.equal(turbasen.util.attribution(type, doc, 'Foo', license), [
'"<a href="http://www.ut.no/tur/abc/">Foo Bar</a>"',
'av Foo',
'er lisensiert under <a href="http://creativecommons.org/licenses/by-sa/4.0/deed.no">CC BY-SA 4.0</a>.',
].join(' '));
});
it('returns attribution for no author', function it() {
assert.equal(turbasen.util.attribution(type, doc, undefined, license), [
'"<a href="http://www.ut.no/tur/abc/">Foo Bar</a>"',
'av Ukjent',
'er lisensiert under <a href="http://creativecommons.org/licenses/by-sa/4.0/deed.no">CC BY-SA 4.0</a>.',
].join(' '));
});
it('returns attribution for untitled document', function it() {
doc.navn = undefined;
assert.equal(turbasen.util.attribution(type, doc, authors, license), [
'"<a href="http://www.ut.no/tur/abc/">Uten Navn</a>"',
'av <a href="http://foo.bar">Foo</a>',
'er lisensiert under <a href="http://creativecommons.org/licenses/by-sa/4.0/deed.no">CC BY-SA 4.0</a>.',
].join(' '));
});
it('returns attribution for unknown license', function it() {
assert.equal(turbasen.util.attribution(type, doc, authors, 'CC BY-NC-ND 3.0 NO'), [
'"<a href="http://www.ut.no/tur/abc/">Foo Bar</a>"',
'av <a href="http://foo.bar">Foo</a>',
'er lisensiert under CC BY-NC-ND 3.0 NO.',
].join(' '));
});
});