Skip to content

Commit 1f3a288

Browse files
author
Hans Kristian Flaatten
committed
test(grupper): add examples/grupper.js to test suite
1 parent 7c3a146 commit 1f3a288

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

examples/grupper.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const turbasen = require('../');
4+
5+
module.exports = (opts, cb) => {
6+
const groups = new Map();
7+
8+
turbasen.grupper.each({ fields: 'status,navn,lenker' }, (group, next) => {
9+
const cache = {
10+
navn: group.navn ? group.navn : 'Ukjent Gruppe',
11+
url: `http://www.ut.no/gruppe/${group._id}`,
12+
};
13+
14+
if (group.lenker) {
15+
for (const u of group.lenker) {
16+
if (u.type === 'Hjemmeside') {
17+
cache.url = u.url;
18+
}
19+
}
20+
}
21+
22+
if (opts.debug || !module.parent) {
23+
console.log(new Date(), cache);
24+
}
25+
26+
groups.set(group._id, cache);
27+
28+
next();
29+
}, err => {
30+
cb(err, groups);
31+
})
32+
};
33+
34+
if (!module.parent) {
35+
module.exports({}, (err, groups) => {})
36+
}

test.js

+21
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ describe('near.js', function describe() {
9999
});
100100
});
101101

102+
describe('grupper.js', function describe() {
103+
it('reutrns a Map of groups with names and url', function it(done) {
104+
this.timeout(15000);
105+
106+
const grupper = require('./examples/grupper');
107+
108+
grupper({}, (err, groups) => {
109+
assert.ifError(err);
110+
111+
for (const g of groups) {
112+
assert.equal(typeof g[0], 'string');
113+
assert.equal(typeof g[1], 'object');
114+
assert.equal(typeof g[1].navn, 'string');
115+
assert.equal(typeof g[1].url, 'string');
116+
}
117+
118+
done();
119+
});
120+
});
121+
});
122+
102123
describe('util.attribution()', function describe() {
103124
let type;
104125
let doc;

0 commit comments

Comments
 (0)