diff --git a/test/cases/getSkipSegments.js b/test/cases/getSkipSegments.js new file mode 100644 index 0000000..7e33518 --- /dev/null +++ b/test/cases/getSkipSegments.js @@ -0,0 +1,94 @@ +var request = require('request'); +var db = require('../../src/databases/databases.js').db; +var utils = require('../utils.js'); + +/* + *CREATE TABLE IF NOT EXISTS "sponsorTimes" ( + "videoID" TEXT NOT NULL, + "startTime" REAL NOT NULL, + "endTime" REAL NOT NULL, + "votes" INTEGER NOT NULL, + "UUID" TEXT NOT NULL UNIQUE, + "userID" TEXT NOT NULL, + "timeSubmitted" INTEGER NOT NULL, + "views" INTEGER NOT NULL, + "shadowHidden" INTEGER NOT NULL +); + */ + +describe('getSkipSegments', () => { + before(() => { + db.exec("INSERT INTO sponsorTimes VALUES ('testtesttest', 1, 11, 2, '1-uuid-0', 'testman', 0, 50, 'sponsor', 0)"); + db.exec("INSERT INTO sponsorTimes VALUES ('testtesttest', 20, 33, 2, '1-uuid-2', 'testman', 0, 50, 'intro', 0)"); + db.exec("INSERT INTO sponsorTimes VALUES ('testtesttest,test', 1, 11, 2, '1-uuid-1', 'testman', 0, 50, 'sponsor', 0)"); + db.exec("INSERT INTO sponsorTimes VALUES ('test3', 1, 11, 2, '1-uuid-4', 'testman', 0, 50, 'sponsor', 0)"); + db.exec("INSERT INTO sponsorTimes VALUES ('test3', 1, 11, 2, '1-uuid-5', 'testman', 0, 50, 'sponsor', 0)"); + }); + + + it('Should be able to get a time by category', (done) => { + request.get(utils.getbaseURL() + + "/api/skipSegments?videoID=testtesttest&category=sponsor", null, + (err, res, body) => { + if (err) done("Couldn't call endpoint"); + else if (res.statusCode !== 200) done("Status code was: " + res.statusCode); + else { + let data = JSON.parse(res.body); + if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 + && data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") { + done(); + } else { + done("Received incorrect body: " + res.body); + } + } + }); + }); + + it('Should be possible to send unexpected query parameters', (done) => { + request.get(utils.getbaseURL() + + "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor", null, + (err, res, body) => { + if (err) done("Couldn't call endpoint"); + else if (res.statusCode !== 200) done("Status code was: " + res.statusCode); + else { + let data = JSON.parse(res.body); + if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 + && data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") { + done(); + } else { + done("Received incorrect body: " + res.body); + } + } + }); + }); + + it('Should return 404 if no segment found', (done) => { + request.get(utils.getbaseURL() + + "/api/skipSegments?videoID=notarealvideo", null, + (err, res, body) => { + if (err) done("couldn't call endpoint"); + else if (res.statusCode !== 404) done("non 404 respone code: " + res.statusCode); + else done(); // pass + }); + }); + + + it('Should be able send a comma in a query param', (done) => { + request.get(utils.getbaseURL() + + "/api/skipSegments?videoID=testtesttest,test&category=sponsor", null, + (err, res, body) => { + if (err) done("Couldn't call endpoint"); + else if (res.statusCode !== 200) done("Status code was: " + res.statusCode); + else { + let data = JSON.parse(res.body); + if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 + && data[0].category === "sponsor" && data[0].UUID === "1-uuid-1") { + done(); + } else { + done("Received incorrect body: " + res.body); + } + } + }); + }); + +}); \ No newline at end of file diff --git a/test/cases/oldGetSponsorTime.js b/test/cases/oldGetSponsorTime.js index 33fed2d..ffb1264 100644 --- a/test/cases/oldGetSponsorTime.js +++ b/test/cases/oldGetSponsorTime.js @@ -19,13 +19,13 @@ var utils = require('../utils.js'); describe('getVideoSponsorTime (Old get method)', () => { before(() => { - db.exec("INSERT INTO sponsorTimes VALUES ('testtesttest', 1, 11, 2, 'uuid-0', 'testman', 0, 50, 'sponsor', 0)"); - db.exec("INSERT INTO sponsorTimes VALUES ('testtesttest,test', 1, 11, 2, 'uuid-1', 'testman', 0, 50, 'sponsor', 0)"); + db.exec("INSERT INTO sponsorTimes VALUES ('old-testtesttest', 1, 11, 2, 'uuid-0', 'testman', 0, 50, 'sponsor', 0)"); + db.exec("INSERT INTO sponsorTimes VALUES ('old-testtesttest,test', 1, 11, 2, 'uuid-1', 'testman', 0, 50, 'sponsor', 0)"); }); it('Should be able to get a time', (done) => { request.get(utils.getbaseURL() - + "/api/getVideoSponsorTimes?videoID=testtesttest", null, + + "/api/getVideoSponsorTimes?videoID=old-testtesttest", null, (err, res, body) => { if (err) done("Couldn't call endpoint"); else if (res.statusCode !== 200) done("non 200"); @@ -46,7 +46,7 @@ describe('getVideoSponsorTime (Old get method)', () => { it('Should be possible to send unexpected query parameters', (done) => { request.get(utils.getbaseURL() - + "/api/getVideoSponsorTimes?videoID=testtesttest&fakeparam=hello", null, + + "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello", null, (err, res, body) => { if (err) done("couldn't callendpoint"); else if (res.statusCode !== 200) done("non 200"); @@ -56,7 +56,7 @@ describe('getVideoSponsorTime (Old get method)', () => { it('Should be able send a comma in a query param', (done) => { request.get(utils.getbaseURL() - + "/api/getVideoSponsorTimes?videoID=testtesttest,test", null, + + "/api/getVideoSponsorTimes?videoID=old-testtesttest,test", null, (err, res, body) => { if (err) done("couln't call endpoint"); else if (res.statusCode !== 200) done("non 200 response: " + res.statusCode); @@ -67,7 +67,7 @@ describe('getVideoSponsorTime (Old get method)', () => { it('Should be able to get the correct time', (done) => { request.get(utils.getbaseURL() - + "/api/getVideoSponsorTimes?videoID=testtesttest", null, + + "/api/getVideoSponsorTimes?videoID=old-testtesttest", null, (err, res, body) => { if (err) done("couldn't call endpoint"); else if (res.statusCode !== 200) done("non 200");