Skip to content

Commit

Permalink
Added first tests and basic functionality to match. Addresses #4
Browse files Browse the repository at this point in the history
This introduces tests to check if urls without http at the start return
false when checked if they are part of the black list. This actually
feels unwanted since it anyway wouldn't match the blacklist. But keeping
it for now. Also wrote the matching function to take in a parameter of a
url and a dictionary of urls to check against. The matcher function will
be responsible for stripping URLs down to root domain names to check if
they can be found inside the dictionary. Currently it returns true or
false, but I'll want it to return something more informative later like
an empty string for no matches and the 'key' value for the dictionary if
it does find a matching url.
  • Loading branch information
kiriappeee committed Sep 23, 2015
1 parent 90dc68b commit be22cf8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/matcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function doesUrlMatchBlackList(urlToMatch, dictionary){
if(urlToMatch.indexOf('http') == -1){
return false;
}
if(dictionary.urls[urlToMatch]){
return true;
}

}

module.exports.doesUrlMatchBlackList = doesUrlMatchBlackList;
26 changes: 26 additions & 0 deletions core/spec/MatcherSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe("Matcher", function(){
matcher = require('../matcher.js');
var dictionary = {urls:
{"https://www.heroku.com/": {
"isDirect": false,
"parent": "https://salesforce.com/",
"source": "",
"description": "",
},
"https://www.salesforce.com/": {
"isDirect": true,
"parent": "",
"source": "",
"description": "",
}
}
};
it("should return false for any url that doesn't contain http: at the start", function(){
expect(matcher.doesUrlMatchBlackList('ftp://abc.com/9.jpg', {})).toBe(false);
expect(matcher.doesUrlMatchBlackList('www.abc.com/9.jpg', {})).toBe(false);
});
it("should return true for any url that does match the list", function(){
expect(matcher.doesUrlMatchBlackList('https://www.heroku.com/', dictionary)).toBe(true);
expect(matcher.doesUrlMatchBlackList('https://www.salesforce.com/', dictionary)).toBe(true);
});
});
9 changes: 9 additions & 0 deletions core/spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}

0 comments on commit be22cf8

Please sign in to comment.