Fix test cases

This commit is contained in:
Nanobyte 2021-01-06 01:43:28 +01:00
parent 87d2827f0f
commit 797e0b4641
13 changed files with 1638 additions and 1473 deletions

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {getbaseURL, Done} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@ -9,49 +9,47 @@ describe('getIsUserVIP', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP?userID=supertestman", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
.then(res => {
if (res.status !== 200) done("non 200: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should get a 400 if no userID', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 400) done("non 400: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/isUserVIP")
.then(res => {
if (res.status !== 400) done("non 400: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should say a VIP is a VIP', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP?userID=supertestman", null,
(err, res, body) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
else {
if (JSON.parse(body).vip === true) done(); // pass
else done("Result was non-vip when should have been vip");
}
});
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
.then(async res => {
if (res.status !== 200) done("non 200: " + res.status);
else {
const data = await res.json();
if (data.vip === true) done(); // pass
else done("Result was non-vip when should have been vip");
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should say a normal user is not a VIP', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP?userID=regulartestman", null,
(err, res, body) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
else {
if (JSON.parse(body).vip === false) done(); // pass
else done("Result was vip when should have been non-vip");
}
});
fetch(getbaseURL() + "/api/isUserVIP?userID=regulartestman")
.then(async res => {
if (res.status !== 200) done("non 200: " + res.status);
else {
const data = await res.json();
if (data.vip === false) done(); // pass
else done("Result was vip when should have been non-vip");
}
})
.catch(err => done("couldn't call endpoint"));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@ -10,12 +10,11 @@ describe('getSavedTimeForUser', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ "/api/getSavedTimeForUser?userID=testman", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200");
else done(); // pass
});
fetch(getbaseURL() + "/api/getSavedTimeForUser?userID=testman")
.then(res => {
if (res.status !== 200) done("non 200");
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
@ -21,56 +21,47 @@ describe('getSegmentsByHash', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/3272f?categories=["sponsor", "intro"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
else {
done();
} // pass
});
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["sponsor", "intro"]')
.then(res => {
if (res.status !== 200) done("non 200 status code, was " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 if no segments are found even if a video for the given hash is known', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/3272f?categories=["shilling"]', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 status code, was " + res.statusCode);
else {
if (body === '[]') {
done(); // pass
} else {
done("Response had videos");
}
}
});
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["shilling"]')
.then(async res => {
if (res.status !== 404) done("non 404 status code, was " + res.status);
else {
const body = await res.text();
if (body === '[]') done(); // pass
else done("Response had videos");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get an empty array if no videos', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/11111?categories=["shilling"]', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 status code, was " + res.statusCode);
else {
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
else done("non empty array returned");
}
});
fetch(getbaseURL() + '/api/skipSegments/11111?categories=["shilling"]')
.then(async res => {
if (res.status !== 404) done("non 404 status code, was " + res.status);
else {
const body = await res.text();
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
else done("non empty array returned");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 400 prefix too short', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/11?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 400) done("non 400 status code, was " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/11?categories=["shilling"]')
.then(res => {
if (res.status !== 400) done("non 400 status code, was " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 400 prefix too long', (done: Done) => {
@ -79,120 +70,106 @@ describe('getSegmentsByHash', () => {
done('failed to generate a long enough string for the test ' + prefix.length);
return;
}
request.get(getbaseURL()
+ '/api/skipSegments/' + prefix + '?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 400) done("non 400 status code, was " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/' + prefix + '?categories=["shilling"]')
.then(res => {
if (res.status !== 400) done("non 400 status code, was " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should not return 400 prefix in range', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/11111?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 400) done("prefix length 5 gave 400 " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/11111?categories=["shilling"]')
.then(res => {
if (res.status === 400) done("prefix length 5 gave 400 " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 for no hash', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 404) done("expected 404, got " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/?categories=["shilling"]')
.then(res => {
if (res.status !== 404) done("expected 404, got " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 500 for bad format categories', (done: Done) => { // should probably be 400
request.get(getbaseURL()
+ '/api/skipSegments/?categories=shilling', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 500) done("expected 500 got " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/?categories=shilling')
.then(res => {
if (res.status !== 500) done("expected 500 got " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get multiple videos', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/fdaf?categories=["sponsor","intro"]', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
else {
body = JSON.parse(body);
if (body.length !== 2) done("expected 2 video, got " + body.length);
else if (body[0].segments.length !== 2) done("expected 2 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segment for second video, got " + body[1].segments.length);
else done();
}
});
fetch(getbaseURL() + '/api/skipSegments/fdaf?categories=["sponsor","intro"]')
.then(async res => {
if (res.status !== 200) done("non 200 status code, was " + res.status);
else {
const body = await res.json();
if (body.length !== 2) done("expected 2 videos, got " + body.length);
else if (body[0].segments.length !== 2) done("expected 2 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segment for second video, got " + body[1].segments.length);
else done();
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get 200 for no categories (default sponsor)', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/fdaf', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
else {
body = JSON.parse(body);
if (body.length !== 2) done("expected 2 videos, got " + body.length);
else if (body[0].segments.length !== 1) done("expected 1 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
else if (body[0].segments[0].category !== 'sponsor' || body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
else done();
}
});
fetch(getbaseURL() + '/api/skipSegments/fdaf')
.then(async res => {
if (res.status !== 200) done("non 200 status code, was " + res.status);
else {
const body = await res.json();
if (body.length !== 2) done("expected 2 videos, got " + body.length);
else if (body[0].segments.length !== 1) done("expected 1 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
else if (body[0].segments[0].category !== 'sponsor' || body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
else done();
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to post a segment and get it using endpoint', (done: Done) => {
let testID = 'abc123goodVideo';
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: testID,
segments: [{
segment: [13, 17],
category: "sponsor",
}],
},
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done('(post) ' + err);
else if (res.statusCode === 200) {
request.get(getbaseURL()
+ '/api/skipSegments/' + getHash(testID, 1).substring(0, 3), null,
(err, res, body) => {
if (err) done("(get) Couldn't call endpoint");
else if (res.statusCode !== 200) done("(get) non 200 status code, was " + res.statusCode);
else {
body = JSON.parse(body);
if (body.length !== 1) done("(get) expected 1 video, got " + body.length);
else if (body[0].segments.length !== 1) done("(get) expected 1 segments for first video, got " + body[0].segments.length);
else if (body[0].segments[0].category !== 'sponsor') done("(get) segment should be sponsor, was " + body[0].segments[0].category);
else done();
}
});
} else {
done("(post) non 200 status code, was " + res.statusCode);
}
},
);
body: JSON.stringify({
userID: "test",
videoID: testID,
segments: [{
segment: [13, 17],
category: "sponsor",
}],
}),
})
.then(async res => {
if (res.status === 200) {
fetch(getbaseURL() + '/api/skipSegments/' + getHash(testID, 1).substring(0, 3))
.then(async res => {
if (res.status !== 200) done("(get) non 200 status code, was " + res.status);
else {
const body = await res.json();
if (body.length !== 1) done("(get) expected 1 video, got " + body.length);
else if (body[0].segments.length !== 1) done("(get) expected 1 segments for first video, got " + body[0].segments.length);
else if (body[0].segments[0].category !== 'sponsor') done("(get) segment should be sponsor, was " + body[0].segments[0].category);
else done();
}
})
.catch(err => done("(get) Couldn't call endpoint"));
} else {
done("(post) non 200 status code, was " + res.status);
}
})
.catch(err => done('(post) ' + err));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
@ -17,200 +17,194 @@ describe('getSkipSegments', () => {
it('Should be able to get a time by category 1', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&category=sponsor", null,
(err, res) => {
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);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
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: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get a time by category 2', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&category=intro", null,
(err, res) => {
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] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=intro")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get a time by categories array', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]", null,
(err, res) => {
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);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
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: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get a time by categories array 2', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]", null,
(err, res) => {
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] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get multiple times by category', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=multiple&categories=[\"intro\"]", null,
(err, res) => {
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 === 2) {
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-7") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "intro" || segment.UUID !== "1-uuid-6")) {
success = false;
break;
}
fetch(getbaseURL() + "/api/skipSegments?videoID=multiple&categories=[\"intro\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 2) {
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-7") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "intro" || segment.UUID !== "1-uuid-6")) {
success = false;
break;
}
if (success) done();
else done("Received incorrect body: " + res.body);
} else {
done("Received incorrect body: " + res.body);
}
if (success) done();
else done("Received incorrect body: " + body);
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint\n\n" + err));
});
it('Should be able to get multiple times by multiple categories', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]", null,
(err, res) => {
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 === 2) {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 2) {
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-2") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "sponsor" || segment.UUID !== "1-uuid-0")) {
success = false;
break;
}
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-2") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "sponsor" || segment.UUID !== "1-uuid-0")) {
success = false;
break;
}
if (success) done();
else done("Received incorrect body: " + res.body);
} else {
done("Received incorrect body: " + res.body);
}
if (success) done();
else done("Received incorrect body: " + body);
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be possible to send unexpected query parameters', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor", null,
(err, res) => {
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);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(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: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Low voted submissions should be hidden', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=test3&category=sponsor", null,
(err, res) => {
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-4") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=test3&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-4") {
done();
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 if no segment found', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=notarealvideo", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 respone code: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/skipSegments?videoID=notarealvideo")
.then(res => {
if (res.status !== 404) done("non 404 respone code: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should be able send a comma in a query param', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest,test&category=sponsor", null,
(err, res) => {
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);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest,test&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(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: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@ -24,144 +24,101 @@ describe('getUserInfo', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_user_01', null,
(err, res) => {
if (err) {
done('couldn\'t call endpoint');
} else {
if (res.statusCode !== 200) {
done('non 200 (' + res.statusCode + ')');
} else {
done(); // pass
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01')
.then(res => {
if (res.status !== 200) done('non 200 (' + res.status + ')');
else done(); // pass
})
.catch(err => done('couldn\'t call endpoint'));
});
it('Should be able to get a 400 (No userID parameter)', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo', null,
(err, res) => {
if (err) {
done('couldn\'t call endpoint');
} else {
if (res.statusCode !== 400) {
done('non 400');
} else {
done(); // pass
}
}
});
fetch(getbaseURL() + '/api/getUserInfo')
.then(res => {
if (res.status !== 400) done('non 400 (' + res.status + ')');
else done(); // pass
})
.catch(err => done('couldn\'t call endpoint'));
});
it('Should return info', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_user_01', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01')
.then(async res => {
if (res.status !== 200) {
done("non 200");
} else {
const data = await res.json();
if (data.userName !== 'Username user 01') {
done('Returned incorrect userName "' + data.userName + '"');
} else if (data.minutesSaved !== 5) {
done('Returned incorrect minutesSaved "' + data.minutesSaved + '"');
} else if (data.viewCount !== 30) {
done('Returned incorrect viewCount "' + data.viewCount + '"');
} else if (data.segmentCount !== 3) {
done('Returned incorrect segmentCount "' + data.segmentCount + '"');
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.userName !== 'Username user 01') {
done('Returned incorrect userName "' + data.userName + '"');
} else if (data.minutesSaved !== 5) {
done('Returned incorrect minutesSaved "' + data.minutesSaved + '"');
} else if (data.viewCount !== 30) {
done('Returned incorrect viewCount "' + data.viewCount + '"');
} else if (data.segmentCount !== 3) {
done('Returned incorrect segmentCount "' + data.segmentCount + '"');
} else {
done(); // pass
}
}
done(); // pass
}
});
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should get warning data', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_0', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 1) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
} else {
done(); // pass
}
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_0')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();;
if (data.warnings !== 1) done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
else done(); // pass
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should get multiple warnings', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_1', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 2) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 2);
} else {
done(); // pass
}
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_1')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();
if (data.warnings !== 2) done('wrong number of warnings: ' + data.warnings + ', not ' + 2);
else done(); // pass
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should not get warnings if noe', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_2', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 0) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 0);
} else {
done(); // pass
}
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_2')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();
if (data.warnings !== 0) done('wrong number of warnings: ' + data.warnings + ', not ' + 0);
else done(); // pass
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should return userID for userName (No userName set)', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_user_02', null,
(err, res, body) => {
if (err) {
done('couldn\'t call endpoint');
} else {
if (res.statusCode !== 200) {
done('non 200');
} else {
const data = JSON.parse(body);
if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') {
return done('Did not return userID for userName');
}
done(); // pass
}
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_02')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();
if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') {
return done('Did not return userID for userName');
}
});
done(); // pass
}
})
.catch(err => done('couldn\'t call endpoint'));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {db} from '../../src/databases/databases';
@ -48,21 +48,28 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
if (JSON.stringify(body) === JSON.stringify(expected)) {
done();
} else {
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(body));
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json)
})
.then(async res => {
if (res.status === 200) {
const data = await res.json();
if (JSON.stringify(data) === JSON.stringify(expected)) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data));
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit categories not in video (sql check)', (done: Done) => {
@ -79,23 +86,29 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['no-segments-video-id-1']);
if (result.length !== 4) {
console.log(result);
done("Expected 4 entrys in db, got " + result.length);
} else {
done();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json)
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['no-segments-video-id-1']);
if (result.length !== 4) {
console.log(result);
done("Expected 4 entrys in db, got " + result.length);
} else {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit categories with _ in the category', (done: Done) => {
@ -107,23 +120,29 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {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();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 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 {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit categories with upper and lower case in the category', (done: Done) => {
@ -135,23 +154,29 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {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();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 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 {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to submit categories with $ in the category', (done: Done) => {
@ -163,36 +188,47 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {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();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 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 {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for missing params', (done: Done) => {
request.post(getbaseURL()
+ "/api/noSegments", {json: {}},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for no categories', (done: Done) => {
@ -202,16 +238,21 @@ describe('noSegmentRecords', () => {
categories: [],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for no userID', (done: Done) => {
@ -221,16 +262,21 @@ describe('noSegmentRecords', () => {
categories: ['sponsor'],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for no videoID', (done: Done) => {
@ -240,16 +286,21 @@ describe('noSegmentRecords', () => {
categories: ['sponsor'],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 object categories)', (done: Done) => {
@ -259,16 +310,21 @@ describe('noSegmentRecords', () => {
categories: {},
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 bad format categories', (done: Done) => {
@ -278,16 +334,21 @@ describe('noSegmentRecords', () => {
categories: 'sponsor',
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 403 if user is not VIP', (done: Done) => {
@ -299,16 +360,21 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to delete a noSegment record', (done: Done) => {
@ -320,21 +386,26 @@ describe('noSegmentRecords', () => {
],
};
request.delete(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record']);
if (result.length === 0) {
done();
} else {
done("Didn't delete record");
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record']);
if (result.length === 0) {
done();
} else {
done("Status code was " + res.statusCode);
done("Didn't delete record");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to delete one noSegment record without removing another', (done: Done) => {
@ -346,21 +417,26 @@ describe('noSegmentRecords', () => {
],
};
request.delete(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record-1']);
if (result.length === 1) {
done();
} else {
done("Didn't delete record");
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record-1']);
if (result.length === 1) {
done();
} else {
done("Status code was " + res.statusCode);
done("Didn't delete record");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
@ -370,31 +446,37 @@ describe('noSegmentRecords', () => {
*/
it('Should not be able to submit a segment to a video with a no-segment record (single submission)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "sponsor",
}],
},
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
body: JSON.stringify({
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to submit segments to a video where any of the submissions with a no-segment record', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
@ -404,60 +486,66 @@ describe('noSegmentRecords', () => {
segment: [50, 60],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
},),
})
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a segment to a video with a different no-segment record', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "intro",
}],
},
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
body: JSON.stringify({
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a segment to a video with no no-segment records', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "testman42",
videoID: "normalVideo",
segments: [{
segment: [20, 40],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
}),
})
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
@ -24,64 +24,60 @@ describe('getVideoSponsorTime (Old get method)', () => {
});
it('Should be able to get a time', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200");
else done(); // pass
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
.then(res => {
if (res.status !== 200) done("non 200 (" + res.status + ")");
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 if no segment found', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=notarealvideo", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 respone code: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=notarealvideo")
.then(res => {
if (res.status !== 404) done("non 404 respone code: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should be possible to send unexpected query parameters', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello", null,
(err, res) => {
if (err) done("couldn't callendpoint");
else if (res.statusCode !== 200) done("non 200");
else done(); // pass
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello")
.then(res => {
if (res.status !== 200) done("non 200");
else done(); // pass
})
.catch(err => done("couldn't callendpoint"));
});
it('Should be able send a comma in a query param', (done: Done) => {
request.get(getbaseURL()
+ "/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);
else if (JSON.parse(body).UUIDs[0] === 'uuid-1') done(); // pass
else done("couldn't parse response");
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest,test")
.then(async res => {
const body = await res.text();
if (res.status !== 200) done("non 200 response: " + res.status);
else if (JSON.parse(body).UUIDs[0] === 'uuid-1') done(); // pass
else done("couldn't parse response");
})
.catch(err => done("couln't call endpoint"));
});
it('Should be able to get the correct time', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest", null,
(err, res, body) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200");
else {
let parsedBody = JSON.parse(body);
if (parsedBody.sponsorTimes[0][0] === 1
&& parsedBody.sponsorTimes[0][1] === 11
&& parsedBody.UUIDs[0] === 'uuid-0') {
done(); // pass
} else {
done("Wrong data was returned + " + parsedBody);
}
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
.then(async res => {
if (res.status !== 200) done("non 200");
else {
const parsedBody = await res.json();
if (parsedBody.sponsorTimes[0][0] === 1
&& parsedBody.sponsorTimes[0][1] === 11
&& parsedBody.UUIDs[0] === 'uuid-0') {
done(); // pass
} else {
done("Wrong data was returned + " + JSON.stringify(parsedBody));
}
}
});
})
.catch(err => done("couldn't call endpoint"));
});
});

View file

@ -1,52 +1,57 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
describe('postVideoSponsorTime (Old submission method)', () => {
it('Should be able to submit a time (GET)', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=test", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcQ"]);
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=test")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcQ"]);
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a time (POST)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=test", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcE"]);
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=test", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcE"]);
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for missing params', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test", null,
(err, res) => {
if (err) done(err);
if (res.statusCode === 400) done();
else done("Status code was: " + res.statusCode);
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test")
.then(res => {
if (res.status === 400) done();
else done("Status code was: " + res.status);
})
.catch(err => done(err));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {config} from '../../src/config';
import {getHash} from '../../src/utils/getHash';
import {Done, getbaseURL} from '../utils';
@ -37,54 +37,67 @@ describe('postSkipSegments', () => {
});
it('Should be able to submit a single time (Params method)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
if (row.startTime === 2 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(res => {
if (res.status === 200) {
const row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
if (row.startTime === 2 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a single time (JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]);
if (row.startTime === 0 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 200) {
const row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]);
if (row.startTime === 0 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit multiple times (JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
@ -94,35 +107,38 @@ describe('postSkipSegments', () => {
segment: [30, 60],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
let success = true;
if (rows.length === 2) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 10 || row.category !== "sponsor") &&
(row.startTime !== 30 || row.endTime !== 60 || row.category !== "intro")) {
success = false;
break;
}
}),
})
.then(res => {
if (res.status === 200) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
let success = true;
if (rows.length === 2) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 10 || row.category !== "sponsor") &&
(row.startTime !== 30 || row.endTime !== 60 || row.category !== "intro")) {
success = false;
break;
}
}
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should allow multiple times if total is under 80% of video(JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "L_jWHffIx5E",
segments: [{
@ -138,37 +154,40 @@ describe('postSkipSegments', () => {
segment: [99, 170],
category: "sponsor",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 3000 || row.category !== "sponsor") &&
(row.startTime !== 3002 || row.endTime !== 3050 || row.category !== "intro") &&
(row.startTime !== 45 || row.endTime !== 100 || row.category !== "interaction") &&
(row.startTime !== 99 || row.endTime !== 170 || row.category !== "sponsor")) {
success = false;
break;
}
}),
})
.then(res => {
if (res.status === 200) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 3000 || row.category !== "sponsor") &&
(row.startTime !== 3002 || row.endTime !== 3050 || row.category !== "intro") &&
(row.startTime !== 45 || row.endTime !== 100 || row.category !== "interaction") &&
(row.startTime !== 99 || row.endTime !== 170 || row.category !== "sponsor")) {
success = false;
break;
}
}
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video (JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "n9rIGdXnSJc",
segments: [{
@ -184,275 +203,334 @@ describe('postSkipSegments', () => {
segment: [4050, 4750],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime === 0 || row.endTime === 2000 || row.category === "interaction") ||
(row.startTime === 3000 || row.endTime === 4000 || row.category === "sponsor") ||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "intro")) {
success = false;
break;
}
}
}
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "80percent_video",
segments: [{
segment: [2000, 4000],
category: "sponsor",
}, {
segment: [1500, 2750],
category: "sponsor",
}, {
segment: [4050, 4750],
category: "sponsor",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]);
let success = rows.length == 2;
}),
})
.then(res => {
if (res.status === 400) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime === 2000 || row.endTime === 4000 || row.category === "sponsor") ||
if ((row.startTime === 0 || row.endTime === 2000 || row.category === "interaction") ||
(row.startTime === 3000 || row.endTime === 4000 || row.category === "sponsor") ||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "sponsor")) {
(row.startTime === 4050 || row.endTime === 4750 || row.category === "intro")) {
success = false;
break;
}
}
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "80percent_video",
segments: [{
segment: [2000, 4000],
category: "sponsor",
}, {
segment: [1500, 2750],
category: "sponsor",
}, {
segment: [4050, 4750],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 400) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]);
let success = rows.length == 2;
for (const row of rows) {
if ((row.startTime === 2000 || row.endTime === 4000 || row.category === "sponsor") ||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "sponsor")) {
success = false;
break;
}
}
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should be accepted if a non-sponsor is less than 1 second', (done: Done) => {
request.post(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", {
method: 'POST',
})
.then(async res => {
if (res.status === 200) done(); // pass
else {
const body = await res.text();
done("non 200 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if a sponsor is less than 1 second', (done: Done) => {
request.post(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 400) done(); // pass
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", {
method: 'POST',
})
.then(async res => {
if (res.status === 400) done(); // pass
else {
const body = await res.text();
done("non 403 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if over 80% of the video', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 403) done(); // pass
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing")
.then(async res => {
if (res.status === 403) done(); // pass
else {
const body = await res.text();
done("non 403 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it("Should be rejected if NB's predicted probability is <70%.", (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing")
.then(async res => {
if (res.status === 200) done(); // pass
else {
const body = await res.text();
done("non 200 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if user has to many active warnings', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "warn-user01",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done(); // success
} else {
done("Status code was " + res.statusCode);
}
});
body: JSON.stringify({
userID: "warn-user01",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 403) {
done(); // success
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be accepted if user has some active warnings', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "warn-user02",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [50, 60],
category: "sponsor",
}],
},
},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
done(); // success
} else {
done("Status code was " + res.statusCode + " " + body);
}
});
}),
})
.then(async res => {
if (res.status === 200) {
done(); // success
} else {
const body = await res.text();
done("Status code was " + res.status + " " + body);
}
})
.catch(err => done(err));
});
it('Should be allowed if youtube thinks duration is 0', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", {
method: 'POST',
})
.then(async res => {
if (res.status === 200) done(); // pass
else {
const body = await res.text();
done("non 200 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if not a valid videoID', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 403) done(); // pass
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing")
.then(async res => {
if (res.status === 403) done(); // pass
else {
const body = await res.text();
done("non 403 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 400 for missing params (Params method)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", null,
(err, res) => {
if (err) done(true);
if (res.statusCode === 400) done();
else done(true);
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", {
method: 'POST',
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 1', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
segments: [{
segment: [9, 10],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
segments: [{
segment: [9, 10],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 2', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 3', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [0],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [0],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 4', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [9, 10],
}, {
segment: [31, 60],
category: "intro",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [9, 10],
}, {
segment: [31, 60],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 5', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@ -13,23 +13,29 @@ describe('postWarning', () => {
issuerUserID: 'warning-vip',
userID: 'warning-0',
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
done("Warning missing from database");
}
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Warning missing from database");
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be not be able to create a duplicate warning if vip', (done: Done) => {
@ -38,22 +44,29 @@ describe('postWarning', () => {
userID: 'warning-0',
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 409) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
done("Warning missing from database");
}
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 409) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Warning missing from database");
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to remove warning if vip', (done: Done) => {
@ -63,22 +76,29 @@ describe('postWarning', () => {
enabled: false
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 0) {
done();
} else {
done("Warning missing from database");
}
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 0) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Warning missing from database");
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to create warning if vip (exp 403)', (done: Done) => {
@ -87,16 +107,23 @@ describe('postWarning', () => {
userID: 'warning-1',
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 403) {
done();
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@ -70,30 +70,39 @@ describe('segmentShift', function () {
});
it('Reject none VIP user', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: 'segshift_randomuser001',
startTime: 20,
endTime: 30,
},
}, (err, res) => {
if (err) return done(err);
return done(res.statusCode === 403 ? undefined : res.statusCode);
});
}),
})
.then(res => {
done(res.status === 403 ? undefined : res.status);
})
.catch(err => done(err));
});
it('Shift is outside segments', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 20,
endTime: 30,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@ -117,20 +126,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is inside segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 65,
endTime: 75,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@ -154,20 +168,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is overlaping startTime of segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 32,
endTime: 42,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@ -191,20 +210,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is overlaping endTime of segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 85,
endTime: 95,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@ -228,20 +252,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is overlaping segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 35,
endTime: 55,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@ -266,8 +295,7 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import * as utils from '../utils';
import { getHash } from '../../src/utils/getHash';
@ -23,9 +23,14 @@ describe('unBan', () => {
});
it('Should be able to unban a user and re-enable shadow banned segments', (done) => {
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-0', 'testMan-unBan', 1]);
if (result.length !== 0) {
console.log(result);
@ -34,34 +39,48 @@ describe('unBan', () => {
done();
}
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.statusCode);
done("Status code was " + res.status);
}
});
})
.catch(err => done(err));
});
it('Should be able to unban a user and re-enable shadow banned segments without noSegment entrys', (done) => {
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
if (result.length !== 1) {
console.log(result);
done("Expected 1 banned entry1 in db, got " + result.length);
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
if (result.length !== 1) {
console.log(result);
done("Expected 1 banned entry1 in db, got " + result.length);
} else {
done();
}
} else {
done();
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
} else {
console.log(body);
done("Status code was " + res.statusCode);
}
});
})
.catch(err => done(err));
});
it('Should be able to unban a user and re-enable shadow banned segments with a mix of noSegment entrys', (done) => {
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE userID = ? AND shadowHidden = ?', ['testEntity-unBan', 1]);
if (result.length !== 1) {
console.log(result);
@ -70,9 +89,11 @@ describe('unBan', () => {
done();
}
} else {
console.log(body);
done("Status code was " + res.statusCode);
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
});
})
.catch(err => done(err));
});
});
});

View file

@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {config} from '../../src/config';
import {db, privateDB} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
@ -63,251 +63,249 @@ describe('voteOnSponsorTime', () => {
});
it('Should be able to upvote a segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
if (row.votes === 3) {
done();
} else {
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
if (row.votes === 3) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to downvote a segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes < 10) {
done();
} else {
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes < 10) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to downvote the same segment when voting from a different user on the same IP', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes === 9) {
done();
} else {
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes === 9) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it("Should not be able to downvote a segment if the user is shadow banned", (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
if (row.votes === 10) {
done();
} else {
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
if (row.votes === 10) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
if (row.votes === 2) {
done();
} else {
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
if (row.votes === 2) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
if (row.votes === 10) {
done();
} else {
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
if (row.votes === 10) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('VIP should be able to completely downvote a segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
if (row.votes <= -2) {
done();
} else {
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
if (row.votes <= -2) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('should be able to completely downvote your own segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
if (row.votes <= -2) {
done();
} else {
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
if (row.votes <= -2) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('should not be able to completely downvote somebody elses segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
if (row.votes === 499) {
done();
} else {
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
if (row.votes === 499) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to vote for a category and it should add your vote to the database', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
if (row.category === "sponsor" && categoryRows.length === 2
&& categoryRows[0]?.votes === 1 && categoryRows[0]?.category === "intro"
&& categoryRows[1]?.votes === 1 && categoryRows[1]?.category === "sponsor") {
done();
} else {
done("Submission changed to " + row.category + " instead of staying as sponsor. Vote was applied as " + categoryRows[0]?.category + " with " + categoryRows[0]?.votes + " votes and there were " + categoryRows.length + " rows.");
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
if (row.category === "sponsor" && categoryRows.length === 2
&& categoryRows[0]?.votes === 1 && categoryRows[0]?.category === "intro"
&& categoryRows[1]?.votes === 1 && categoryRows[1]?.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submission changed to " + row.category + " instead of staying as sponsor. Vote was applied as " + categoryRows[0]?.category + " with " + categoryRows[0]?.votes + " votes and there were " + categoryRows.length + " rows.");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not able to change to an invalid category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
if (row.category === "sponsor") {
done();
} else {
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory")
.then(res => {
if (res.status === 400) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
if (row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to change your vote for a category and it should add your vote to the database', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let submissionRow = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
let introVotes = 0;
let outroVotes = 0;
let sponsorVotes = 0;
for (const row of categoryRows) {
if (row?.category === "intro") introVotes += row?.votes;
if (row?.category === "outro") outroVotes += row?.votes;
if (row?.category === "sponsor") sponsorVotes += row?.votes;
}
if (submissionRow.category === "sponsor" && categoryRows.length === 3
&& introVotes === 0 && outroVotes === 1 && sponsorVotes === 1) {
done();
} else {
done("Submission changed to " + submissionRow.category + " instead of staying as sponsor. There were "
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
}
} else {
done("Status code was " + res.statusCode);
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro")
.then(res => {
if (res.status === 200) {
let submissionRow = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
let introVotes = 0;
let outroVotes = 0;
let sponsorVotes = 0;
for (const row of categoryRows) {
if (row?.category === "intro") introVotes += row?.votes;
if (row?.category === "outro") outroVotes += row?.votes;
if (row?.category === "sponsor") sponsorVotes += row?.votes;
}
});
if (submissionRow.category === "sponsor" && categoryRows.length === 3
&& introVotes === 0 && outroVotes === 1 && sponsorVotes === 1) {
done();
} else {
done("Submission changed to " + submissionRow.category + " instead of staying as sponsor. There were "
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
}
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to change your vote to an invalid category', (done: Done) => {
const vote = (inputCat: string, assertCat: string, callback: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat, null,
(err) => {
if (err) done(err);
else {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]);
if (row.category === assertCat) {
callback();
} else {
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat)
.then(res => {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]);
if (row.category === assertCat) {
callback();
} else {
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
})
.catch(err => done(err));
};
vote("sponsor", "sponsor", () => {
vote("fakeCategory", "sponsor", done);
@ -316,149 +314,148 @@ describe('voteOnSponsorTime', () => {
it('VIP should be able to vote for a category and it should immediately change', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
let row2 = db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]);
if (row.category === "outro" && row2.votes === 500) {
done();
} else {
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
let row2 = db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]);
if (row.category === "outro" && row2.votes === 500) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Submitter should be able to vote for a category and it should immediately change', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.category === "outro") {
done();
} else {
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.category === "outro") {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to category-vote on an invalid UUID submission', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 400.");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro")
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status + " instead of 400.");
}
})
.catch(err => done(err));
});
it('Non-VIP should not be able to upvote "dead" submission', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 403");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1")
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status + " instead of 403");
}
})
.catch(err => done(err));
});
it('VIP should be able to upvote "dead" submission', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.votes > -3) {
done();
} else {
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.votes > -3) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to upvote a segment (Too many warning)', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done(); // success
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1")
.then(res => {
if (res.status === 403) {
done(); // success
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Non-VIP should not be able to vote on a segment with no-segments category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 403");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1")
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status + " instead of 403");
}
})
.catch(err => done(err));
});
it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 403");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro")
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status + " instead of 403");
}
})
.catch(err => done(err));
});
it('VIP should able to vote on a segment with no-segments category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 200");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1")
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status + " instead of 200");
}
})
.catch(err => done(err));
});
it('Non-VIP should be able to vote on a segment on a no-segments video with a category that doesn\'t have no-segments', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 200");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1")
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status + " instead of 200");
}
})
.catch(err => done(err));
});
});