categorys -> categories

This commit is contained in:
Joe Dowd 2020-08-31 01:48:41 +01:00
parent 36ce803828
commit 1e643c1c07
2 changed files with 23 additions and 23 deletions

View file

@ -7,14 +7,14 @@ module.exports = (req, res) => {
// Collect user input data
let videoID = req.body.videoID;
let userID = req.body.userID;
let categorys = req.body.categorys;
let categories = req.body.categories;
// Check input data is valid
if (!videoID
|| !userID
|| !categorys
|| !Array.isArray(categorys)
|| categorys.length === 0
|| !categories
|| !Array.isArray(categories)
|| categories.length === 0
) {
res.status(400).json({
status: 400,
@ -45,20 +45,20 @@ module.exports = (req, res) => {
});
}
// get user categorys not already submitted that match accepted format
let categorysToMark = categorys.filter((category) => {
// get user categories not already submitted that match accepted format
let categoriesToMark = categories.filter((category) => {
return !!category.match(/^[a-zA-Z]+$/);
}).filter((category) => {
return noSegmentList.indexOf(category) === -1;
});
// remove any duplicates
categorysToMark = categorysToMark.filter((category, index) => {
return categorysToMark.indexOf(category) === index;
categoriesToMark = categoriesToMark.filter((category, index) => {
return categoriesToMark.indexOf(category) === index;
});
// create database entry
categorysToMark.forEach((category) => {
categoriesToMark.forEach((category) => {
try {
db.prepare('run', "INSERT INTO noSegments (videoID, userID, category) VALUES(?, ?, ?)", [videoID, userID, category]);
} catch (err) {
@ -73,6 +73,6 @@ module.exports = (req, res) => {
res.status(200).json({
status: 200,
submitted: categorysToMark
submitted: categoriesToMark
});
};

View file

@ -25,11 +25,11 @@ describe('noSegmentRecords', () => {
else done('Version isn\'t greater that 1. Version is ' + version);
});
it('Should be able to submit categorys not in video (http response)', (done) => {
it('Should be able to submit categories not in video (http response)', (done) => {
let json = {
videoID: 'no-segments-video-id',
userID: 'VIPUser-noSegments',
categorys: [
categories: [
'outro',
'shilling',
'shilling',
@ -64,11 +64,11 @@ describe('noSegmentRecords', () => {
});
});
it('Should be able to submit categorys not in video (sql check)', (done) => {
it('Should be able to submit categories not in video (sql check)', (done) => {
let json = {
videoID: 'no-segments-video-id-1',
userID: 'VIPUser-noSegments',
categorys: [
categories: [
'outro',
'shilling',
'shilling',
@ -110,11 +110,11 @@ describe('noSegmentRecords', () => {
});
});
it('Should return 400 for no categorys', (done) => {
it('Should return 400 for no categories', (done) => {
let json = {
videoID: 'test',
userID: 'test',
categorys: []
categories: []
};
request.post(utils.getbaseURL()
@ -133,7 +133,7 @@ describe('noSegmentRecords', () => {
let json = {
videoID: 'test',
userID: null,
categorys: ['sponsor']
categories: ['sponsor']
};
request.post(utils.getbaseURL()
@ -152,7 +152,7 @@ describe('noSegmentRecords', () => {
let json = {
videoID: null,
userID: 'test',
categorys: ['sponsor']
categories: ['sponsor']
};
request.post(utils.getbaseURL()
@ -167,11 +167,11 @@ describe('noSegmentRecords', () => {
});
});
it('Should return 400 object categorys)', (done) => {
it('Should return 400 object categories)', (done) => {
let json = {
videoID: 'test',
userID: 'test',
categorys: {}
categories: {}
};
request.post(utils.getbaseURL()
@ -186,11 +186,11 @@ describe('noSegmentRecords', () => {
});
});
it('Should return 400 bad format categorys', (done) => {
it('Should return 400 bad format categories', (done) => {
let json = {
videoID: 'test',
userID: 'test',
categorys: 'sponsor'
categories: 'sponsor'
};
request.post(utils.getbaseURL()
@ -209,7 +209,7 @@ describe('noSegmentRecords', () => {
let json = {
videoID: 'test',
userID: 'test',
categorys: [
categories: [
'sponsor'
]
};