-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first tests and basic functionality to match. Addresses #4
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
1 parent
90dc68b
commit be22cf8
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |