-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
7 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
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
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
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
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,56 @@ | ||
var sanitizer = require('../../../sanitizer/_sort'); | ||
|
||
module.exports.tests = {}; | ||
|
||
module.exports.tests.sanitize_sort = function(test, common) { | ||
test('sort=foo', function(t) { | ||
var raw = { sort: 'foo' }; | ||
var clean = {}; | ||
var res = sanitizer().sanitize(raw, clean); | ||
t.equal(res.errors.length, 0, 'should return no errors'); | ||
t.equal(res.warnings.length, 1, 'should return warning'); | ||
t.equal(res.warnings[0], 'invalid \'sort\', using \'distance\''); | ||
t.equal(clean.sort, 'distance', 'default to distance'); | ||
t.end(); | ||
}); | ||
|
||
test('sort not set', function(t) { | ||
var raw = {}; | ||
var clean = {}; | ||
var res = sanitizer().sanitize(raw, clean); | ||
t.equal(res.errors.length, 0, 'should return no errors'); | ||
t.equal(res.warnings.length, 0, 'should return no warning'); | ||
t.equal(clean.sort, 'distance', 'default to distance'); | ||
t.end(); | ||
}); | ||
|
||
test('return an array of expected parameters in object form for validation', function(t) { | ||
const expected = [{ name: 'sort' }]; | ||
const validParameters = sanitizer().expected(); | ||
t.deepEquals(validParameters, expected); | ||
t.end(); | ||
}); | ||
|
||
var valid_sorts = ['popularity', 'distance']; | ||
valid_sorts.forEach(function (sort) { | ||
test('sort=' + sort, function (t) { | ||
var raw = {sort: sort}; | ||
var clean = {}; | ||
var res = sanitizer().sanitize(raw, clean); | ||
t.equal(res.errors.length, 0, 'should return no errors'); | ||
t.equal(res.warnings.length, 0, 'should return warning'); | ||
t.equal(clean.sort, sort, 'set to correct value'); | ||
t.end(); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports.all = function (tape, common) { | ||
function test(name, testFunction) { | ||
return tape('SANITIZE _sort ' + name, testFunction); | ||
} | ||
|
||
for( var testCase in module.exports.tests ){ | ||
module.exports.tests[testCase](test, common); | ||
} | ||
}; |
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