mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
added underscore to category format check
This commit is contained in:
parent
aa878482d3
commit
00534d91d4
2 changed files with 85 additions and 1 deletions
|
@ -45,7 +45,7 @@ module.exports = (req, res) => {
|
|||
|
||||
// get user categories not already submitted that match accepted format
|
||||
let categoriesToMark = categories.filter((category) => {
|
||||
return !!category.match(/^[a-zA-Z]+$/);
|
||||
return !!category.match(/^[_a-zA-Z]+$/);
|
||||
}).filter((category) => {
|
||||
return noSegmentList.indexOf(category) === -1;
|
||||
});
|
||||
|
|
|
@ -96,6 +96,90 @@ describe('noSegmentRecords', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('Should be able to submit categories with _ in the category', (done) => {
|
||||
let json = {
|
||||
videoID: 'underscore',
|
||||
userID: 'VIPUser-noSegments',
|
||||
categories: [
|
||||
'word_word',
|
||||
]
|
||||
};
|
||||
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postNoSegments", {json},
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['underscore']);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
console.log(body);
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be able to submit categories with upper and lower case in the category', (done) => {
|
||||
let json = {
|
||||
videoID: 'bothCases',
|
||||
userID: 'VIPUser-noSegments',
|
||||
categories: [
|
||||
'wordWord',
|
||||
]
|
||||
};
|
||||
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postNoSegments", {json},
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['bothCases']);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
console.log(body);
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not be able to submit categories with $ in the category', (done) => {
|
||||
let json = {
|
||||
videoID: 'specialChar',
|
||||
userID: 'VIPUser-noSegments',
|
||||
categories: [
|
||||
'word&word',
|
||||
]
|
||||
};
|
||||
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postNoSegments", {json},
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['specialChar']);
|
||||
if (result.length !== 0) {
|
||||
console.log(result);
|
||||
done("Expected 0 entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
console.log(body);
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return 400 for missing params', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postNoSegments", {json: {}},
|
||||
|
|
Loading…
Reference in a new issue