Adding test.

This commit is contained in:
gaba
2017-02-07 13:57:46 -08:00
parent d08a9fb7b2
commit 3effd11ad2
2 changed files with 58 additions and 8 deletions
+6 -8
View File
@@ -55,17 +55,15 @@ class Domainlist {
// This will return true in the event that at least one blockword is found
// in the phrase.
return list.every((domain) => {
// Not considering wildcards for now.
if (domain === domainToMatch) {
for (let i = 0; i < list.length; i++) {
if (list[i] === domainToMatch) {
return true;
}
}
// We've walked over all the whitelisted domains, and haven't had a
// mismatch... It is not an allowed domain!
return false;
});
// We've walked over all the whitelisted domains, and haven't had a
// mismatch... It is not an allowed domain!
return false;
}
/**
+52
View File
@@ -0,0 +1,52 @@
const expect = require('chai').expect;
const Domainlist = require('../../services/domainlist');
const SettingsService = require('../../services/settings');
describe('services.Domainlist', () => {
const domainlists = {
whitelist: [
'nytimes.com',
'wapo.com'
]
};
let domainlist = new Domainlist();
const settings = {id: '1', moderation: 'PRE', domainlist: {whitelist: ['nytimes.com', 'wapo.com']}};
beforeEach(() => SettingsService.init(settings));
describe('#init', () => {
before(() => domainlist.upsert(domainlists));
it('has entries', () => {
expect(domainlist.lists.whitelist).to.not.be.empty;
});
});
describe('#match', () => {
const whiteList = Domainlist.parseList(domainlists['whitelist']);
it('does match on an included domain', () => {
[
'wapo.com',
'nytimes.com'
].forEach((domain) => {
expect(domainlist.match(whiteList, domain)).to.be.true;
});
});
it('does not match on a not included domain', () => {
[
'badsite.com',
'www.badsite.com',
'otherexample.com'
].forEach((domain) => {
expect(domainlist.match(whiteList, domain)).to.be.false;
});
});
});
});