From 00534d91d46c343c294c59175349489bb89d908e Mon Sep 17 00:00:00 2001 From: Joe Dowd Date: Mon, 31 Aug 2020 03:09:47 +0100 Subject: [PATCH] added underscore to category format check --- src/routes/postNoSegments.js | 2 +- test/cases/noSegmentRecords.js | 84 ++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/src/routes/postNoSegments.js b/src/routes/postNoSegments.js index 6aab052..cdbfce9 100644 --- a/src/routes/postNoSegments.js +++ b/src/routes/postNoSegments.js @@ -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; }); diff --git a/test/cases/noSegmentRecords.js b/test/cases/noSegmentRecords.js index 3989258..d439b13 100644 --- a/test/cases/noSegmentRecords.js +++ b/test/cases/noSegmentRecords.js @@ -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: {}},