mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-12 22:47:12 +03:00
remaining tests
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const VIPUser = "clearCacheVIP";
|
const VIPUser = "clearCacheVIP";
|
||||||
const regularUser = "regular-user";
|
const regularUser = "regular-user";
|
||||||
const endpoint = `${getbaseURL()}/api/clearCache`;
|
const endpoint = "/api/clearCache";
|
||||||
|
const postClearCache = (userID: string, videoID: string) => client({ method: "post", url: endpoint, params: { userID, videoID } });
|
||||||
|
|
||||||
describe("postClearCache", () => {
|
describe("postClearCache", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
@@ -16,10 +15,8 @@ describe("postClearCache", () => {
|
|||||||
await db.prepare("run", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0)`);
|
await db.prepare("run", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0)`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to clear cache for existing video", (done: Done) => {
|
it("Should be able to clear cache for existing video", (done) => {
|
||||||
fetch(`${endpoint}?userID=${VIPUser}&videoID=clear-test`, {
|
postClearCache(VIPUser, "clear-test")
|
||||||
method: "POST"
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
@@ -27,10 +24,8 @@ describe("postClearCache", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to clear cache for nonexistent video", (done: Done) => {
|
it("Should be able to clear cache for nonexistent video", (done) => {
|
||||||
fetch(`${endpoint}?userID=${VIPUser}&videoID=dne-video`, {
|
postClearCache(VIPUser, "dne-video")
|
||||||
method: "POST"
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
@@ -38,10 +33,8 @@ describe("postClearCache", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get 403 as non-vip", (done: Done) => {
|
it("Should get 403 as non-vip", (done) => {
|
||||||
fetch(`${endpoint}?userID=${regularUser}&videoID=clear-tes`, {
|
postClearCache(regularUser, "clear-test")
|
||||||
method: "POST"
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
@@ -49,10 +42,8 @@ describe("postClearCache", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should give 400 with missing videoID", (done: Done) => {
|
it("Should give 400 with missing videoID", (done) => {
|
||||||
fetch(`${endpoint}?userID=${VIPUser}`, {
|
client.post(endpoint, { params: { userID: VIPUser } })
|
||||||
method: "POST"
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
@@ -60,10 +51,8 @@ describe("postClearCache", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should give 400 with missing userID", (done: Done) => {
|
it("Should give 400 with missing userID", (done) => {
|
||||||
fetch(`${endpoint}?userID=${VIPUser}`, {
|
client.post(endpoint, { params: { videoID: "clear-test" } })
|
||||||
method: "POST"
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { Done, postJSON } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import { IDatabase } from "../../src/databases/IDatabase";
|
import { IDatabase } from "../../src/databases/IDatabase";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
|
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
|
||||||
const votes = 0,
|
const votes = 0,
|
||||||
@@ -34,7 +32,8 @@ async function dbSponsorTimesCompareExpect(db: IDatabase, videoId: string, expec
|
|||||||
describe("postPurgeAllSegments", function () {
|
describe("postPurgeAllSegments", function () {
|
||||||
const privateVipUserID = "VIPUser-purgeAll";
|
const privateVipUserID = "VIPUser-purgeAll";
|
||||||
const vipUserID = getHash(privateVipUserID);
|
const vipUserID = getHash(privateVipUserID);
|
||||||
const endpoint = `${getbaseURL()}/api/purgeAllSegments`;
|
const endpoint = "/api/purgeAllSegments";
|
||||||
|
const postSegmentShift = (videoID: string, userID: string) => client.post(endpoint, { videoID, userID });
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
// startTime and endTime get set in beforeEach for consistency
|
// startTime and endTime get set in beforeEach for consistency
|
||||||
@@ -46,29 +45,17 @@ describe("postPurgeAllSegments", function () {
|
|||||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [vipUserID]);
|
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [vipUserID]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Reject non-VIP user", function (done: Done) {
|
it("Reject non-VIP user", function (done) {
|
||||||
fetch(endpoint, {
|
postSegmentShift("vsegpurge01", "segshift_randomuser001")
|
||||||
...postJSON,
|
.then(res => {
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegpurge01",
|
|
||||||
userID: "segshift_randomuser001",
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Purge all segments success", function (done: Done) {
|
it("Purge all segments success", function (done) {
|
||||||
fetch(endpoint, {
|
postSegmentShift("vsegpurge01", privateVipUserID)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegpurge01",
|
|
||||||
userID: privateVipUserID,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done(await dbSponsorTimesCompareExpect(db, "vsegpurge01", 1) || await dbSponsorTimesCompareExpect(db, "vseg-not-purged01", 0));
|
done(await dbSponsorTimesCompareExpect(db, "vsegpurge01", 1) || await dbSponsorTimesCompareExpect(db, "vseg-not-purged01", 0));
|
||||||
@@ -76,9 +63,9 @@ describe("postPurgeAllSegments", function () {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if missing body", function (done: Done) {
|
it("Should return 400 if missing body", function (done) {
|
||||||
fetch(endpoint, { ...postJSON })
|
client.post(endpoint, {})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
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, postJSON } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { ImportMock } from "ts-mock-imports";
|
import { ImportMock } from "ts-mock-imports";
|
||||||
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
|
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
|
||||||
import { YouTubeApiMock } from "../youtubeMock";
|
import { YouTubeApiMock } from "../youtubeMock";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
||||||
const sinonStub = mockManager.mock("listVideos");
|
const sinonStub = mockManager.mock("listVideos");
|
||||||
@@ -38,7 +36,17 @@ describe("postSkipSegments", () => {
|
|||||||
const queryDatabaseActionType = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
const queryDatabaseActionType = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||||
const queryDatabaseDuration = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
const queryDatabaseDuration = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||||
|
|
||||||
const endpoint = `${getbaseURL()}/api/skipSegments`;
|
const endpoint = "/api/skipSegments";
|
||||||
|
const postSkipSegmentJSON = (data: Record<string, any>) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
data
|
||||||
|
});
|
||||||
|
const postSkipSegmentParam = (params: Record<string, any>) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params
|
||||||
|
});
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
@@ -81,10 +89,14 @@ describe("postSkipSegments", () => {
|
|||||||
db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]);
|
db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]);
|
||||||
});
|
});
|
||||||
|
|
||||||
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) => {
|
||||||
const videoID = "dQw4w9WgXcR";
|
const videoID = "dQw4w9WgXcR";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=2&endTime=10&userID=${submitUserOne}&category=sponsor`, {
|
postSkipSegmentParam({
|
||||||
method: "POST"
|
videoID,
|
||||||
|
startTime: 2,
|
||||||
|
endTime: 10,
|
||||||
|
userID: submitUserOne,
|
||||||
|
category: "sponsor"
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -100,18 +112,15 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const videoID = "dQw4w9WgXcF";
|
const videoID = "dQw4w9WgXcF";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -128,11 +137,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit a single time with an action type (JSON method)", (done: Done) => {
|
it("Should be able to submit a single time with an action type (JSON method)", (done) => {
|
||||||
const videoID = "dQw4w9WgXcV";
|
const videoID = "dQw4w9WgXcV";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -140,7 +147,6 @@ describe("postSkipSegments", () => {
|
|||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
actionType: "mute"
|
actionType: "mute"
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -157,11 +163,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to submit an intro with mute action type (JSON method)", (done: Done) => {
|
it("Should not be able to submit an intro with mute action type (JSON method)", (done) => {
|
||||||
const videoID = "dQw4w9WgXpQ";
|
const videoID = "dQw4w9WgXpQ";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -169,7 +173,6 @@ describe("postSkipSegments", () => {
|
|||||||
category: "intro",
|
category: "intro",
|
||||||
actionType: "mute"
|
actionType: "mute"
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -180,11 +183,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done: Done) => {
|
it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done) => {
|
||||||
const videoID = "dQw4w9WgXZX";
|
const videoID = "dQw4w9WgXZX";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
videoDuration: 100,
|
videoDuration: 100,
|
||||||
@@ -192,7 +193,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -209,11 +209,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)", (done: Done) => {
|
it("Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)", (done) => {
|
||||||
const videoID = "dQw4w9WgXZH";
|
const videoID = "dQw4w9WgXZH";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
videoDuration: 4980.20,
|
videoDuration: 4980.20,
|
||||||
@@ -221,7 +219,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [1, 10],
|
segment: [1, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -239,11 +236,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit a single time with a duration in the body (JSON method)", (done: Done) => {
|
it("Should be able to submit a single time with a duration in the body (JSON method)", (done) => {
|
||||||
const videoID = "noDuration";
|
const videoID = "noDuration";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
videoDuration: 100,
|
videoDuration: 100,
|
||||||
@@ -251,7 +246,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -275,9 +269,7 @@ describe("postSkipSegments", () => {
|
|||||||
VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor"]);
|
VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor"]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(endpoint, {
|
const res = await postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
videoDuration: 100,
|
videoDuration: 100,
|
||||||
@@ -285,7 +277,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [1, 10],
|
segment: [1, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const lockCategoriesRow = await db.prepare("get", `SELECT * from "lockCategories" WHERE videoID = ?`, [videoID]);
|
const lockCategoriesRow = await db.prepare("get", `SELECT * from "lockCategories" WHERE videoID = ?`, [videoID]);
|
||||||
@@ -309,10 +300,16 @@ describe("postSkipSegments", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should still not be allowed if youtube thinks duration is 0", (done: Done) => {
|
it("Should still not be allowed if youtube thinks duration is 0", (done) => {
|
||||||
const videoID= "noDuration";
|
const videoID= "noDuration";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=10000&userID=${submitUserThree}&category=sponsor`, {
|
postSkipSegmentJSON({
|
||||||
method: "POST",
|
userID: submitUserThree,
|
||||||
|
videoID,
|
||||||
|
videoDuration: 100,
|
||||||
|
segments: [{
|
||||||
|
segment: [30, 10000],
|
||||||
|
category: "sponsor",
|
||||||
|
}],
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
@@ -321,11 +318,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit a single time under a different service (JSON method)", (done: Done) => {
|
it("Should be able to submit a single time under a different service (JSON method)", (done) => {
|
||||||
const videoID = "dQw4w9WgXcG";
|
const videoID = "dQw4w9WgXcG";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
service: "PeerTube",
|
service: "PeerTube",
|
||||||
@@ -333,7 +328,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -351,18 +345,15 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("VIP submission should start locked", (done: Done) => {
|
it("VIP submission should start locked", (done) => {
|
||||||
const videoID = "vipuserIDSubmission";
|
const videoID = "vipuserIDSubmission";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitVIPuser,
|
userID: submitVIPuser,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -379,11 +370,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const videoID = "dQw4w9WgXcT";
|
const videoID = "dQw4w9WgXcT";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -393,7 +382,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [30, 60],
|
segment: [30, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -413,11 +401,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const videoID = "L_jWHffIx5E";
|
const videoID = "L_jWHffIx5E";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -433,7 +419,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [99, 170],
|
segment: [99, 170],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -461,11 +446,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const videoID = "n9rIGdXnSJc";
|
const videoID = "n9rIGdXnSJc";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -481,7 +464,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [4050, 4750],
|
segment: [4050, 4750],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
@@ -492,11 +474,9 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const videoID = "80percent_video";
|
const videoID = "80percent_video";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -509,7 +489,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [4050, 4750],
|
segment: [4050, 4750],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
@@ -533,10 +512,14 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const videoID = "qqwerty";
|
const videoID = "qqwerty";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}&category=intro`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 30,
|
||||||
|
endTime: 30.5,
|
||||||
|
userID: submitUserTwo,
|
||||||
|
category: "intro"
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -545,10 +528,14 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected if segment starts and ends at the same time", (done: Done) => {
|
it("Should be rejected if segment starts and ends at the same time", (done) => {
|
||||||
const videoID = "qqwerty";
|
const videoID = "qqwerty";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=90&endTime=90&userID=${submitUserTwo}&category=intro`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 90,
|
||||||
|
endTime: 90,
|
||||||
|
userID: submitUserTwo,
|
||||||
|
category: "intro"
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -557,10 +544,14 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be accepted if highlight segment starts and ends at the same time", (done: Done) => {
|
it("Should be accepted if highlight segment starts and ends at the same time", (done) => {
|
||||||
const videoID = "qqwerty";
|
const videoID = "qqwerty";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30&userID=${submitUserTwo}&category=poi_highlight`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 30,
|
||||||
|
endTime: 30,
|
||||||
|
userID: submitUserTwo,
|
||||||
|
category: "poi_highlight"
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -569,10 +560,14 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected if highlight segment doesn't start and end at the same time", (done: Done) => {
|
it("Should be rejected if highlight segment doesn't start and end at the same time", (done) => {
|
||||||
const videoID = "qqwerty";
|
const videoID = "qqwerty";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}&category=poi_highlight`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 30,
|
||||||
|
endTime: 30.5,
|
||||||
|
userID: submitUserTwo,
|
||||||
|
category: "poi_highlight"
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -581,10 +576,13 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
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) => {
|
||||||
const videoID = "qqwerty";
|
const videoID = "qqwerty";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 30,
|
||||||
|
endTime: 30.5,
|
||||||
|
userID: submitUserTwo
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -593,45 +591,50 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected if over 80% of the video", (done: Done) => {
|
it("Should be rejected if over 80% of the video", (done) => {
|
||||||
const videoID = "qqwerty";
|
const videoID = "qqwerty";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=1000000&userID=${submitUserTwo}&category=sponsor`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 30,
|
||||||
|
endTime: 1000000,
|
||||||
|
userID: submitUserTwo,
|
||||||
|
category: "sponsor"
|
||||||
})
|
})
|
||||||
.then( async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
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) => {
|
||||||
const videoID = "LevkAjUE6d4";
|
const videoID = "LevkAjUE6d4";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=40&endTime=60&userID=${submitUserTwo}&category=sponsor`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 40,
|
||||||
|
endTime: 60,
|
||||||
|
userID: submitUserTwo,
|
||||||
|
category: "sponsor"
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected with custom message if user has to many active warnings", (done: Done) => {
|
it("Should be rejected with custom message if user has to many active warnings", (done) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: warnUser01,
|
userID: warnUser01,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
const errorMessage = await res.text();
|
const errorMessage = res.data;
|
||||||
const reason = "Reason01";
|
const reason = "Reason01";
|
||||||
const expected = "Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes"
|
const expected = "Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes"
|
||||||
+ " that are not malicious, and we just want to clarify the rules. "
|
+ " that are not malicious, and we just want to clarify the rules. "
|
||||||
@@ -644,88 +647,77 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: warnUser02,
|
userID: warnUser02,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [50, 60],
|
segment: [50, 60],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
done(); // success
|
done(); // success
|
||||||
} else {
|
} else {
|
||||||
const body = await res.text();
|
done(`Status code was ${res.status} ${res.data}`);
|
||||||
done(`Status code was ${res.status} ${body}`);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be accepted if user has some warnings removed", (done: Done) => {
|
it("Should be accepted if user has some warnings removed", (done) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: warnUser03,
|
userID: warnUser03,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [53, 60],
|
segment: [53, 60],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
done(); // success
|
done(); // success
|
||||||
} else {
|
} else {
|
||||||
const body = await res.text();
|
done(`Status code was ${res.status} ${res.data}`);
|
||||||
done(`Status code was ${res.status} ${body}`);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for missing params (Params method)", (done: Done) => {
|
it("Should return 400 for missing params (Params method)", (done) => {
|
||||||
fetch(`${endpoint}?startTime=9&endTime=10&userID=${submitUserOne}`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
startTime: 9,
|
||||||
|
endTime: 10,
|
||||||
|
userID: submitUserOne
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
if (res.status === 400) done();
|
if (res.status === 400) done();
|
||||||
else done(true);
|
else done(true);
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected with default message if user has to many active warnings", (done: Done) => {
|
it("Should be rejected with default message if user has to many active warnings", (done) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: warnUser01,
|
userID: warnUser01,
|
||||||
videoID: warnVideoID,
|
videoID: warnVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
const errorMessage = await res.text();
|
const errorMessage = res.data;
|
||||||
assert.notStrictEqual(errorMessage, "");
|
assert.notStrictEqual(errorMessage, "");
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for missing params (JSON method) 1", (done: Done) => {
|
it("Should return 400 for missing params (JSON method) 1", (done) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [9, 10],
|
segment: [9, 10],
|
||||||
@@ -734,7 +726,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [31, 60],
|
segment: [31, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -742,13 +733,10 @@ describe("postSkipSegments", () => {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
it("Should return 400 for missing params (JSON method) 2", (done: Done) => {
|
it("Should return 400 for missing params (JSON method) 2", (done) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID: badInputVideoID,
|
videoID: badInputVideoID,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -756,10 +744,8 @@ describe("postSkipSegments", () => {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
it("Should return 400 for missing params (JSON method) 3", (done: Done) => {
|
it("Should return 400 for missing params (JSON method) 3", (done) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID: badInputVideoID,
|
videoID: badInputVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -769,7 +755,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [31, 60],
|
segment: [31, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -777,10 +762,9 @@ describe("postSkipSegments", () => {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
it("Should return 400 for missing params (JSON method) 4", (done: Done) => {
|
|
||||||
fetch(endpoint, {
|
it("Should return 400 for missing params (JSON method) 4", (done) => {
|
||||||
...postJSON,
|
postSkipSegmentJSON({
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID: badInputVideoID,
|
videoID: badInputVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -789,7 +773,6 @@ describe("postSkipSegments", () => {
|
|||||||
segment: [31, 60],
|
segment: [31, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -797,13 +780,11 @@ describe("postSkipSegments", () => {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
it("Should return 400 for missing params (JSON method) 5", (done: Done) => {
|
|
||||||
fetch(endpoint, {
|
it("Should return 400 for missing params (JSON method) 5", (done) => {
|
||||||
...postJSON,
|
postSkipSegmentJSON({
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID: badInputVideoID,
|
videoID: badInputVideoID,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -812,73 +793,64 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 403 and custom reason for submiting in lockedCategory", async () => {
|
it("Should return 403 and custom reason for submiting in lockedCategory", (done) => {
|
||||||
const videoID = "lockedVideo";
|
const videoID = "lockedVideo";
|
||||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
|
db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
|
||||||
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor", "Custom Reason"]);
|
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor", "Custom Reason"])
|
||||||
|
.then(() => postSkipSegmentJSON({
|
||||||
try {
|
|
||||||
const res = await fetch(endpoint, {
|
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [1, 10],
|
segment: [1, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
}))
|
||||||
});
|
.then(res => {
|
||||||
|
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
assert.match(await res.text(), /Lock reason: /);
|
assert.match(res.data, /Lock reason: /);
|
||||||
assert.match(await res.text(), /Custom Reason/);
|
assert.match(res.data, /Custom Reason/);
|
||||||
} catch (e) {
|
done();
|
||||||
return e;
|
})
|
||||||
}
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 403 for submiting in lockedCategory", async () => {
|
it("Should return 403 for submiting in lockedCategory", (done) => {
|
||||||
const videoID = "lockedVideo1";
|
const videoID = "lockedVideo1";
|
||||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
|
db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
|
||||||
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "intro", ""]);
|
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "intro", ""])
|
||||||
|
.then(() => postSkipSegmentJSON({
|
||||||
try {
|
|
||||||
const res = await fetch(endpoint, {
|
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [1, 10],
|
segment: [1, 10],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
}))
|
||||||
|
.then(res => {
|
||||||
|
assert.strictEqual(res.status, 403);
|
||||||
|
assert.doesNotMatch(res.data, /Lock reason: /);
|
||||||
|
assert.doesNotMatch(res.data, /Custom Reason/);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(res.status, 403);
|
it("Should be able to submit with custom user-agent 1", (done) => {
|
||||||
assert.doesNotMatch(await res.text(), /Lock reason: /);
|
client({
|
||||||
assert.doesNotMatch(await res.text(), /Custom Reason/);
|
url: endpoint,
|
||||||
} catch (e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}).timeout(5000);
|
|
||||||
|
|
||||||
it("Should be able to submit with custom user-agent 1", (done: Done) => {
|
|
||||||
fetch(endpoint, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"User-Agent": "com.google.android.youtube/5.0"
|
"User-Agent": "com.google.android.youtube/5.0"
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
data: {
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID: "userAgent-1",
|
videoID: "userAgent-1",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -894,21 +866,19 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit with empty user-agent", (done: Done) => {
|
it("Should be able to submit with empty user-agent", (done) => {
|
||||||
fetch(endpoint, {
|
client({
|
||||||
|
url: endpoint,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
data: {
|
||||||
"Content-Type": "application/json",
|
|
||||||
"User-Agent": ""
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID: "userAgent-3",
|
videoID: "userAgent-3",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [0, 10],
|
segment: [0, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
userAgent: "",
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -924,13 +894,8 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit with custom userAgent in body", (done: Done) => {
|
it("Should be able to submit with custom userAgent in body", (done) => {
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID: "userAgent-4",
|
videoID: "userAgent-4",
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -938,7 +903,6 @@ describe("postSkipSegments", () => {
|
|||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
userAgent: "MeaBot/5.0"
|
userAgent: "MeaBot/5.0"
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -954,18 +918,15 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit with commas in timestamps", (done: Done) => {
|
it("Should be able to submit with commas in timestamps", (done) => {
|
||||||
const videoID = "commas-1";
|
const videoID = "commas-1";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: ["0,2", "10,392"],
|
segment: ["0,2", "10,392"],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}]
|
}]
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -980,10 +941,14 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be rejected if a POI is at less than 1 second", (done: Done) => {
|
it("Should be rejected if a POI is at less than 1 second", (done) => {
|
||||||
const videoID = "qqwerty";
|
const videoID = "qqwerty";
|
||||||
fetch(`${endpoint}?videoID=${videoID}&startTime=0.5&endTime=0.5&category=poi_highlight&userID=${submitUserTwo}`, {
|
postSkipSegmentParam({
|
||||||
method: "POST",
|
videoID,
|
||||||
|
startTime: 0.5,
|
||||||
|
endTime: 0.5,
|
||||||
|
category: "poi_highlight",
|
||||||
|
userID: submitUserTwo
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
@@ -992,18 +957,15 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to submit with colons in timestamps", (done: Done) => {
|
it("Should not be able to submit with colons in timestamps", (done) => {
|
||||||
const videoID = "colon-1";
|
const videoID = "colon-1";
|
||||||
fetch(endpoint, {
|
postSkipSegmentJSON({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: submitUserOne,
|
userID: submitUserOne,
|
||||||
videoID,
|
videoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: ["0:2.000", "3:10.392"],
|
segment: ["0:2.000", "3:10.392"],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}]
|
}]
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
|
|||||||
@@ -1,30 +1,25 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { Done, postJSON } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
describe("postWarning", () => {
|
describe("postWarning", () => {
|
||||||
// constants
|
// constants
|
||||||
const endpoint = `${getbaseURL()}/api/warnUser`;
|
const endpoint = "/api/warnUser";
|
||||||
const getWarning = (userID: string) => db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [userID]);
|
const getWarning = (userID: string) => db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [userID]);
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash("warning-vip")]);
|
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash("warning-vip")]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to create warning if vip (exp 200)", (done: Done) => {
|
it("Should be able to create warning if vip (exp 200)", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: "warning-vip",
|
issuerUserID: "warning-vip",
|
||||||
userID: "warning-0",
|
userID: "warning-0",
|
||||||
reason: "warning-reason-0"
|
reason: "warning-reason-0"
|
||||||
};
|
};
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getWarning(json.userID);
|
const row = await getWarning(json.userID);
|
||||||
@@ -39,16 +34,13 @@ describe("postWarning", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: "warning-vip",
|
issuerUserID: "warning-vip",
|
||||||
userID: "warning-0",
|
userID: "warning-0",
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 409);
|
assert.strictEqual(res.status, 409);
|
||||||
const row = await getWarning(json.userID);
|
const row = await getWarning(json.userID);
|
||||||
@@ -62,17 +54,14 @@ describe("postWarning", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: "warning-vip",
|
issuerUserID: "warning-vip",
|
||||||
userID: "warning-0",
|
userID: "warning-0",
|
||||||
enabled: false
|
enabled: false
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getWarning(json.userID);
|
const row = await getWarning(json.userID);
|
||||||
@@ -85,16 +74,13 @@ describe("postWarning", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to create warning if not vip (exp 403)", (done: Done) => {
|
it("Should not be able to create warning if not vip (exp 403)", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: "warning-not-vip",
|
issuerUserID: "warning-not-vip",
|
||||||
userID: "warning-1",
|
userID: "warning-1",
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
@@ -102,8 +88,8 @@ describe("postWarning", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if missing body", (done: Done) => {
|
it("Should return 400 if missing body", (done) => {
|
||||||
fetch(endpoint, postJSON)
|
client.post(endpoint, {})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
@@ -111,17 +97,14 @@ describe("postWarning", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should re-enable disabled warning", (done: Done) => {
|
it("Should re-enable disabled warning", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
issuerUserID: "warning-vip",
|
issuerUserID: "warning-vip",
|
||||||
userID: "warning-0",
|
userID: "warning-0",
|
||||||
enabled: true
|
enabled: true
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await getWarning(json.userID);
|
const data = await getWarning(json.userID);
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { Done, postJSON } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import { IDatabase } from "../../src/databases/IDatabase";
|
import { IDatabase } from "../../src/databases/IDatabase";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
describe("segmentShift", function () {
|
describe("segmentShift", function () {
|
||||||
// functions
|
// functions
|
||||||
@@ -42,7 +40,12 @@ describe("segmentShift", function () {
|
|||||||
// constants
|
// constants
|
||||||
const privateVipUserID = "VIPUser-segmentShift";
|
const privateVipUserID = "VIPUser-segmentShift";
|
||||||
const vipUserID = getHash(privateVipUserID);
|
const vipUserID = getHash(privateVipUserID);
|
||||||
const endpoint = `${getbaseURL()}/api/segmentShift`;
|
const endpoint = "/api/segmentShift";
|
||||||
|
const postSegmentShift = async (data: Record<string, any>) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
// startTime and endTime get set in beforeEach for consistency
|
// startTime and endTime get set in beforeEach for consistency
|
||||||
@@ -61,15 +64,12 @@ describe("segmentShift", function () {
|
|||||||
await dbSponsorTimesSetByUUID(db, "vsegshifttest01uuid04", 120, 140);
|
await dbSponsorTimesSetByUUID(db, "vsegshifttest01uuid04", 120, 140);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Reject none VIP user", function (done: Done) {
|
it("Reject non VIP user", (done) => {
|
||||||
fetch(endpoint, {
|
postSegmentShift({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegshift01",
|
videoID: "vsegshift01",
|
||||||
userID: "segshift_randomuser001",
|
userID: "segshift_randomuser001",
|
||||||
startTime: 20,
|
startTime: 20,
|
||||||
endTime: 30,
|
endTime: 30,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
@@ -78,15 +78,12 @@ describe("segmentShift", function () {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Shift is outside segments", function (done: Done) {
|
it("Shift is outside segments", (done) => {
|
||||||
fetch(endpoint, {
|
postSegmentShift({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegshift01",
|
videoID: "vsegshift01",
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 20,
|
startTime: 20,
|
||||||
endTime: 30,
|
endTime: 30,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -112,15 +109,12 @@ describe("segmentShift", function () {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Shift is inside segment", function (done: Done) {
|
it("Shift is inside segment", (done) => {
|
||||||
fetch(endpoint, {
|
postSegmentShift({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegshift01",
|
videoID: "vsegshift01",
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 65,
|
startTime: 65,
|
||||||
endTime: 75,
|
endTime: 75,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -146,15 +140,12 @@ describe("segmentShift", function () {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Shift is overlaping startTime of segment", function (done: Done) {
|
it("Shift is overlaping startTime of segment", (done) => {
|
||||||
fetch(endpoint, {
|
postSegmentShift({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegshift01",
|
videoID: "vsegshift01",
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 32,
|
startTime: 32,
|
||||||
endTime: 42,
|
endTime: 42,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -180,15 +171,12 @@ describe("segmentShift", function () {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Shift is overlaping endTime of segment", function (done: Done) {
|
it("Shift is overlaping endTime of segment", (done) => {
|
||||||
fetch(endpoint, {
|
postSegmentShift({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegshift01",
|
videoID: "vsegshift01",
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 85,
|
startTime: 85,
|
||||||
endTime: 95,
|
endTime: 95,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -214,15 +202,12 @@ describe("segmentShift", function () {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Shift is overlaping segment", function (done: Done) {
|
it("Shift is overlaping segment", (done) => {
|
||||||
fetch(endpoint, {
|
postSegmentShift({
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
videoID: "vsegshift01",
|
videoID: "vsegshift01",
|
||||||
userID: privateVipUserID,
|
userID: privateVipUserID,
|
||||||
startTime: 35,
|
startTime: 35,
|
||||||
endTime: 55,
|
endTime: 55,
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { db, privateDB } from "../../src/databases/databases";
|
import { db, privateDB } from "../../src/databases/databases";
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const adminPrivateUserID = "testUserId";
|
const adminPrivateUserID = "testUserId";
|
||||||
const user00PrivateUserID = "setUsername_00";
|
const user00PrivateUserID = "setUsername_00";
|
||||||
@@ -52,7 +50,7 @@ function wellFormatUserName(userName: string) {
|
|||||||
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
|
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean, done: Done) {
|
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean, done: Mocha.Done) {
|
||||||
const log = await getLastLogUserNameChange(userID);
|
const log = await getLastLogUserNameChange(userID);
|
||||||
assert.strictEqual(newUserName, log.newUserName);
|
assert.strictEqual(newUserName, log.newUserName);
|
||||||
assert.strictEqual(oldUserName, log.oldUserName);
|
assert.strictEqual(oldUserName, log.oldUserName);
|
||||||
@@ -60,8 +58,27 @@ async function testUserNameChangelog(userID: string, newUserName: string, oldUse
|
|||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const endpoint = "/api/setUsername";
|
||||||
|
const postSetUserName = (userID: string, username: string) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
username,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const postSetUserNameAdmin = (userID: string, username: string, adminUserID: string) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
username,
|
||||||
|
adminUserID,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
describe("setUsername", () => {
|
describe("setUsername", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/setUsername`;
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await addUsername(getHash(user01PrivateUserID), username01, 0);
|
await addUsername(getHash(user01PrivateUserID), username01, 0);
|
||||||
await addUsername(getHash(user02PrivateUserID), username02, 0);
|
await addUsername(getHash(user02PrivateUserID), username02, 0);
|
||||||
@@ -72,157 +89,147 @@ describe("setUsername", () => {
|
|||||||
await addUsername(getHash(user07PrivateUserID), username07, 1);
|
await addUsername(getHash(user07PrivateUserID), username07, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to set username that has never been set", (done: Done) => {
|
it("Should be able to set username that has never been set", (done) => {
|
||||||
fetch(`${endpoint}?userID=${user00PrivateUserID}&username=${username00}`, {
|
postSetUserName(user00PrivateUserID, username00)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
|
console.log(res.data);
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
|
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
assert.strictEqual(usernameInfo.userName, username00);
|
assert.strictEqual(usernameInfo.userName, username00);
|
||||||
assert.notStrictEqual(usernameInfo.locked, 1, "username should not be locked");
|
assert.notStrictEqual(usernameInfo.locked, 1, "username should not be locked");
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 200", (done: Done) => {
|
it("Should return 200", (done) => {
|
||||||
fetch(`${endpoint}?userID=${user01PrivateUserID}&username=Changed%20Username`, {
|
const username = "Changed%20Username";
|
||||||
method: "POST",
|
postSetUserName(user01PrivateUserID, username)
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
testUserNameChangelog(user01PrivateUserID, decodeURIComponent("Changed%20Username"), username01, false, done);
|
testUserNameChangelog(user01PrivateUserID, username, username01, false, done);
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for missing param "userID"', (done: Done) => {
|
it('Should return 400 for missing param "userID"', (done) => {
|
||||||
fetch(`${endpoint}?username=MyUsername`, {
|
client({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
data: {
|
||||||
|
userName: "MyUsername"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for missing param "username"', (done: Done) => {
|
it('Should return 400 for missing param "username"', (done) => {
|
||||||
fetch(`${endpoint}?userID=test`, {
|
client({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
data: {
|
||||||
|
userID: "test"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 400 for "username" longer then 64 characters', (done: Done) => {
|
it('Should return 400 for "username" longer then 64 characters', (done) => {
|
||||||
const username65 = "0000000000000000000000000000000000000000000000000000000000000000X";
|
const username65 = "0000000000000000000000000000000000000000000000000000000000000000X";
|
||||||
fetch(`${endpoint}?userID=test&username=${encodeURIComponent(username65)}`, {
|
postSetUserName("test", username65)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not change username if it contains "discord"', (done: Done) => {
|
it('Should not change username if it contains "discord"', (done) => {
|
||||||
const newUsername = "discord.me";
|
const newUsername = "discord.me";
|
||||||
fetch(`${endpoint}?userID=${user02PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
postSetUserName(user02PrivateUserID, newUsername)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const userNameInfo = await getUsernameInfo(getHash(user02PrivateUserID));
|
const userNameInfo = await getUsernameInfo(getHash(user02PrivateUserID));
|
||||||
assert.notStrictEqual(userNameInfo.userName, newUsername);
|
assert.notStrictEqual(userNameInfo.userName, newUsername);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to change username", (done: Done) => {
|
it("Should be able to change username", (done) => {
|
||||||
const newUsername = "newUsername";
|
const newUsername = "newUsername";
|
||||||
fetch(`${endpoint}?userID=${user03PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
postSetUserName(user03PrivateUserID, newUsername)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user03PrivateUserID));
|
const usernameInfo = await getUsernameInfo(getHash(user03PrivateUserID));
|
||||||
assert.strictEqual(usernameInfo.userName, newUsername, "Username should change");
|
assert.strictEqual(usernameInfo.userName, newUsername, "Username should change");
|
||||||
assert.notStrictEqual(usernameInfo.locked, 1, "Username should not be locked");
|
assert.notStrictEqual(usernameInfo.locked, 1, "Username should not be locked");
|
||||||
testUserNameChangelog(user03PrivateUserID, newUsername, username03, false, done);
|
testUserNameChangelog(user03PrivateUserID, newUsername, username03, false, done);
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to change locked username", (done: Done) => {
|
it("Should not be able to change locked username", (done) => {
|
||||||
const newUsername = "newUsername";
|
const newUsername = "newUsername";
|
||||||
fetch(`${endpoint}?userID=${user04PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
postSetUserName(user04PrivateUserID, newUsername)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user04PrivateUserID));
|
const usernameInfo = await getUsernameInfo(getHash(user04PrivateUserID));
|
||||||
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not be changed");
|
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not be changed");
|
||||||
assert.strictEqual(usernameInfo.locked, 1, "username should be locked");
|
assert.strictEqual(usernameInfo.locked, 1, "username should be locked");
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch((err) => done(`couldn't call endpoint: ${err}`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should filter out unicode control characters", (done: Done) => {
|
it("Should filter out unicode control characters", (done) => {
|
||||||
const newUsername = "This\nUsername+has\tInvalid+Characters";
|
const newUsername = "This\nUsername+has\tInvalid+Characters";
|
||||||
fetch(`${endpoint}?userID=${user05PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
postSetUserName(user05PrivateUserID, newUsername)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user05PrivateUserID));
|
const usernameInfo = await getUsernameInfo(getHash(user05PrivateUserID));
|
||||||
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not contain control characters");
|
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not contain control characters");
|
||||||
testUserNameChangelog(user05PrivateUserID, wellFormatUserName(newUsername), username05, false, done);
|
testUserNameChangelog(user05PrivateUserID, wellFormatUserName(newUsername), username05, false, done);
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Incorrect adminUserID should return 403", (done: Done) => {
|
it("Incorrect adminUserID should return 403", (done) => {
|
||||||
const newUsername = "New Username";
|
const newUsername = "New Username";
|
||||||
fetch(`${endpoint}?adminUserID=invalidAdminID&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername,"invalidAdminID")
|
||||||
method: "POST",
|
.then(res => {
|
||||||
})
|
|
||||||
.then(async res => {
|
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Admin should be able to change username", (done: Done) => {
|
it("Admin should be able to change username", (done) => {
|
||||||
const newUsername = "New Username";
|
const newUsername = "New Username";
|
||||||
fetch(`${endpoint}?adminUserID=${adminPrivateUserID}&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername, adminPrivateUserID)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
||||||
assert.strictEqual(usernameInfo.userName, newUsername, "username should be changed");
|
assert.strictEqual(usernameInfo.userName, newUsername, "username should be changed");
|
||||||
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
||||||
testUserNameChangelog(user06PrivateUserID, newUsername, username06, true, done);
|
testUserNameChangelog(user06PrivateUserID, newUsername, username06, true, done);
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Admin should be able to change locked username", (done: Done) => {
|
it("Admin should be able to change locked username", (done) => {
|
||||||
const newUsername = "New Username";
|
const newUsername = "New Username";
|
||||||
fetch(`${endpoint}?adminUserID=${adminPrivateUserID}&userID=${getHash(user07PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
postSetUserNameAdmin(getHash(user07PrivateUserID), newUsername, adminPrivateUserID)
|
||||||
method: "POST",
|
|
||||||
})
|
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
||||||
assert.strictEqual(usernameInfo.userName, newUsername, "Username should be changed");
|
assert.strictEqual(usernameInfo.userName, newUsername, "Username should be changed");
|
||||||
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
||||||
testUserNameChangelog(user07PrivateUserID, newUsername, username07, true, done);
|
testUserNameChangelog(user07PrivateUserID, newUsername, username07, true, done);
|
||||||
})
|
})
|
||||||
.catch(() => done(`couldn't call endpoint`));
|
.catch((err) => done(err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import { Category } from "../../src/types/segments.model";
|
import { Category } from "../../src/types/segments.model";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
describe("shadowBanUser", () => {
|
describe("shadowBanUser", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/shadowBanUser`;
|
|
||||||
const getShadowBan = (userID: string) => db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, [userID]);
|
const getShadowBan = (userID: string) => db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, [userID]);
|
||||||
const getShadowBanSegments = (userID: string, status: number) => db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, [userID, status]);
|
const getShadowBanSegments = (userID: string, status: number) => db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, [userID, status]);
|
||||||
const getShadowBanSegmentCategory = (userID: string, status: number): Promise<{shadowHidden: number, category: Category}[]> => db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, [userID, status]);
|
const getShadowBanSegmentCategory = (userID: string, status: number): Promise<{shadowHidden: number, category: Category}[]> => db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, [userID, status]);
|
||||||
|
|
||||||
|
const endpoint = "/api/shadowBanUser";
|
||||||
const VIPuserID = "shadow-ban-vip";
|
const VIPuserID = "shadow-ban-vip";
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
@@ -36,10 +34,15 @@ describe("shadowBanUser", () => {
|
|||||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]);
|
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to ban user and hide submissions", (done: Done) => {
|
it("Should be able to ban user and hide submissions", (done) => {
|
||||||
const userID = "shadowBanned";
|
const userID = "shadowBanned";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}`, {
|
client({
|
||||||
method: "POST"
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -52,10 +55,17 @@ describe("shadowBanUser", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to unban user without unhiding submissions", (done: Done) => {
|
it("Should be able to unban user without unhiding submissions", (done) => {
|
||||||
const userID = "shadowBanned";
|
const userID = "shadowBanned";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false&unHideOldSubmissions=false`, {
|
client({
|
||||||
method: "POST"
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
enabled: false,
|
||||||
|
unHideOldSubmissions: false,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -68,10 +78,16 @@ describe("shadowBanUser", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to ban user and hide submissions from only some categories", (done: Done) => {
|
it("Should be able to ban user and hide submissions from only some categories", (done) => {
|
||||||
const userID = "shadowBanned2";
|
const userID = "shadowBanned2";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&categories=["sponsor"]`, {
|
client({
|
||||||
method: "POST"
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
categories: `["sponsor"]`
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -85,10 +101,16 @@ describe("shadowBanUser", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to unban user and unhide submissions", (done: Done) => {
|
it("Should be able to unban user and unhide submissions", (done) => {
|
||||||
const userID = "shadowBanned2";
|
const userID = "shadowBanned2";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false`, {
|
client({
|
||||||
method: "POST"
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
enabled: false,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -101,10 +123,17 @@ describe("shadowBanUser", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to unban user and unhide some submissions", (done: Done) => {
|
it("Should be able to unban user and unhide some submissions", (done) => {
|
||||||
const userID = "shadowBanned3";
|
const userID = "shadowBanned3";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false&categories=["sponsor"]`, {
|
client({
|
||||||
method: "POST"
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
enabled: false,
|
||||||
|
categories: `["sponsor"]`
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
@@ -118,10 +147,18 @@ describe("shadowBanUser", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get 409 when re-shadowbanning user", (done: Done) => {
|
it("Should get 409 when re-shadowbanning user", (done) => {
|
||||||
const userID = "shadowBanned4";
|
const userID = "shadowBanned4";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=true&categories=["sponsor"]&unHideOldSubmissions=false`, {
|
client({
|
||||||
method: "POST"
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
enabled: true,
|
||||||
|
categories: `["sponsor"]`,
|
||||||
|
unHideOldSubmissions: false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 409);
|
assert.strictEqual(res.status, 409);
|
||||||
@@ -135,10 +172,18 @@ describe("shadowBanUser", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to re-shadowban user to hide old submissions", (done: Done) => {
|
it("Should be able to re-shadowban user to hide old submissions", (done) => {
|
||||||
const userID = "shadowBanned4";
|
const userID = "shadowBanned4";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=true&categories=["sponsor"]&unHideOldSubmissions=true`, {
|
client({
|
||||||
method: "POST"
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
enabled: true,
|
||||||
|
categories: `["sponsor"]`,
|
||||||
|
unHideOldSubmissions: true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { postJSON } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
describe("unBan", () => {
|
describe("unBan", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/shadowBanUser`;
|
const endpoint = "/api/shadowBanUser";
|
||||||
const VIPuser = "VIPUser-unBan";
|
const VIPuser = "VIPUser-unBan";
|
||||||
|
const postUnBan = (userID: string, adminUserID: string, enabled: boolean) => client({
|
||||||
|
url: endpoint,
|
||||||
|
method: "POST",
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID,
|
||||||
|
enabled
|
||||||
|
}
|
||||||
|
});
|
||||||
const videoIDUnBanCheck = (videoID: string, userID: string, status: number) => db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', [videoID, userID, status]);
|
const videoIDUnBanCheck = (videoID: string, userID: string, status: number) => db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', [videoID, userID, status]);
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertShadowBannedUserQuery = 'INSERT INTO "shadowBannedUsers" VALUES(?)';
|
const insertShadowBannedUserQuery = 'INSERT INTO "shadowBannedUsers" VALUES(?)';
|
||||||
@@ -30,9 +37,7 @@ 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) => {
|
||||||
const userID = "testMan-unBan";
|
const userID = "testMan-unBan";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
postUnBan(userID, VIPuser, false)
|
||||||
...postJSON
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await videoIDUnBanCheck("unBan-videoID-0", userID, 1);
|
const result = await videoIDUnBanCheck("unBan-videoID-0", userID, 1);
|
||||||
@@ -44,9 +49,7 @@ describe("unBan", () => {
|
|||||||
|
|
||||||
it("Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys", (done) => {
|
it("Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys", (done) => {
|
||||||
const userID = "testWoman-unBan";
|
const userID = "testWoman-unBan";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
postUnBan(userID, VIPuser, false)
|
||||||
...postJSON
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await videoIDUnBanCheck("unBan-videoID-1", userID, 1);
|
const result = await videoIDUnBanCheck("unBan-videoID-1", userID, 1);
|
||||||
@@ -58,9 +61,7 @@ describe("unBan", () => {
|
|||||||
|
|
||||||
it("Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys", (done) => {
|
it("Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys", (done) => {
|
||||||
const userID = "testEntity-unBan";
|
const userID = "testEntity-unBan";
|
||||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
postUnBan(userID, VIPuser, false)
|
||||||
...postJSON
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', [userID, 1]);
|
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', [userID, 1]);
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import fetch from "node-fetch";
|
|
||||||
import { config } from "../../src/config";
|
import { config } from "../../src/config";
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { getHash } from "../../src/utils/getHash";
|
import { getHash } from "../../src/utils/getHash";
|
||||||
import { ImportMock } from "ts-mock-imports";
|
import { ImportMock } from "ts-mock-imports";
|
||||||
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
|
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
|
||||||
import { YouTubeApiMock } from "../youtubeMock";
|
import { YouTubeApiMock } from "../youtubeMock";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
||||||
const sinonStub = mockManager.mock("listVideos");
|
const sinonStub = mockManager.mock("listVideos");
|
||||||
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
||||||
|
const vipUser = "VIPUser";
|
||||||
|
const randomID2 = "randomID2";
|
||||||
|
|
||||||
describe("voteOnSponsorTime", () => {
|
describe("voteOnSponsorTime", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
@@ -35,7 +35,7 @@ describe("voteOnSponsorTime", () => {
|
|||||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-9", getHash("randomID2"), 0, 50, "sponsor", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-9", getHash(randomID2), 0, 50, "sponsor", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", 0, 0]);
|
||||||
@@ -59,19 +59,38 @@ describe("voteOnSponsorTime", () => {
|
|||||||
await db.prepare("run", insertWarningQuery, [warnUser02Hash, (now - (warningExpireTime + 2000)), warnVip01Hash, 1]);
|
await db.prepare("run", insertWarningQuery, [warnUser02Hash, (now - (warningExpireTime + 2000)), warnVip01Hash, 1]);
|
||||||
|
|
||||||
|
|
||||||
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("VIPUser")]);
|
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(vipUser)]);
|
||||||
await db.prepare("run", 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)', [getHash("randomID4")]);
|
await db.prepare("run", 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)', [getHash("randomID4")]);
|
||||||
|
|
||||||
await db.prepare("run", 'INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES (?, ?, ?)', ["no-sponsor-segments-video", "someUser", "sponsor"]);
|
await db.prepare("run", 'INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES (?, ?, ?)', ["no-sponsor-segments-video", "someUser", "sponsor"]);
|
||||||
});
|
});
|
||||||
// constants
|
// constants
|
||||||
const endpoint = `${getbaseURL()}/api/voteOnSponsorTime`;
|
const endpoint = "/api/voteOnSponsorTime";
|
||||||
|
const postVote = (userID: string, UUID: string, type: number) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
UUID,
|
||||||
|
type
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const postVoteCategory = (userID: string, UUID: string, category: string) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
UUID,
|
||||||
|
category
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const getSegmentVotes = (UUID: string) => db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
const getSegmentVotes = (UUID: string) => db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||||
const getSegmentCategory = (UUID: string) => db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
const getSegmentCategory = (UUID: string) => db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||||
|
|
||||||
it("Should be able to upvote a segment", (done: Done) => {
|
it("Should be able to upvote a segment", (done) => {
|
||||||
const UUID = "vote-uuid-0";
|
const UUID = "vote-uuid-0";
|
||||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=1`)
|
postVote("randomID", UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -81,9 +100,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to downvote a segment", (done: Done) => {
|
it("Should be able to downvote a segment", (done) => {
|
||||||
const UUID = "vote-uuid-2";
|
const UUID = "vote-uuid-2";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=0`)
|
postVote(randomID2, UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -93,9 +112,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "vote-uuid-2";
|
const UUID = "vote-uuid-2";
|
||||||
fetch(`${endpoint}?userID=randomID3&UUID=${UUID}&type=0`)
|
postVote("randomID3", UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -105,75 +124,81 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
fetch(`${endpoint}?userID=randomID4&UUID=vote-uuid-1.6&type=0`)
|
const UUID = "vote-uuid-1.6";
|
||||||
|
postVote("randomID4", UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes("vote-uuid-1.6");
|
const row = await getSegmentVotes(UUID);
|
||||||
assert.strictEqual(row.votes, 10);
|
assert.strictEqual(row.votes, 10);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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) => {
|
||||||
fetch(`${endpoint}?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1`)
|
const UUID = "vote-uuid-1";
|
||||||
|
postVote("hasNotSubmittedID", UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes("vote-uuid-1");
|
const row = await getSegmentVotes(UUID);
|
||||||
assert.strictEqual(row.votes, 2);
|
assert.strictEqual(row.votes, 2);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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) => {
|
||||||
fetch(`${endpoint}?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0`)
|
const UUID = "vote-uuid-1.5";
|
||||||
|
postVote("hasNotSubmittedID", UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes("vote-uuid-1.5");
|
const row = await getSegmentVotes(UUID);
|
||||||
assert.strictEqual(row.votes, 10);
|
assert.strictEqual(row.votes, 10);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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) => {
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=vote-uuid-3&type=0`)
|
const UUID = "vote-uuid-3";
|
||||||
|
postVote(vipUser, UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes("vote-uuid-3");
|
const row = await getSegmentVotes(UUID);
|
||||||
assert.ok(row.votes <= -2);
|
assert.ok(row.votes <= -2);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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) => {
|
||||||
fetch(`${endpoint}?userID=own-submission-id&UUID=own-submission-uuid&type=0`)
|
const UUID = "own-submission-uuid";
|
||||||
|
postVote("own-submission-id", UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes("own-submission-uuid");
|
const row = await getSegmentVotes(UUID);
|
||||||
assert.ok(row.votes <= -2);
|
assert.ok(row.votes <= -2);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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) => {
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=not-own-submission-uuid&type=0`)
|
const UUID = "not-own-submission-uuid";
|
||||||
|
postVote(randomID2, UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes("not-own-submission-uuid");
|
const row = await getSegmentVotes(UUID);
|
||||||
assert.strictEqual(row.votes, 499);
|
assert.strictEqual(row.votes, 499);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "vote-uuid-4";
|
const UUID = "vote-uuid-4";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=intro`)
|
postVoteCategory(randomID2, UUID, "intro")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentCategory(UUID);
|
const row = await getSegmentCategory(UUID);
|
||||||
@@ -189,9 +214,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "incorrect-category";
|
const UUID = "incorrect-category";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=fakecategory`)
|
postVoteCategory(randomID2, UUID, "fakecategory")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
const row = await getSegmentCategory(UUID);
|
const row = await getSegmentCategory(UUID);
|
||||||
@@ -201,9 +226,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not able to change to highlight category", (done: Done) => {
|
it("Should not able to change to highlight category", (done) => {
|
||||||
const UUID = "incorrect-category";
|
const UUID = "incorrect-category";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=highlight`)
|
postVoteCategory(randomID2, UUID, "highlight")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
const row = await getSegmentCategory(UUID);
|
const row = await getSegmentCategory(UUID);
|
||||||
@@ -213,11 +238,11 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "vote-uuid-4";
|
const UUID = "vote-uuid-4";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=outro`)
|
postVoteCategory(randomID2, UUID, "outro")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (res.status === 200) {
|
assert.strictEqual(res.status, 200, "Status code should be 200");
|
||||||
const submissionRow = await getSegmentCategory(UUID);
|
const submissionRow = await getSegmentCategory(UUID);
|
||||||
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, [UUID]);
|
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, [UUID]);
|
||||||
let introVotes = 0;
|
let introVotes = 0;
|
||||||
@@ -234,18 +259,15 @@ describe("voteOnSponsorTime", () => {
|
|||||||
assert.strictEqual(outroVotes, 1);
|
assert.strictEqual(outroVotes, 1);
|
||||||
assert.strictEqual(sponsorVotes, 1);
|
assert.strictEqual(sponsorVotes, 1);
|
||||||
done();
|
done();
|
||||||
} else {
|
|
||||||
done(`Status code was ${res.status}`);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "incorrect-category-change";
|
const UUID = "incorrect-category-change";
|
||||||
const vote = (inputCat: string, assertCat: string, callback: Done) => {
|
const vote = (inputCat: string, assertCat: string, callback: Mocha.Done) => {
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=${inputCat}`)
|
postVoteCategory(randomID2, UUID, inputCat)
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const row = await getSegmentCategory(UUID);
|
const row = await getSegmentCategory(UUID);
|
||||||
assert.strictEqual(row.category, assertCat);
|
assert.strictEqual(row.category, assertCat);
|
||||||
@@ -259,9 +281,9 @@ 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) => {
|
||||||
const UUID = "vote-uuid-5";
|
const UUID = "vote-uuid-5";
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&category=outro`)
|
postVoteCategory(vipUser, UUID, "outro")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentCategory(UUID);
|
const row = await getSegmentCategory(UUID);
|
||||||
@@ -273,9 +295,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "vote-uuid-5_1";
|
const UUID = "vote-uuid-5_1";
|
||||||
fetch(`${endpoint}?userID=testman&UUID=${UUID}&category=outro`)
|
postVoteCategory("testman", UUID, "outro")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentCategory("vote-uuid-5");
|
const row = await getSegmentCategory("vote-uuid-5");
|
||||||
@@ -285,9 +307,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "invalid-uuid";
|
const UUID = "invalid-uuid";
|
||||||
fetch(`${endpoint}?userID=randomID3&UUID=${UUID}&category=intro`)
|
postVoteCategory("randomID3", UUID, "intro")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
@@ -295,9 +317,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "vote-uuid-5";
|
const UUID = "vote-uuid-5";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=1`)
|
postVote(randomID2, UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -307,9 +329,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Non-VIP should not be able to downvote "dead" submission', (done: Done) => {
|
it('Non-VIP should not be able to downvote "dead" submission', (done) => {
|
||||||
const UUID = "vote-uuid-5";
|
const UUID = "vote-uuid-5";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=0`)
|
postVote(randomID2, UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -319,9 +341,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "vote-uuid-5";
|
const UUID = "vote-uuid-5";
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
|
postVote(vipUser, UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -331,9 +353,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "warnvote-uuid-0";
|
const UUID = "warnvote-uuid-0";
|
||||||
fetch(`${endpoint}?userID=warn-voteuser01&UUID=${UUID}&type=1`)
|
postVote("warn-voteuser01", UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
@@ -341,9 +363,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Non-VIP should not be able to downvote on a segment with no-segments category", (done: Done) => {
|
it("Non-VIP should not be able to downvote on a segment with no-segments category", (done) => {
|
||||||
const UUID = "no-sponsor-segments-uuid-0";
|
const UUID = "no-sponsor-segments-uuid-0";
|
||||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=0`)
|
postVote("randomID", UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -353,9 +375,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Non-VIP should be able to upvote on a segment with no-segments category", (done: Done) => {
|
it("Non-VIP should be able to upvote on a segment with no-segments category", (done) => {
|
||||||
const UUID = "no-sponsor-segments-uuid-0";
|
const UUID = "no-sponsor-segments-uuid-0";
|
||||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=1`)
|
postVote("randomID", UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -365,9 +387,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.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) => {
|
||||||
const UUID = "no-sponsor-segments-uuid-0";
|
const UUID = "no-sponsor-segments-uuid-0";
|
||||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&category=outro`)
|
postVoteCategory("randomID", UUID, "outro")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentCategory(UUID);
|
const row = await getSegmentCategory(UUID);
|
||||||
@@ -377,9 +399,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("VIP upvote should lock segment", (done: Done) => {
|
it("VIP upvote should lock segment", (done) => {
|
||||||
const UUID = "segment-locking-uuid-1";
|
const UUID = "segment-locking-uuid-1";
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
|
postVote(vipUser, UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||||
@@ -389,9 +411,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("VIP downvote should unlock segment", (done: Done) => {
|
it("VIP downvote should unlock segment", (done) => {
|
||||||
const UUID = "segment-locking-uuid-1";
|
const UUID = "segment-locking-uuid-1";
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=0`)
|
postVote(vipUser, UUID, 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||||
@@ -401,9 +423,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("VIP upvote should unhide segment", (done: Done) => {
|
it("VIP upvote should unhide segment", (done) => {
|
||||||
const UUID = "segment-hidden-uuid-1";
|
const UUID = "segment-hidden-uuid-1";
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
|
postVote(vipUser, UUID, 1)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await db.prepare("get", `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
const row = await db.prepare("get", `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||||
@@ -413,9 +435,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to undo-vote a segment", (done: Done) => {
|
it("Should be able to undo-vote a segment", (done) => {
|
||||||
const UUID = "vote-uuid-2";
|
const UUID = "vote-uuid-2";
|
||||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=20`)
|
postVote(randomID2, UUID, 20)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await getSegmentVotes(UUID);
|
const row = await getSegmentVotes(UUID);
|
||||||
@@ -425,9 +447,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to vote with type 10", (done: Done) => {
|
it("Should not be able to vote with type 10", (done) => {
|
||||||
const UUID = "segment-locking-uuid-1";
|
const UUID = "segment-locking-uuid-1";
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=10`)
|
postVote(vipUser, UUID, 10)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
@@ -435,9 +457,9 @@ describe("voteOnSponsorTime", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to vote with type 11", (done: Done) => {
|
it("Should not be able to vote with type 11", (done) => {
|
||||||
const UUID = "segment-locking-uuid-1";
|
const UUID = "segment-locking-uuid-1";
|
||||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=11`)
|
postVote(vipUser, UUID, 11)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user