This repository was archived by the owner on Dec 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter-feed-tests.js
75 lines (59 loc) · 2.43 KB
/
filter-feed-tests.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
'use strict';
var assert = require('assert');
var runner = require('./lib/runner');
var test = runner.test.bind(runner);
var filterFeed = require('../src/filter-feed');
runner.subject('filterFeed');
var fixtureFiltersConfig = [
{ name: 'foo', type: 'blacklist', tokens: ['Foo'] },
{ name: 'bar', type: 'blacklist', tokens: ['Bar'] },
{ name: 'baz', type: 'graylist', tokens: ['Baz'] }
];
var createFilters = filterFeed.createFilters;
runner.subject('.createFilters');
test('creates filters from configs', function() {
var filters = createFilters(fixtureFiltersConfig);
assert.equal(filters[0].name, 'foo');
assert(filters[0].pattern.test('Some title with Foo'));
assert(!filters[0].pattern.test('Some title with Bar'));
assert.equal(filters[1].name, 'bar');
assert(filters[1].pattern.test('Some title with Bar'));
assert(!filters[1].pattern.test('Some title with Foo'));
});
var filters = createFilters(fixtureFiltersConfig);
var mockFinders = {
link: function(mockEntry) { return mockEntry.link; },
title: function(mockEntry) { return mockEntry.title; }
};
var mockRepostGuard = {
checkLink: function(link) { return link !== 'repost.com'; }
};
var defaultShouldSkipEntry = filterFeed.defaultShouldSkipEntry;
runner.subject('.defaultShouldSkipEntry');
test("returns 'blocked' reason for filtered posts", function() {
var entryToBlock = { title: 'Some title with Foo', link: 'foo.com' };
var skip = defaultShouldSkipEntry(entryToBlock, mockFinders, filters, mockRepostGuard);
assert.equal(skip, 'blocked');
});
test("returns 'repost' reason for duplicate posts", function() {
var entryToDedupe = { title: 'Some title', link: 'repost.com' };
var skip = defaultShouldSkipEntry(entryToDedupe, mockFinders, filters, mockRepostGuard);
assert.equal(skip, 'repost');
});
test('otherwise returns false', function() {
var entryToKeep = { title: 'Some title', link: 'foo.com' };
var skip = defaultShouldSkipEntry(entryToKeep, mockFinders, filters, mockRepostGuard);
assert(!skip);
});
test('also returns false for questionable posts, tags title ', function() {
var entryToKeep = { title: 'Some title with Baz', link: 'baz.com',
transformContent: function(tagName, args) {
assert.equal(tagName, 'title');
this.title = args.to();
}
};
var skip = defaultShouldSkipEntry(entryToKeep, mockFinders, filters, mockRepostGuard);
assert(!skip);
assert.equal(entryToKeep.title.indexOf('[baz] '), 0);
});
runner.report();