mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 05:27:00 +03:00
Fix test cases
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {getbaseURL, Done} from '../utils';
|
import {getbaseURL, Done} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
@@ -9,49 +9,47 @@ describe('getIsUserVIP', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get a 200', (done: Done) => {
|
it('Should be able to get a 200', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
|
||||||
+ "/api/isUserVIP?userID=supertestman", null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("non 200: " + res.status);
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
|
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Should get a 400 if no userID', (done: Done) => {
|
it('Should get a 400 if no userID', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/isUserVIP")
|
||||||
+ "/api/isUserVIP", null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 400) done("non 400: " + res.status);
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 400) done("non 400: " + res.statusCode);
|
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should say a VIP is a VIP', (done: Done) => {
|
it('Should say a VIP is a VIP', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
|
||||||
+ "/api/isUserVIP?userID=supertestman", null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) done("non 200: " + res.status);
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
if (JSON.parse(body).vip === true) done(); // pass
|
const data = await res.json();
|
||||||
|
if (data.vip === true) done(); // pass
|
||||||
else done("Result was non-vip when should have been vip");
|
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) => {
|
it('Should say a normal user is not a VIP', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/isUserVIP?userID=regulartestman")
|
||||||
+ "/api/isUserVIP?userID=regulartestman", null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) done("non 200: " + res.status);
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
if (JSON.parse(body).vip === false) done(); // pass
|
const data = await res.json();
|
||||||
|
if (data.vip === false) done(); // pass
|
||||||
else done("Result was vip when should have been non-vip");
|
else done("Result was vip when should have been non-vip");
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
@@ -10,12 +10,11 @@ describe('getSavedTimeForUser', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get a 200', (done: Done) => {
|
it('Should be able to get a 200', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/getSavedTimeForUser?userID=testman")
|
||||||
+ "/api/getSavedTimeForUser?userID=testman", null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("non 200");
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200");
|
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
@@ -21,56 +21,47 @@ describe('getSegmentsByHash', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get a 200', (done: Done) => {
|
it('Should be able to get a 200', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["sponsor", "intro"]')
|
||||||
+ '/api/skipSegments/3272f?categories=["sponsor", "intro"]', null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
else done(); // pass
|
||||||
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
|
})
|
||||||
else {
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
done();
|
|
||||||
} // pass
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 404 if no segments are found even if a video for the given hash is known', (done: Done) => {
|
it('Should return 404 if no segments are found even if a video for the given hash is known', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["shilling"]')
|
||||||
+ '/api/skipSegments/3272f?categories=["shilling"]', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 404) done("non 404 status code, was " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 404) done("non 404 status code, was " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
if (body === '[]') {
|
const body = await res.text();
|
||||||
done(); // pass
|
if (body === '[]') done(); // pass
|
||||||
} else {
|
else done("Response had videos");
|
||||||
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) => {
|
it('Should be able to get an empty array if no videos', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/11111?categories=["shilling"]')
|
||||||
+ '/api/skipSegments/11111?categories=["shilling"]', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 404) done("non 404 status code, was " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 404) done("non 404 status code, was " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
|
const body = await res.text();
|
||||||
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
|
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
|
||||||
else done("non empty array returned");
|
else done("non empty array returned");
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 prefix too short', (done: Done) => {
|
it('Should return 400 prefix too short', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/11?categories=["shilling"]')
|
||||||
+ '/api/skipSegments/11?categories=["shilling"]', null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 400) done("non 400 status code, was " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
else done(); // pass
|
||||||
else if (res.statusCode !== 400) done("non 400 status code, was " + res.statusCode);
|
})
|
||||||
else {
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
done(); // pass
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 prefix too long', (done: Done) => {
|
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);
|
done('failed to generate a long enough string for the test ' + prefix.length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
fetch(getbaseURL() + '/api/skipSegments/' + prefix + '?categories=["shilling"]')
|
||||||
request.get(getbaseURL()
|
.then(res => {
|
||||||
+ '/api/skipSegments/' + prefix + '?categories=["shilling"]', null,
|
if (res.status !== 400) done("non 400 status code, was " + res.status);
|
||||||
(err, res) => {
|
else done(); // pass
|
||||||
if (err) done("Couldn't call endpoint");
|
})
|
||||||
else if (res.statusCode !== 400) done("non 400 status code, was " + res.statusCode);
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
else {
|
|
||||||
done(); // pass
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not return 400 prefix in range', (done: Done) => {
|
it('Should not return 400 prefix in range', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/11111?categories=["shilling"]')
|
||||||
+ '/api/skipSegments/11111?categories=["shilling"]', null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status === 400) done("prefix length 5 gave 400 " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
else done(); // pass
|
||||||
else if (res.statusCode === 400) done("prefix length 5 gave 400 " + res.statusCode);
|
})
|
||||||
else {
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
done(); // pass
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 404 for no hash', (done: Done) => {
|
it('Should return 404 for no hash', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/?categories=["shilling"]')
|
||||||
+ '/api/skipSegments/?categories=["shilling"]', null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 404) done("expected 404, got " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
else done(); // pass
|
||||||
else if (res.statusCode !== 404) done("expected 404, got " + res.statusCode);
|
})
|
||||||
else {
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
done(); // pass
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 500 for bad format categories', (done: Done) => { // should probably be 400
|
it('Should return 500 for bad format categories', (done: Done) => { // should probably be 400
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/?categories=shilling')
|
||||||
+ '/api/skipSegments/?categories=shilling', null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 500) done("expected 500 got " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
else done(); // pass
|
||||||
else if (res.statusCode !== 500) done("expected 500 got " + res.statusCode);
|
})
|
||||||
else {
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
done(); // pass
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get multiple videos', (done: Done) => {
|
it('Should be able to get multiple videos', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/fdaf?categories=["sponsor","intro"]')
|
||||||
+ '/api/skipSegments/fdaf?categories=["sponsor","intro"]', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
body = JSON.parse(body);
|
const body = await res.json();
|
||||||
if (body.length !== 2) done("expected 2 video, got " + body.length);
|
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[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 if (body[1].segments.length !== 1) done("expected 1 segment for second video, got " + body[1].segments.length);
|
||||||
else done();
|
else done();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get 200 for no categories (default sponsor)', (done: Done) => {
|
it('Should be able to get 200 for no categories (default sponsor)', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/skipSegments/fdaf')
|
||||||
+ '/api/skipSegments/fdaf', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
body = JSON.parse(body);
|
const body = await res.json();
|
||||||
if (body.length !== 2) done("expected 2 videos, got " + body.length);
|
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[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[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 if (body[0].segments[0].category !== 'sponsor' || body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
|
||||||
else done();
|
else done();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to post a segment and get it using endpoint', (done: Done) => {
|
it('Should be able to post a segment and get it using endpoint', (done: Done) => {
|
||||||
let testID = 'abc123goodVideo';
|
let testID = 'abc123goodVideo';
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
|
||||||
+ "/api/postVideoSponsorTimes", {
|
method: 'POST',
|
||||||
json: {
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: testID,
|
videoID: testID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [13, 17],
|
segment: [13, 17],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(async res => {
|
||||||
if (err) done('(post) ' + err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
fetch(getbaseURL() + '/api/skipSegments/' + getHash(testID, 1).substring(0, 3))
|
||||||
request.get(getbaseURL()
|
.then(async res => {
|
||||||
+ '/api/skipSegments/' + getHash(testID, 1).substring(0, 3), null,
|
if (res.status !== 200) done("(get) non 200 status code, was " + res.status);
|
||||||
(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 {
|
else {
|
||||||
body = JSON.parse(body);
|
const body = await res.json();
|
||||||
if (body.length !== 1) done("(get) expected 1 video, got " + body.length);
|
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.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 if (body[0].segments[0].category !== 'sponsor') done("(get) segment should be sponsor, was " + body[0].segments[0].category);
|
||||||
else done();
|
else done();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("(get) Couldn't call endpoint"));
|
||||||
} else {
|
} else {
|
||||||
done("(post) non 200 status code, was " + res.statusCode);
|
done("(post) non 200 status code, was " + res.status);
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
);
|
.catch(err => done('(post) ' + err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
@@ -17,87 +17,81 @@ describe('getSkipSegments', () => {
|
|||||||
|
|
||||||
|
|
||||||
it('Should be able to get a time by category 1', (done: Done) => {
|
it('Should be able to get a time by category 1', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor")
|
||||||
+ "/api/skipSegments?videoID=testtesttest&category=sponsor", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const data = await res.json();
|
||||||
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
||||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
|
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
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) => {
|
it('Should be able to get a time by category 2', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=intro")
|
||||||
+ "/api/skipSegments?videoID=testtesttest&category=intro", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const data = await res.json();
|
||||||
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
|
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
|
||||||
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
|
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
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) => {
|
it('Should be able to get a time by categories array', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]")
|
||||||
+ "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const data = await res.json();
|
||||||
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
||||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
|
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
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) => {
|
it('Should be able to get a time by categories array 2', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]")
|
||||||
+ "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const data = await res.json();
|
||||||
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
|
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
|
||||||
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
|
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
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) => {
|
it('Should be able to get multiple times by category', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=multiple&categories=[\"intro\"]")
|
||||||
+ "/api/skipSegments?videoID=multiple&categories=[\"intro\"]", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const body = await res.text();
|
||||||
|
const data = JSON.parse(body);
|
||||||
if (data.length === 2) {
|
if (data.length === 2) {
|
||||||
|
|
||||||
let success = true;
|
let success = true;
|
||||||
for (const segment of data) {
|
for (const segment of data) {
|
||||||
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|
||||||
@@ -110,22 +104,22 @@ describe('getSkipSegments', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (success) done();
|
if (success) done();
|
||||||
else done("Received incorrect body: " + res.body);
|
else done("Received incorrect body: " + body);
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
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) => {
|
it('Should be able to get multiple times by multiple categories', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]")
|
||||||
+ "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const body = await res.text();
|
||||||
|
const data = JSON.parse(body);
|
||||||
if (data.length === 2) {
|
if (data.length === 2) {
|
||||||
|
|
||||||
let success = true;
|
let success = true;
|
||||||
@@ -140,77 +134,77 @@ describe('getSkipSegments', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (success) done();
|
if (success) done();
|
||||||
else done("Received incorrect body: " + res.body);
|
else done("Received incorrect body: " + body);
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
done("Received incorrect body: " + body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be possible to send unexpected query parameters', (done: Done) => {
|
it('Should be possible to send unexpected query parameters', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor")
|
||||||
+ "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const body = await res.text();
|
||||||
|
const data = JSON.parse(body);
|
||||||
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
||||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
|
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
done("Received incorrect body: " + body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Low voted submissions should be hidden', (done: Done) => {
|
it('Low voted submissions should be hidden', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=test3&category=sponsor")
|
||||||
+ "/api/skipSegments?videoID=test3&category=sponsor", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const body = await res.text();
|
||||||
|
const data = JSON.parse(body);
|
||||||
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
||||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-4") {
|
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-4") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
done("Received incorrect body: " + body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 404 if no segment found', (done: Done) => {
|
it('Should return 404 if no segment found', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=notarealvideo")
|
||||||
+ "/api/skipSegments?videoID=notarealvideo", null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 404) done("non 404 respone code: " + res.statusCode);
|
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Should be able send a comma in a query param', (done: Done) => {
|
it('Should be able send a comma in a query param', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest,test&category=sponsor")
|
||||||
+ "/api/skipSegments?videoID=testtesttest,test&category=sponsor", null,
|
.then(async res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
|
|
||||||
else {
|
else {
|
||||||
let data = JSON.parse(res.body);
|
const body = await res.text();
|
||||||
|
const data = JSON.parse(body);
|
||||||
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
||||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-1") {
|
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-1") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Received incorrect body: " + res.body);
|
done("Received incorrect body: " + body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
@@ -24,48 +24,30 @@ describe('getUserInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get a 200', (done: Done) => {
|
it('Should be able to get a 200', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01')
|
||||||
+ '/api/getUserInfo?userID=getuserinfo_user_01', null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done('non 200 (' + res.status + ')');
|
||||||
if (err) {
|
else done(); // pass
|
||||||
done('couldn\'t call endpoint');
|
})
|
||||||
} else {
|
.catch(err => done('couldn\'t call endpoint'));
|
||||||
if (res.statusCode !== 200) {
|
|
||||||
done('non 200 (' + res.statusCode + ')');
|
|
||||||
} else {
|
|
||||||
done(); // pass
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get a 400 (No userID parameter)', (done: Done) => {
|
it('Should be able to get a 400 (No userID parameter)', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/getUserInfo')
|
||||||
+ '/api/getUserInfo', null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||||
if (err) {
|
else done(); // pass
|
||||||
done('couldn\'t call endpoint');
|
})
|
||||||
} else {
|
.catch(err => done('couldn\'t call endpoint'));
|
||||||
if (res.statusCode !== 400) {
|
|
||||||
done('non 400');
|
|
||||||
} else {
|
|
||||||
done(); // pass
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return info', (done: Done) => {
|
it('Should return info', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01')
|
||||||
+ '/api/getUserInfo?userID=getuserinfo_user_01', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) {
|
||||||
if (err) {
|
|
||||||
done("couldn't call endpoint");
|
|
||||||
} else {
|
|
||||||
if (res.statusCode !== 200) {
|
|
||||||
done("non 200");
|
done("non 200");
|
||||||
} else {
|
} else {
|
||||||
const data = JSON.parse(body);
|
const data = await res.json();
|
||||||
if (data.userName !== 'Username user 01') {
|
if (data.userName !== 'Username user 01') {
|
||||||
done('Returned incorrect userName "' + data.userName + '"');
|
done('Returned incorrect userName "' + data.userName + '"');
|
||||||
} else if (data.minutesSaved !== 5) {
|
} else if (data.minutesSaved !== 5) {
|
||||||
@@ -78,90 +60,65 @@ describe('getUserInfo', () => {
|
|||||||
done(); // pass
|
done(); // pass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
});
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should get warning data', (done: Done) => {
|
it('Should get warning data', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_0')
|
||||||
+ '/api/getUserInfo?userID=getuserinfo_warning_0', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) {
|
||||||
if (err) {
|
done('non 200 (' + res.status + ')');
|
||||||
done("couldn't call endpoint");
|
|
||||||
} else {
|
} else {
|
||||||
if (res.statusCode !== 200) {
|
const data = await res.json();;
|
||||||
done("non 200");
|
if (data.warnings !== 1) done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
|
||||||
} else {
|
else done(); // pass
|
||||||
const data = JSON.parse(body);
|
|
||||||
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) => {
|
it('Should get multiple warnings', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_1')
|
||||||
+ '/api/getUserInfo?userID=getuserinfo_warning_1', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) {
|
||||||
if (err) {
|
done('non 200 (' + res.status + ')');
|
||||||
done("couldn't call endpoint");
|
|
||||||
} else {
|
} else {
|
||||||
if (res.statusCode !== 200) {
|
const data = await res.json();
|
||||||
done("non 200");
|
if (data.warnings !== 2) done('wrong number of warnings: ' + data.warnings + ', not ' + 2);
|
||||||
} else {
|
else done(); // pass
|
||||||
const data = JSON.parse(body);
|
|
||||||
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) => {
|
it('Should not get warnings if noe', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_2')
|
||||||
+ '/api/getUserInfo?userID=getuserinfo_warning_2', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) {
|
||||||
if (err) {
|
done('non 200 (' + res.status + ')');
|
||||||
done("couldn't call endpoint");
|
|
||||||
} else {
|
} else {
|
||||||
if (res.statusCode !== 200) {
|
const data = await res.json();
|
||||||
done("non 200");
|
if (data.warnings !== 0) done('wrong number of warnings: ' + data.warnings + ', not ' + 0);
|
||||||
} else {
|
else done(); // pass
|
||||||
const data = JSON.parse(body);
|
|
||||||
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) => {
|
it('Should return userID for userName (No userName set)', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_02')
|
||||||
+ '/api/getUserInfo?userID=getuserinfo_user_02', null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) {
|
||||||
if (err) {
|
done('non 200 (' + res.status + ')');
|
||||||
done('couldn\'t call endpoint');
|
|
||||||
} else {
|
} else {
|
||||||
if (res.statusCode !== 200) {
|
const data = await res.json();
|
||||||
done('non 200');
|
|
||||||
} else {
|
|
||||||
const data = JSON.parse(body);
|
|
||||||
if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') {
|
if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') {
|
||||||
return done('Did not return userID for userName');
|
return done('Did not return userID for userName');
|
||||||
}
|
}
|
||||||
done(); // pass
|
done(); // pass
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
});
|
.catch(err => done('couldn\'t call endpoint'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
@@ -48,21 +48,28 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res, body) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
if (JSON.stringify(body) === JSON.stringify(expected)) {
|
body: JSON.stringify(json)
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status === 200) {
|
||||||
|
const data = await res.json();
|
||||||
|
if (JSON.stringify(data) === JSON.stringify(expected)) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(body));
|
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit categories not in video (sql check)', (done: Done) => {
|
it('Should be able to submit categories not in video (sql check)', (done: Done) => {
|
||||||
@@ -79,11 +86,15 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res, body) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
|
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']);
|
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['no-segments-video-id-1']);
|
||||||
if (result.length !== 4) {
|
if (result.length !== 4) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@@ -92,10 +103,12 @@ describe('noSegmentRecords', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit categories with _ in the category', (done: Done) => {
|
it('Should be able to submit categories with _ in the category', (done: Done) => {
|
||||||
@@ -107,11 +120,15 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res, body) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status === 200) {
|
||||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['underscore']);
|
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['underscore']);
|
||||||
if (result.length !== 1) {
|
if (result.length !== 1) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@@ -120,10 +137,12 @@ describe('noSegmentRecords', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should be able to submit categories with upper and lower case in the category', (done: Done) => {
|
||||||
@@ -135,11 +154,15 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res, body) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status === 200) {
|
||||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['bothCases']);
|
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['bothCases']);
|
||||||
if (result.length !== 1) {
|
if (result.length !== 1) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@@ -148,10 +171,12 @@ describe('noSegmentRecords', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not be able to submit categories with $ in the category', (done: Done) => {
|
it('Should not be able to submit categories with $ in the category', (done: Done) => {
|
||||||
@@ -163,11 +188,15 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res, body) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status === 200) {
|
||||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['specialChar']);
|
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['specialChar']);
|
||||||
if (result.length !== 0) {
|
if (result.length !== 0) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@@ -176,23 +205,30 @@ describe('noSegmentRecords', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for missing params', (done: Done) => {
|
it('Should return 400 for missing params', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json: {}},
|
method: 'POST',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 400) {
|
},
|
||||||
|
body: JSON.stringify({}),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 400) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for no categories', (done: Done) => {
|
it('Should return 400 for no categories', (done: Done) => {
|
||||||
@@ -202,16 +238,21 @@ describe('noSegmentRecords', () => {
|
|||||||
categories: [],
|
categories: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 400) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 400) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for no userID', (done: Done) => {
|
it('Should return 400 for no userID', (done: Done) => {
|
||||||
@@ -221,16 +262,21 @@ describe('noSegmentRecords', () => {
|
|||||||
categories: ['sponsor'],
|
categories: ['sponsor'],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 400) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 400) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for no videoID', (done: Done) => {
|
it('Should return 400 for no videoID', (done: Done) => {
|
||||||
@@ -240,16 +286,21 @@ describe('noSegmentRecords', () => {
|
|||||||
categories: ['sponsor'],
|
categories: ['sponsor'],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 400) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 400) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 object categories)', (done: Done) => {
|
it('Should return 400 object categories)', (done: Done) => {
|
||||||
@@ -259,16 +310,21 @@ describe('noSegmentRecords', () => {
|
|||||||
categories: {},
|
categories: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 400) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 400) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 bad format categories', (done: Done) => {
|
it('Should return 400 bad format categories', (done: Done) => {
|
||||||
@@ -278,16 +334,21 @@ describe('noSegmentRecords', () => {
|
|||||||
categories: 'sponsor',
|
categories: 'sponsor',
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 400) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 400) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 403 if user is not VIP', (done: Done) => {
|
it('Should return 403 if user is not VIP', (done: Done) => {
|
||||||
@@ -299,16 +360,21 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'POST',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 403) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 403) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to delete a noSegment record', (done: Done) => {
|
it('Should be able to delete a noSegment record', (done: Done) => {
|
||||||
@@ -320,11 +386,15 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.delete(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'DELETE',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 200) {
|
||||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record']);
|
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record']);
|
||||||
if (result.length === 0) {
|
if (result.length === 0) {
|
||||||
done();
|
done();
|
||||||
@@ -332,9 +402,10 @@ describe('noSegmentRecords', () => {
|
|||||||
done("Didn't delete record");
|
done("Didn't delete record");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to delete one noSegment record without removing another', (done: Done) => {
|
it('Should be able to delete one noSegment record without removing another', (done: Done) => {
|
||||||
@@ -346,11 +417,15 @@ describe('noSegmentRecords', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
request.delete(getbaseURL()
|
fetch(getbaseURL() + "/api/noSegments", {
|
||||||
+ "/api/noSegments", {json},
|
method: 'DELETE',
|
||||||
(err, res) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 200) {
|
||||||
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record-1']);
|
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record-1']);
|
||||||
if (result.length === 1) {
|
if (result.length === 1) {
|
||||||
done();
|
done();
|
||||||
@@ -358,9 +433,10 @@ describe('noSegmentRecords', () => {
|
|||||||
done("Didn't delete record");
|
done("Didn't delete record");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should not be able to submit a segment to a video with a no-segment record (single submission)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
|
||||||
+ "/api/postVideoSponsorTimes", {
|
method: 'POST',
|
||||||
json: {
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "testman42",
|
userID: "testman42",
|
||||||
videoID: "noSubmitVideo",
|
videoID: "noSubmitVideo",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [20, 40],
|
segment: [20, 40],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 403) {
|
||||||
else if (res.statusCode === 403) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
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()
|
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
|
||||||
+ "/api/postVideoSponsorTimes", {
|
method: 'POST',
|
||||||
json: {
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "testman42",
|
userID: "testman42",
|
||||||
videoID: "noSubmitVideo",
|
videoID: "noSubmitVideo",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -404,60 +486,66 @@ describe('noSegmentRecords', () => {
|
|||||||
segment: [50, 60],
|
segment: [50, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
},),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 403) {
|
||||||
else if (res.statusCode === 403) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should be able to submit a segment to a video with a different no-segment record', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
|
||||||
+ "/api/postVideoSponsorTimes", {
|
method: 'POST',
|
||||||
json: {
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "testman42",
|
userID: "testman42",
|
||||||
videoID: "noSubmitVideo",
|
videoID: "noSubmitVideo",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [20, 40],
|
segment: [20, 40],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should be able to submit a segment to a video with no no-segment records', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
|
||||||
+ "/api/postVideoSponsorTimes", {
|
method: 'POST',
|
||||||
json: {
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "testman42",
|
userID: "testman42",
|
||||||
videoID: "normalVideo",
|
videoID: "normalVideo",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [20, 40],
|
segment: [20, 40],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
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) => {
|
it('Should be able to get a time', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
|
||||||
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest", null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("non 200 (" + res.status + ")");
|
||||||
if (err) done("Couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200");
|
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
});
|
})
|
||||||
|
.catch(err => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 404 if no segment found', (done: Done) => {
|
it('Should return 404 if no segment found', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=notarealvideo")
|
||||||
+ "/api/getVideoSponsorTimes?videoID=notarealvideo", null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 404) done("non 404 respone code: " + res.statusCode);
|
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Should be possible to send unexpected query parameters', (done: Done) => {
|
it('Should be possible to send unexpected query parameters', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello")
|
||||||
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello", null,
|
.then(res => {
|
||||||
(err, res) => {
|
if (res.status !== 200) done("non 200");
|
||||||
if (err) done("couldn't callendpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200");
|
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't callendpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able send a comma in a query param', (done: Done) => {
|
it('Should be able send a comma in a query param', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest,test")
|
||||||
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest,test", null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
const body = await res.text();
|
||||||
if (err) done("couln't call endpoint");
|
if (res.status !== 200) done("non 200 response: " + res.status);
|
||||||
else if (res.statusCode !== 200) done("non 200 response: " + res.statusCode);
|
|
||||||
else if (JSON.parse(body).UUIDs[0] === 'uuid-1') done(); // pass
|
else if (JSON.parse(body).UUIDs[0] === 'uuid-1') done(); // pass
|
||||||
else done("couldn't parse response");
|
else done("couldn't parse response");
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couln't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get the correct time', (done: Done) => {
|
it('Should be able to get the correct time', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
|
||||||
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest", null,
|
.then(async res => {
|
||||||
(err, res, body) => {
|
if (res.status !== 200) done("non 200");
|
||||||
if (err) done("couldn't call endpoint");
|
|
||||||
else if (res.statusCode !== 200) done("non 200");
|
|
||||||
else {
|
else {
|
||||||
let parsedBody = JSON.parse(body);
|
const parsedBody = await res.json();
|
||||||
if (parsedBody.sponsorTimes[0][0] === 1
|
if (parsedBody.sponsorTimes[0][0] === 1
|
||||||
&& parsedBody.sponsorTimes[0][1] === 11
|
&& parsedBody.sponsorTimes[0][1] === 11
|
||||||
&& parsedBody.UUIDs[0] === 'uuid-0') {
|
&& parsedBody.UUIDs[0] === 'uuid-0') {
|
||||||
done(); // pass
|
done(); // pass
|
||||||
} else {
|
} else {
|
||||||
done("Wrong data was returned + " + parsedBody);
|
done("Wrong data was returned + " + JSON.stringify(parsedBody));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
})
|
||||||
|
.catch(err => done("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
|
|
||||||
|
|
||||||
describe('postVideoSponsorTime (Old submission method)', () => {
|
describe('postVideoSponsorTime (Old submission method)', () => {
|
||||||
it('Should be able to submit a time (GET)', (done: Done) => {
|
it('Should be able to submit a time (GET)', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=test", null,
|
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=test")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcQ"]);
|
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcQ"]);
|
||||||
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
|
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
|
||||||
done();
|
done();
|
||||||
@@ -17,17 +16,22 @@ describe('postVideoSponsorTime (Old submission method)', () => {
|
|||||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit a time (POST)', (done: Done) => {
|
it('Should be able to submit a time (POST)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=test", null,
|
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=test", {
|
||||||
(err, res) => {
|
method: 'POST',
|
||||||
if (err) done(err);
|
headers: {
|
||||||
else if (res.statusCode === 200) {
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 200) {
|
||||||
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcE"]);
|
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcE"]);
|
||||||
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
|
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
|
||||||
done();
|
done();
|
||||||
@@ -35,18 +39,19 @@ describe('postVideoSponsorTime (Old submission method)', () => {
|
|||||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for missing params', (done: Done) => {
|
it('Should return 400 for missing params', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test", null,
|
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 400) done();
|
||||||
if (res.statusCode === 400) done();
|
else done("Status code was: " + res.status);
|
||||||
else done("Status code was: " + res.statusCode);
|
})
|
||||||
});
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {config} from '../../src/config';
|
import {config} from '../../src/config';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
@@ -37,54 +37,67 @@ describe('postSkipSegments', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit a single time (Params method)', (done: Done) => {
|
it('Should be able to submit a single time (Params method)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", null,
|
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", {
|
||||||
(err, res) => {
|
method: 'POST',
|
||||||
if (err) done(err);
|
headers: {
|
||||||
else if (res.statusCode === 200) {
|
'Content-Type': 'application/json',
|
||||||
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
|
},
|
||||||
|
})
|
||||||
|
.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") {
|
if (row.startTime === 2 && row.endTime === 10 && row.category === "sponsor") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit a single time (JSON method)', (done: Done) => {
|
it('Should be able to submit a single time (JSON method)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "dQw4w9WgXcF",
|
videoID: "dQw4w9WgXcF",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
const row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]);
|
||||||
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]);
|
|
||||||
if (row.startTime === 0 && row.endTime === 10 && row.category === "sponsor") {
|
if (row.startTime === 0 && row.endTime === 10 && row.category === "sponsor") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit multiple times (JSON method)', (done: Done) => {
|
it('Should be able to submit multiple times (JSON method)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "dQw4w9WgXcQ",
|
videoID: "dQw4w9WgXcQ",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -94,12 +107,11 @@ describe('postSkipSegments', () => {
|
|||||||
segment: [30, 60],
|
segment: [30, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
|
||||||
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
|
|
||||||
let success = true;
|
let success = true;
|
||||||
if (rows.length === 2) {
|
if (rows.length === 2) {
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
@@ -110,19 +122,23 @@ describe('postSkipSegments', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) done();
|
if (success) done();
|
||||||
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
}).timeout(5000);
|
}).timeout(5000);
|
||||||
|
|
||||||
it('Should allow multiple times if total is under 80% of video(JSON method)', (done: Done) => {
|
it('Should allow multiple times if total is under 80% of video(JSON method)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "L_jWHffIx5E",
|
videoID: "L_jWHffIx5E",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -138,12 +154,11 @@ describe('postSkipSegments', () => {
|
|||||||
segment: [99, 170],
|
segment: [99, 170],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]);
|
||||||
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]);
|
|
||||||
let success = true;
|
let success = true;
|
||||||
if (rows.length === 4) {
|
if (rows.length === 4) {
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
@@ -156,19 +171,23 @@ describe('postSkipSegments', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) done();
|
if (success) done();
|
||||||
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
}).timeout(5000);
|
}).timeout(5000);
|
||||||
|
|
||||||
it('Should reject multiple times if total is over 80% of video (JSON method)', (done: Done) => {
|
it('Should reject multiple times if total is over 80% of video (JSON method)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "n9rIGdXnSJc",
|
videoID: "n9rIGdXnSJc",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -184,12 +203,11 @@ describe('postSkipSegments', () => {
|
|||||||
segment: [4050, 4750],
|
segment: [4050, 4750],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 400) {
|
||||||
else if (res.statusCode === 400) {
|
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]);
|
||||||
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]);
|
|
||||||
let success = true;
|
let success = true;
|
||||||
if (rows.length === 4) {
|
if (rows.length === 4) {
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
@@ -207,15 +225,20 @@ describe('postSkipSegments', () => {
|
|||||||
else
|
else
|
||||||
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
}).timeout(5000);
|
}).timeout(5000);
|
||||||
|
|
||||||
it('Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)', (done: Done) => {
|
it('Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "80percent_video",
|
videoID: "80percent_video",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -228,12 +251,11 @@ describe('postSkipSegments', () => {
|
|||||||
segment: [4050, 4750],
|
segment: [4050, 4750],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 400) {
|
||||||
else if (res.statusCode === 400) {
|
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]);
|
||||||
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]);
|
|
||||||
let success = rows.length == 2;
|
let success = rows.length == 2;
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
if ((row.startTime === 2000 || row.endTime === 4000 || row.category === "sponsor") ||
|
if ((row.startTime === 2000 || row.endTime === 4000 || row.category === "sponsor") ||
|
||||||
@@ -247,129 +269,169 @@ describe('postSkipSegments', () => {
|
|||||||
else
|
else
|
||||||
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
}).timeout(5000);
|
}).timeout(5000);
|
||||||
|
|
||||||
it('Should be accepted if a non-sponsor is less than 1 second', (done: Done) => {
|
it('Should be accepted if a non-sponsor is less than 1 second', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", null,
|
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", {
|
||||||
(err, res, body) => {
|
method: 'POST',
|
||||||
if (err) done("Couldn't call endpoint");
|
})
|
||||||
else if (res.statusCode === 200) done(); // pass
|
.then(async res => {
|
||||||
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
|
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) => {
|
it('Should be rejected if a sponsor is less than 1 second', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", null,
|
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", {
|
||||||
(err, res, body) => {
|
method: 'POST',
|
||||||
if (err) done("Couldn't call endpoint");
|
})
|
||||||
else if (res.statusCode === 400) done(); // pass
|
.then(async res => {
|
||||||
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
|
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) => {
|
it('Should be rejected if over 80% of the video', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing", null,
|
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing")
|
||||||
(err, res, body) => {
|
.then(async res => {
|
||||||
if (err) done("Couldn't call endpoint");
|
if (res.status === 403) done(); // pass
|
||||||
else if (res.statusCode === 403) done(); // pass
|
else {
|
||||||
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
|
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) => {
|
it("Should be rejected if NB's predicted probability is <70%.", (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing", null,
|
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing")
|
||||||
(err, res, body) => {
|
.then(async res => {
|
||||||
if (err) done("Couldn't call endpoint");
|
if (res.status === 200) done(); // pass
|
||||||
else if (res.statusCode === 200) done(); // pass
|
else {
|
||||||
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
|
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) => {
|
it('Should be rejected if user has to many active warnings', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "warn-user01",
|
userID: "warn-user01",
|
||||||
videoID: "dQw4w9WgXcF",
|
videoID: "dQw4w9WgXcF",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 403) {
|
||||||
else if (res.statusCode === 403) {
|
|
||||||
done(); // success
|
done(); // success
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be accepted if user has some active warnings', (done: Done) => {
|
it('Should be accepted if user has some active warnings', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "warn-user02",
|
userID: "warn-user02",
|
||||||
videoID: "dQw4w9WgXcF",
|
videoID: "dQw4w9WgXcF",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [50, 60],
|
segment: [50, 60],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res, body) => {
|
.then(async res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
done(); // success
|
done(); // success
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode + " " + body);
|
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) => {
|
it('Should be allowed if youtube thinks duration is 0', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", null,
|
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", {
|
||||||
(err, res, body) => {
|
method: 'POST',
|
||||||
if (err) done("Couldn't call endpoint");
|
})
|
||||||
else if (res.statusCode === 200) done(); // pass
|
.then(async res => {
|
||||||
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
|
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) => {
|
it('Should be rejected if not a valid videoID', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing", null,
|
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing")
|
||||||
(err, res, body) => {
|
.then(async res => {
|
||||||
if (err) done("Couldn't call endpoint");
|
if (res.status === 403) done(); // pass
|
||||||
else if (res.statusCode === 403) done(); // pass
|
else {
|
||||||
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
|
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) => {
|
it('Should return 400 for missing params (Params method)', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", null,
|
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", {
|
||||||
(err, res) => {
|
method: 'POST',
|
||||||
if (err) done(true);
|
})
|
||||||
if (res.statusCode === 400) done();
|
.then(res => {
|
||||||
|
if (res.status === 400) done();
|
||||||
else done(true);
|
else done(true);
|
||||||
});
|
})
|
||||||
|
.catch(err => done(true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for missing params (JSON method) 1', (done: Done) => {
|
it('Should return 400 for missing params (JSON method) 1', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [9, 10],
|
segment: [9, 10],
|
||||||
@@ -378,32 +440,40 @@ describe('postSkipSegments', () => {
|
|||||||
segment: [31, 60],
|
segment: [31, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(true);
|
if (res.status === 400) done();
|
||||||
else if (res.statusCode === 400) done();
|
|
||||||
else done(true);
|
else done(true);
|
||||||
});
|
})
|
||||||
|
.catch(err => done(true));
|
||||||
});
|
});
|
||||||
it('Should return 400 for missing params (JSON method) 2', (done: Done) => {
|
it('Should return 400 for missing params (JSON method) 2', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "dQw4w9WgXcQ",
|
videoID: "dQw4w9WgXcQ",
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(true);
|
if (res.status === 400) done();
|
||||||
else if (res.statusCode === 400) done();
|
|
||||||
else done(true);
|
else done(true);
|
||||||
});
|
})
|
||||||
|
.catch(err => done(true));
|
||||||
});
|
});
|
||||||
it('Should return 400 for missing params (JSON method) 3', (done: Done) => {
|
it('Should return 400 for missing params (JSON method) 3', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "dQw4w9WgXcQ",
|
videoID: "dQw4w9WgXcQ",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -413,18 +483,22 @@ describe('postSkipSegments', () => {
|
|||||||
segment: [31, 60],
|
segment: [31, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(true);
|
if (res.status === 400) done();
|
||||||
else if (res.statusCode === 400) done();
|
|
||||||
else done(true);
|
else done(true);
|
||||||
});
|
})
|
||||||
|
.catch(err => done(true));
|
||||||
});
|
});
|
||||||
it('Should return 400 for missing params (JSON method) 4', (done: Done) => {
|
it('Should return 400 for missing params (JSON method) 4', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "dQw4w9WgXcQ",
|
videoID: "dQw4w9WgXcQ",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -433,26 +507,30 @@ describe('postSkipSegments', () => {
|
|||||||
segment: [31, 60],
|
segment: [31, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(true);
|
if (res.status === 400) done();
|
||||||
else if (res.statusCode === 400) done();
|
|
||||||
else done(true);
|
else done(true);
|
||||||
});
|
})
|
||||||
|
.catch(err => done(true));
|
||||||
});
|
});
|
||||||
it('Should return 400 for missing params (JSON method) 5', (done: Done) => {
|
it('Should return 400 for missing params (JSON method) 5', (done: Done) => {
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
userID: "test",
|
userID: "test",
|
||||||
videoID: "dQw4w9WgXcQ",
|
videoID: "dQw4w9WgXcQ",
|
||||||
},
|
}),
|
||||||
},
|
})
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(true);
|
if (res.status === 400) done();
|
||||||
else if (res.statusCode === 400) done();
|
|
||||||
else done(true);
|
else done(true);
|
||||||
});
|
})
|
||||||
|
.catch(err => done(true));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
@@ -13,12 +13,16 @@ describe('postWarning', () => {
|
|||||||
issuerUserID: 'warning-vip',
|
issuerUserID: 'warning-vip',
|
||||||
userID: 'warning-0',
|
userID: 'warning-0',
|
||||||
};
|
};
|
||||||
|
fetch(getbaseURL()
|
||||||
request.post(getbaseURL()
|
+ "/api/warnUser", {
|
||||||
+ "/api/warnUser", {json},
|
method: 'POST',
|
||||||
(err, res, body) => {
|
headers: {
|
||||||
if (err) done(err);
|
'Content-Type': 'application/json',
|
||||||
else if (res.statusCode === 200) {
|
},
|
||||||
|
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]);
|
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)) {
|
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
|
||||||
done();
|
done();
|
||||||
@@ -26,10 +30,12 @@ describe('postWarning', () => {
|
|||||||
done("Warning missing from database");
|
done("Warning missing from database");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should be not be able to create a duplicate warning if vip', (done: Done) => {
|
||||||
@@ -38,11 +44,16 @@ describe('postWarning', () => {
|
|||||||
userID: 'warning-0',
|
userID: 'warning-0',
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/warnUser", {json},
|
+ "/api/warnUser", {
|
||||||
(err, res, body) => {
|
method: 'POST',
|
||||||
if (err) done(err);
|
headers: {
|
||||||
else if (res.statusCode === 409) {
|
'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]);
|
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)) {
|
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
|
||||||
done();
|
done();
|
||||||
@@ -50,10 +61,12 @@ describe('postWarning', () => {
|
|||||||
done("Warning missing from database");
|
done("Warning missing from database");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to remove warning if vip', (done: Done) => {
|
it('Should be able to remove warning if vip', (done: Done) => {
|
||||||
@@ -63,11 +76,16 @@ describe('postWarning', () => {
|
|||||||
enabled: false
|
enabled: false
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/warnUser", {json},
|
+ "/api/warnUser", {
|
||||||
(err, res, body) => {
|
method: 'POST',
|
||||||
if (err) done(err);
|
headers: {
|
||||||
else if (res.statusCode === 200) {
|
'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]);
|
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
|
||||||
if (row?.enabled == 0) {
|
if (row?.enabled == 0) {
|
||||||
done();
|
done();
|
||||||
@@ -75,10 +93,12 @@ describe('postWarning', () => {
|
|||||||
done("Warning missing from database");
|
done("Warning missing from database");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not be able to create warning if vip (exp 403)', (done: Done) => {
|
it('Should not be able to create warning if vip (exp 403)', (done: Done) => {
|
||||||
@@ -87,16 +107,23 @@ describe('postWarning', () => {
|
|||||||
userID: 'warning-1',
|
userID: 'warning-1',
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/warnUser", {json},
|
+ "/api/warnUser", {
|
||||||
(err, res, body) => {
|
method: 'POST',
|
||||||
if (err) done(err);
|
headers: {
|
||||||
else if (res.statusCode === 403) {
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(json),
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status === 403) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
@@ -70,30 +70,39 @@ describe('segmentShift', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Reject none VIP user', function (done: Done) {
|
it('Reject none VIP user', function (done: Done) {
|
||||||
request.post(`${baseURL}/api/segmentShift`, {
|
fetch(`${baseURL}/api/segmentShift`, {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
videoID: 'vsegshift01',
|
videoID: 'vsegshift01',
|
||||||
userID: 'segshift_randomuser001',
|
userID: 'segshift_randomuser001',
|
||||||
startTime: 20,
|
startTime: 20,
|
||||||
endTime: 30,
|
endTime: 30,
|
||||||
},
|
}),
|
||||||
}, (err, res) => {
|
})
|
||||||
if (err) return done(err);
|
.then(res => {
|
||||||
return done(res.statusCode === 403 ? undefined : res.statusCode);
|
done(res.status === 403 ? undefined : res.status);
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Shift is outside segments', function (done: Done) {
|
it('Shift is outside segments', function (done: Done) {
|
||||||
request.post(`${baseURL}/api/segmentShift`, {
|
fetch(`${baseURL}/api/segmentShift`, {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
videoID: 'vsegshift01',
|
videoID: 'vsegshift01',
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 20,
|
startTime: 20,
|
||||||
endTime: 30,
|
endTime: 30,
|
||||||
},
|
}),
|
||||||
}, (err, res) => {
|
})
|
||||||
if (err) return done(err);
|
.then(res => {
|
||||||
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
|
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||||
const expect = [
|
const expect = [
|
||||||
{
|
{
|
||||||
UUID: 'vsegshifttest01uuid01',
|
UUID: 'vsegshifttest01uuid01',
|
||||||
@@ -117,20 +126,25 @@ describe('segmentShift', function () {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
done(dbSponsorTimesCompareExpect(db, expect));
|
done(dbSponsorTimesCompareExpect(db, expect));
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Shift is inside segment', function (done: Done) {
|
it('Shift is inside segment', function (done: Done) {
|
||||||
request.post(`${baseURL}/api/segmentShift`, {
|
fetch(`${baseURL}/api/segmentShift`, {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
videoID: 'vsegshift01',
|
videoID: 'vsegshift01',
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 65,
|
startTime: 65,
|
||||||
endTime: 75,
|
endTime: 75,
|
||||||
},
|
}),
|
||||||
}, (err, res) => {
|
})
|
||||||
if (err) return done(err);
|
.then(res => {
|
||||||
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
|
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||||
const expect = [
|
const expect = [
|
||||||
{
|
{
|
||||||
UUID: 'vsegshifttest01uuid01',
|
UUID: 'vsegshifttest01uuid01',
|
||||||
@@ -154,20 +168,25 @@ describe('segmentShift', function () {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
done(dbSponsorTimesCompareExpect(db, expect));
|
done(dbSponsorTimesCompareExpect(db, expect));
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Shift is overlaping startTime of segment', function (done: Done) {
|
it('Shift is overlaping startTime of segment', function (done: Done) {
|
||||||
request.post(`${baseURL}/api/segmentShift`, {
|
fetch(`${baseURL}/api/segmentShift`, {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
videoID: 'vsegshift01',
|
videoID: 'vsegshift01',
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 32,
|
startTime: 32,
|
||||||
endTime: 42,
|
endTime: 42,
|
||||||
},
|
}),
|
||||||
}, (err, res) => {
|
})
|
||||||
if (err) return done(err);
|
.then(res => {
|
||||||
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
|
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||||
const expect = [
|
const expect = [
|
||||||
{
|
{
|
||||||
UUID: 'vsegshifttest01uuid01',
|
UUID: 'vsegshifttest01uuid01',
|
||||||
@@ -191,20 +210,25 @@ describe('segmentShift', function () {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
done(dbSponsorTimesCompareExpect(db, expect));
|
done(dbSponsorTimesCompareExpect(db, expect));
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Shift is overlaping endTime of segment', function (done: Done) {
|
it('Shift is overlaping endTime of segment', function (done: Done) {
|
||||||
request.post(`${baseURL}/api/segmentShift`, {
|
fetch(`${baseURL}/api/segmentShift`, {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
videoID: 'vsegshift01',
|
videoID: 'vsegshift01',
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 85,
|
startTime: 85,
|
||||||
endTime: 95,
|
endTime: 95,
|
||||||
},
|
}),
|
||||||
}, (err, res) => {
|
})
|
||||||
if (err) return done(err);
|
.then(res => {
|
||||||
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
|
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||||
const expect = [
|
const expect = [
|
||||||
{
|
{
|
||||||
UUID: 'vsegshifttest01uuid01',
|
UUID: 'vsegshifttest01uuid01',
|
||||||
@@ -228,20 +252,25 @@ describe('segmentShift', function () {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
done(dbSponsorTimesCompareExpect(db, expect));
|
done(dbSponsorTimesCompareExpect(db, expect));
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Shift is overlaping segment', function (done: Done) {
|
it('Shift is overlaping segment', function (done: Done) {
|
||||||
request.post(`${baseURL}/api/segmentShift`, {
|
fetch(`${baseURL}/api/segmentShift`, {
|
||||||
json: {
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
videoID: 'vsegshift01',
|
videoID: 'vsegshift01',
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 35,
|
startTime: 35,
|
||||||
endTime: 55,
|
endTime: 55,
|
||||||
},
|
}),
|
||||||
}, (err, res) => {
|
})
|
||||||
if (err) return done(err);
|
.then(res => {
|
||||||
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
|
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||||
const expect = [
|
const expect = [
|
||||||
{
|
{
|
||||||
UUID: 'vsegshifttest01uuid01',
|
UUID: 'vsegshifttest01uuid01',
|
||||||
@@ -266,8 +295,7 @@ describe('segmentShift', function () {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
done(dbSponsorTimesCompareExpect(db, expect));
|
done(dbSponsorTimesCompareExpect(db, expect));
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
import * as utils from '../utils';
|
import * as utils from '../utils';
|
||||||
import { getHash } from '../../src/utils/getHash';
|
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) => {
|
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) => {
|
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", {
|
||||||
if (err) done(err);
|
method: 'POST',
|
||||||
else if (res.statusCode === 200) {
|
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]);
|
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-0', 'testMan-unBan', 1]);
|
||||||
if (result.length !== 0) {
|
if (result.length !== 0) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@@ -34,16 +39,23 @@ describe('unBan', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
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) => {
|
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) => {
|
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", {
|
||||||
if (err) done(err);
|
method: 'POST',
|
||||||
else if (res.statusCode === 200) {
|
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]);
|
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
|
||||||
if (result.length !== 1) {
|
if (result.length !== 1) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@@ -52,16 +64,23 @@ describe('unBan', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
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 with a mix of noSegment entrys', (done) => {
|
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) => {
|
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", {
|
||||||
if (err) done(err);
|
method: 'POST',
|
||||||
else if (res.statusCode === 200) {
|
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]);
|
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE userID = ? AND shadowHidden = ?', ['testEntity-unBan', 1]);
|
||||||
if (result.length !== 1) {
|
if (result.length !== 1) {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@@ -70,9 +89,11 @@ describe('unBan', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const body = await res.text();
|
||||||
console.log(body);
|
console.log(body);
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import request from 'request';
|
import fetch from 'node-fetch';
|
||||||
import {config} from '../../src/config';
|
import {config} from '../../src/config';
|
||||||
import {db, privateDB} from '../../src/databases/databases';
|
import {db, privateDB} from '../../src/databases/databases';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
@@ -63,11 +63,10 @@ describe('voteOnSponsorTime', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to upvote a segment', (done: Done) => {
|
it('Should be able to upvote a segment', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
|
||||||
if (row.votes === 3) {
|
if (row.votes === 3) {
|
||||||
done();
|
done();
|
||||||
@@ -75,17 +74,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
|
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to downvote a segment', (done: Done) => {
|
it('Should be able to downvote a segment', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0", null,
|
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
||||||
if (row.votes < 10) {
|
if (row.votes < 10) {
|
||||||
done();
|
done();
|
||||||
@@ -93,17 +92,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
|
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
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()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0", null,
|
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
||||||
if (row.votes === 9) {
|
if (row.votes === 9) {
|
||||||
done();
|
done();
|
||||||
@@ -111,17 +110,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
|
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it("Should not be able to downvote a segment if the user is shadow banned", (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0", null,
|
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
|
||||||
if (row.votes === 10) {
|
if (row.votes === 10) {
|
||||||
done();
|
done();
|
||||||
@@ -129,17 +128,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
|
||||||
if (row.votes === 2) {
|
if (row.votes === 2) {
|
||||||
done();
|
done();
|
||||||
@@ -147,17 +146,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
|
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0", null,
|
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
|
||||||
if (row.votes === 10) {
|
if (row.votes === 10) {
|
||||||
done();
|
done();
|
||||||
@@ -165,17 +164,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('VIP should be able to completely downvote a segment', (done: Done) => {
|
it('VIP should be able to completely downvote a segment', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0", null,
|
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
|
||||||
if (row.votes <= -2) {
|
if (row.votes <= -2) {
|
||||||
done();
|
done();
|
||||||
@@ -183,17 +182,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
|
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to completely downvote your own segment', (done: Done) => {
|
it('should be able to completely downvote your own segment', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0", null,
|
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
|
||||||
if (row.votes <= -2) {
|
if (row.votes <= -2) {
|
||||||
done();
|
done();
|
||||||
@@ -201,17 +200,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not be able to completely downvote somebody elses segment', (done: Done) => {
|
it('should not be able to completely downvote somebody elses segment', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0", null,
|
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
|
||||||
if (row.votes === 499) {
|
if (row.votes === 499) {
|
||||||
done();
|
done();
|
||||||
@@ -219,17 +218,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should be able to vote for a category and it should add your vote to the database', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro", null,
|
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
|
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"]);
|
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||||
if (row.category === "sponsor" && categoryRows.length === 2
|
if (row.category === "sponsor" && categoryRows.length === 2
|
||||||
@@ -240,17 +239,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
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.");
|
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 {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not able to change to an invalid category', (done: Done) => {
|
it('Should not able to change to an invalid category', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory", null,
|
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 400) {
|
||||||
else if (res.statusCode === 400) {
|
|
||||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
|
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
|
||||||
if (row.category === "sponsor") {
|
if (row.category === "sponsor") {
|
||||||
done();
|
done();
|
||||||
@@ -258,17 +257,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
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()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro", null,
|
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let submissionRow = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
|
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 categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||||
let introVotes = 0;
|
let introVotes = 0;
|
||||||
@@ -287,27 +286,26 @@ describe('voteOnSponsorTime', () => {
|
|||||||
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
|
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should not be able to change your vote to an invalid category', (done: Done) => {
|
||||||
const vote = (inputCat: string, assertCat: string, callback: Done) => {
|
const vote = (inputCat: string, assertCat: string, callback: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat, null,
|
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat)
|
||||||
(err) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
|
||||||
else {
|
|
||||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]);
|
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]);
|
||||||
if (row.category === assertCat) {
|
if (row.category === assertCat) {
|
||||||
callback();
|
callback();
|
||||||
} else {
|
} else {
|
||||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
});
|
.catch(err => done(err));
|
||||||
};
|
};
|
||||||
vote("sponsor", "sponsor", () => {
|
vote("sponsor", "sponsor", () => {
|
||||||
vote("fakeCategory", "sponsor", done);
|
vote("fakeCategory", "sponsor", done);
|
||||||
@@ -316,11 +314,10 @@ describe('voteOnSponsorTime', () => {
|
|||||||
|
|
||||||
|
|
||||||
it('VIP should be able to vote for a category and it should immediately change', (done: Done) => {
|
it('VIP should be able to vote for a category and it should immediately change', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro", null,
|
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
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"]);
|
let row2 = db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]);
|
||||||
if (row.category === "outro" && row2.votes === 500) {
|
if (row.category === "outro" && row2.votes === 500) {
|
||||||
@@ -329,17 +326,17 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
|
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Submitter should be able to vote for a category and it should immediately change', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro", null,
|
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||||
if (row.category === "outro") {
|
if (row.category === "outro") {
|
||||||
done();
|
done();
|
||||||
@@ -347,43 +344,43 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
|
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Should not be able to category-vote on an invalid UUID submission', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro", null,
|
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 400) {
|
||||||
else if (res.statusCode === 400) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode + " instead of 400.");
|
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) => {
|
it('Non-VIP should not be able to upvote "dead" submission', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 403) {
|
||||||
else if (res.statusCode === 403) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode + " instead of 403");
|
done("Status code was " + res.status + " instead of 403");
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('VIP should be able to upvote "dead" submission', (done: Done) => {
|
it('VIP should be able to upvote "dead" submission', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||||
if (row.votes > -3) {
|
if (row.votes > -3) {
|
||||||
done();
|
done();
|
||||||
@@ -391,74 +388,74 @@ describe('voteOnSponsorTime', () => {
|
|||||||
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
|
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
done("Status code was " + res.status);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not be able to upvote a segment (Too many warning)', (done: Done) => {
|
it('Should not be able to upvote a segment (Too many warning)', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 403) {
|
||||||
else if (res.statusCode === 403) {
|
|
||||||
done(); // success
|
done(); // success
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode);
|
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) => {
|
it('Non-VIP should not be able to vote on a segment with no-segments category', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 403) {
|
||||||
else if (res.statusCode === 403) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode + " instead of 403");
|
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) => {
|
it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro", null,
|
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 403) {
|
||||||
else if (res.statusCode === 403) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode + " instead of 403");
|
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) => {
|
it('VIP should able to vote on a segment with no-segments category', (done: Done) => {
|
||||||
request.get(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode + " instead of 200");
|
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) => {
|
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()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1", null,
|
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1")
|
||||||
(err, res) => {
|
.then(res => {
|
||||||
if (err) done(err);
|
if (res.status === 200) {
|
||||||
else if (res.statusCode === 200) {
|
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.statusCode + " instead of 200");
|
done("Status code was " + res.status + " instead of 200");
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user