2021-07-12 08:43:46 +02:00
|
|
|
import fetch from "node-fetch";
|
|
|
|
import {config} from "../../src/config";
|
|
|
|
import {getHash} from "../../src/utils/getHash";
|
2021-09-17 02:44:12 +02:00
|
|
|
import {Done, getbaseURL, partialDeepEquals, postJSON} from "../utils";
|
2021-07-12 08:43:46 +02:00
|
|
|
import {db} from "../../src/databases/databases";
|
|
|
|
import {ImportMock} from "ts-mock-imports";
|
|
|
|
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
|
|
|
|
import {YouTubeApiMock} from "../youtubeMock";
|
|
|
|
import assert from "assert";
|
|
|
|
|
|
|
|
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
|
|
|
const sinonStub = mockManager.mock("listVideos");
|
2020-10-20 21:56:07 +02:00
|
|
|
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
2020-10-17 20:56:54 +02:00
|
|
|
|
2021-09-17 02:44:12 +02:00
|
|
|
// Constant and helpers
|
|
|
|
const submitUserOne = `PostSkipUser1${".".repeat(18)}`;
|
|
|
|
const submitUserTwo = `PostSkipUser2${".".repeat(18)}`;
|
|
|
|
const submitUserThree = `PostSkipUser3${".".repeat(18)}`;
|
|
|
|
|
|
|
|
const warnUser01 = "warn-user01-qwertyuiopasdfghjklzxcvbnm";
|
|
|
|
const warnUser01Hash = getHash(warnUser01);
|
|
|
|
const warnUser02 = "warn-user02-qwertyuiopasdfghjklzxcvbnm";
|
|
|
|
const warnUser02Hash = getHash(warnUser02);
|
|
|
|
const warnUser03 = "warn-user03-qwertyuiopasdfghjklzxcvbnm";
|
|
|
|
const warnUser03Hash = getHash(warnUser03);
|
|
|
|
const warnUser04 = "warn-user04-qwertyuiopasdfghjklzxcvbnm";
|
|
|
|
const warnUser04Hash = getHash(warnUser04);
|
|
|
|
|
|
|
|
const submitUserOneHash = getHash(submitUserOne);
|
|
|
|
const submitVIPuser = `VIPPostSkipUser${".".repeat(16)}`;
|
|
|
|
const warnVideoID = "dQw4w9WgXcF";
|
|
|
|
const badInputVideoID = "dQw4w9WgXcQ";
|
|
|
|
|
|
|
|
const queryDatabase = async (videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
|
|
|
const queryDatabaseActionType = async(videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
|
|
|
const queryDatabaseDuration = async (videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
|
|
|
|
|
|
|
const endpoint = `${getbaseURL()}/api/skipSegments`;
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
describe("postSkipSegments", () => {
|
2020-10-17 20:56:54 +02:00
|
|
|
before(() => {
|
2021-05-07 01:51:11 +02:00
|
|
|
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
2021-09-17 02:44:12 +02:00
|
|
|
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 1000, 0, "80percent-uuid-0", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]);
|
|
|
|
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 1001, 1005, 0, "80percent-uuid-1", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]);
|
|
|
|
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 5000, -2, "80percent-uuid-2", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]);
|
2020-10-17 20:56:54 +02:00
|
|
|
|
|
|
|
const now = Date.now();
|
2021-07-06 06:49:07 +02:00
|
|
|
const warnVip01Hash = getHash("warn-vip01-qwertyuiopasdfghjklzxcvbnm");
|
2021-07-12 08:43:46 +02:00
|
|
|
const reason01 = "Reason01";
|
|
|
|
const reason02 = "";
|
|
|
|
const reason03 = "Reason03";
|
|
|
|
const reason04 = "";
|
2020-10-17 20:56:54 +02:00
|
|
|
const MILLISECONDS_IN_HOUR = 3600000;
|
|
|
|
const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires;
|
2021-02-19 02:24:04 +01:00
|
|
|
|
2021-09-17 02:50:59 +02:00
|
|
|
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issuerUserID", "enabled", "reason", "issueTime") VALUES(?, ?, ?, ?, ?)';
|
2021-09-17 02:44:12 +02:00
|
|
|
// User 1
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, now]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 1000)]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 2000)]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 3601000)]);
|
|
|
|
// User 2
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, now]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, now]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, (now - (warningExpireTime + 1000))]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, (now - (warningExpireTime + 2000))]);
|
|
|
|
// User 3
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason03, now]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason03, (now - 1000)]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, (now - 2000)]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, (now - 3601000)]);
|
|
|
|
// User 4
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 0, reason04, now]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 0, reason04, (now - 1000)]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason04, (now - 2000)]);
|
|
|
|
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason04, (now - 3601000)]);
|
2021-05-07 01:51:11 +02:00
|
|
|
|
|
|
|
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
2021-09-17 02:44:12 +02:00
|
|
|
db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]);
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to submit a single time (Params method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXcR";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=2&endTime=10&userID=${submitUserOne}&category=sponsor`, {
|
|
|
|
method: "POST"
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabase(videoID);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 2,
|
|
|
|
endTime: 10,
|
|
|
|
category: "sponsor",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to submit a single time (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXcF";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-01-06 01:43:28 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabase(videoID);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
locked: 0,
|
|
|
|
category: "sponsor",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to submit a single time with an action type (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXcV";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-07-06 06:22:01 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-07-06 06:22:01 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
actionType: "mute"
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabaseActionType(videoID);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
category: "sponsor",
|
|
|
|
actionType: "mute",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-06 06:22:01 +02:00
|
|
|
});
|
|
|
|
|
2021-09-04 06:33:37 +02:00
|
|
|
it("Should not be able to submit an intro with mute action type (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXpQ";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-09-04 06:33:37 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-09-04 06:33:37 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "intro",
|
|
|
|
actionType: "mute"
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabaseActionType(videoID);
|
2021-09-04 06:33:37 +02:00
|
|
|
assert.strictEqual(row, undefined);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXZX";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-03-20 03:45:30 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-03-20 03:45:30 +01:00
|
|
|
videoDuration: 100,
|
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabaseDuration(videoID);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
category: "sponsor",
|
|
|
|
videoDuration: 4980,
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-03-20 03:45:30 +01:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
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) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXZH";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-03-27 00:13:52 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-06-03 04:34:38 +02:00
|
|
|
videoDuration: 4980.20,
|
2021-03-27 00:13:52 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [1, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabaseDuration(videoID);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 1,
|
|
|
|
endTime: 10,
|
|
|
|
locked: 0,
|
|
|
|
category: "sponsor",
|
|
|
|
videoDuration: 4980.20,
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-03-27 00:13:52 +01:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to submit a single time with a duration in the body (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "noDuration";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-03-20 03:45:30 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-03-20 03:45:30 +01:00
|
|
|
videoDuration: 100,
|
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabaseDuration(videoID);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
locked: 0,
|
|
|
|
category: "sponsor",
|
|
|
|
videoDuration: 100,
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-03-20 03:45:30 +01:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to submit with a new duration, and hide old submissions and remove segment locks", async () => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "noDuration";
|
2021-07-27 09:03:51 +02:00
|
|
|
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category")
|
2021-09-17 02:44:12 +02:00
|
|
|
VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor"]);
|
2021-03-30 01:16:18 +02:00
|
|
|
|
|
|
|
try {
|
2021-09-17 02:44:12 +02:00
|
|
|
const res = await fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-03-30 01:16:18 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-03-30 01:16:18 +02:00
|
|
|
videoDuration: 100,
|
|
|
|
segments: [{
|
|
|
|
segment: [1, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
});
|
2021-07-07 09:47:08 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const lockCategoriesRow = await db.prepare("get", `SELECT * from "lockCategories" WHERE videoID = ?`, [videoID]);
|
2021-07-27 09:03:51 +02:00
|
|
|
const videoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
|
2021-09-17 02:44:12 +02:00
|
|
|
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 0`, [videoID]);
|
2021-07-27 09:03:51 +02:00
|
|
|
const hiddenVideoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
|
2021-09-17 02:44:12 +02:00
|
|
|
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 1`, [videoID]);
|
2021-07-07 09:47:08 +02:00
|
|
|
assert.ok(!lockCategoriesRow);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 1,
|
|
|
|
endTime: 10,
|
|
|
|
locked: 0,
|
|
|
|
category: "sponsor",
|
|
|
|
videoDuration: 100,
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(videoRows[0], expected));
|
2021-07-07 09:47:08 +02:00
|
|
|
assert.strictEqual(videoRows.length, 1);
|
|
|
|
assert.strictEqual(hiddenVideoRows.length, 1);
|
2021-03-30 01:16:18 +02:00
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should still not be allowed if youtube thinks duration is 0", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID= "noDuration";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=10000&userID=${submitUserThree}&category=sponsor`, {
|
2021-07-12 08:43:46 +02:00
|
|
|
method: "POST",
|
2021-06-03 04:34:38 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 403);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-03 04:34:38 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to submit a single time under a different service (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXcG";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-03-20 02:31:16 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-03-20 02:31:16 +01:00
|
|
|
service: "PeerTube",
|
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "service" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
locked: 0,
|
|
|
|
category: "sponsor",
|
|
|
|
service: "PeerTube",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-03-20 02:31:16 +01:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("VIP submission should start locked", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "vipuserIDSubmission";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-02-19 02:24:04 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitVIPuser,
|
|
|
|
videoID,
|
2021-02-19 02:24:04 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabase(videoID);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
locked: 1,
|
|
|
|
category: "sponsor",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-02-19 02:24:04 +01:00
|
|
|
});
|
2021-07-12 08:43:46 +02:00
|
|
|
|
|
|
|
it("Should be able to submit multiple times (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "dQw4w9WgXcT";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-07-12 08:43:46 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [3, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [30, 60],
|
|
|
|
category: "intro",
|
|
|
|
}],
|
|
|
|
}),
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
2021-07-12 08:43:46 +02:00
|
|
|
const expected = [{
|
|
|
|
startTime: 3,
|
|
|
|
endTime: 10,
|
|
|
|
category: "sponsor"
|
|
|
|
}, {
|
|
|
|
startTime: 30,
|
|
|
|
endTime: 60,
|
|
|
|
category: "intro"
|
|
|
|
}];
|
|
|
|
assert.deepStrictEqual(rows, expected);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
}).timeout(5000);
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should allow multiple times if total is under 80% of video(JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "L_jWHffIx5E";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-07-12 08:43:46 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [3, 3000],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [3002, 3050],
|
|
|
|
category: "intro",
|
|
|
|
}, {
|
|
|
|
segment: [45, 100],
|
|
|
|
category: "interaction",
|
|
|
|
}, {
|
|
|
|
segment: [99, 170],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, [videoID]);
|
2021-07-12 08:43:46 +02:00
|
|
|
const expected = [{
|
|
|
|
startTime: 3,
|
|
|
|
endTime: 3000,
|
|
|
|
category: "sponsor"
|
|
|
|
}, {
|
|
|
|
startTime: 3002,
|
|
|
|
endTime: 3050,
|
|
|
|
category: "intro"
|
|
|
|
}, {
|
|
|
|
startTime: 45,
|
|
|
|
endTime: 100,
|
|
|
|
category: "interaction"
|
|
|
|
}, {
|
|
|
|
startTime: 99,
|
|
|
|
endTime: 170,
|
|
|
|
category: "sponsor"
|
|
|
|
}];
|
|
|
|
assert.deepStrictEqual(rows, expected);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
}).timeout(5000);
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should reject multiple times if total is over 80% of video (JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "n9rIGdXnSJc";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-07-12 08:43:46 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-07-12 08:43:46 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 2000],
|
|
|
|
category: "interaction",
|
|
|
|
}, {
|
|
|
|
segment: [3000, 4000],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [1500, 2750],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [4050, 4750],
|
|
|
|
category: "intro",
|
|
|
|
}],
|
|
|
|
}),
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 403);
|
2021-09-17 02:44:12 +02:00
|
|
|
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, [videoID]);
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.deepStrictEqual(rows, []);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
}).timeout(5000);
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "80percent_video";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-01-06 01:43:28 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [2000, 4000],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [1500, 2750],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [4050, 4750],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 403);
|
|
|
|
const expected = [{
|
|
|
|
category: "sponsor",
|
|
|
|
startTime: 2000,
|
|
|
|
endTime: 4000
|
|
|
|
}, {
|
|
|
|
category: "sponsor",
|
|
|
|
startTime: 1500,
|
|
|
|
endTime: 2750
|
|
|
|
}, {
|
|
|
|
category: "sponsor",
|
|
|
|
startTime: 4050,
|
|
|
|
endTime: 4750
|
|
|
|
}];
|
2021-09-17 02:44:12 +02:00
|
|
|
const rows = await queryDatabase(videoID);
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.notDeepStrictEqual(rows, expected);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
}).timeout(5000);
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be accepted if a non-sponsor is less than 1 second", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "qqwerty";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}&category=intro`, {
|
2021-07-12 08:43:46 +02:00
|
|
|
method: "POST",
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be rejected if segment starts and ends at the same time", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "qqwerty";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=90&endTime=90&userID=${submitUserTwo}&category=intro`, {
|
2021-07-12 08:43:46 +02:00
|
|
|
method: "POST",
|
2021-04-05 05:12:26 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-04-05 05:12:26 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be accepted if highlight segment starts and ends at the same time", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "qqwerty";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30&userID=${submitUserTwo}&category=poi_highlight`, {
|
2021-07-12 08:43:46 +02:00
|
|
|
method: "POST",
|
2021-04-05 05:12:26 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-04-05 05:12:26 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be rejected if highlight segment doesn't start and end at the same time", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "qqwerty";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}&category=poi_highlight`, {
|
2021-07-12 08:43:46 +02:00
|
|
|
method: "POST",
|
2021-04-05 05:12:26 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-04-05 05:12:26 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be rejected if a sponsor is less than 1 second", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "qqwerty";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}`, {
|
2021-07-12 08:43:46 +02:00
|
|
|
method: "POST",
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be rejected if over 80% of the video", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "qqwerty";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=1000000&userID=${submitUserTwo}&category=sponsor`, {
|
|
|
|
method: "POST",
|
|
|
|
})
|
|
|
|
.then( async res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 403);
|
2021-09-17 02:44:12 +02:00
|
|
|
console.log(res.text());
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Should be rejected if NB's predicted probability is <70%.", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "LevkAjUE6d4";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=40&endTime=60&userID=${submitUserTwo}&category=sponsor`, {
|
|
|
|
method: "POST",
|
|
|
|
})
|
|
|
|
.then(async res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
console.log(res.text());
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be rejected with custom message if user has to many active warnings", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: warnUser01,
|
|
|
|
videoID: warnVideoID,
|
2021-01-06 01:43:28 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 403);
|
|
|
|
const errorMessage = await res.text();
|
2021-07-22 23:50:39 +02:00
|
|
|
const reason = "Reason01";
|
2021-07-25 20:34:55 +02:00
|
|
|
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. "
|
2021-08-29 20:58:12 +02:00
|
|
|
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
|
2021-09-17 02:44:12 +02:00
|
|
|
+ `Your userID is ${warnUser01Hash}.\n\nWarning reason: '${reason}'`;
|
2021-07-25 20:34:55 +02:00
|
|
|
|
2021-07-22 23:50:39 +02:00
|
|
|
assert.strictEqual(errorMessage, expected);
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be accepted if user has some active warnings", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: warnUser02,
|
|
|
|
videoID: warnVideoID,
|
2021-07-12 08:43:46 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [50, 60],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
2021-01-24 18:45:13 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
done(); // success
|
|
|
|
} else {
|
|
|
|
const body = await res.text();
|
2021-07-13 21:55:03 +02:00
|
|
|
done(`Status code was ${res.status} ${body}`);
|
2021-07-12 08:43:46 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-01-24 18:45:13 +01:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be accepted if user has some warnings removed", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-24 18:45:13 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: warnUser03,
|
|
|
|
videoID: warnVideoID,
|
2021-07-12 08:43:46 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [53, 60],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
done(); // success
|
|
|
|
} else {
|
|
|
|
const body = await res.text();
|
2021-07-13 21:55:03 +02:00
|
|
|
done(`Status code was ${res.status} ${body}`);
|
2021-07-12 08:43:46 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should return 400 for missing params (Params method)", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(`${endpoint}?startTime=9&endTime=10&userID=${submitUserOne}`, {
|
2021-07-12 08:43:46 +02:00
|
|
|
method: "POST",
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
if (res.status === 400) done();
|
|
|
|
else done(true);
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be rejected with default message if user has to many active warnings", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-07-04 04:45:13 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: warnUser01,
|
|
|
|
videoID: warnVideoID,
|
2021-07-04 04:45:13 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 403);
|
|
|
|
const errorMessage = await res.text();
|
|
|
|
assert.notStrictEqual(errorMessage, "");
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-04 04:45:13 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should return 400 for missing params (JSON method) 1", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
2021-01-06 01:43:28 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [9, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [31, 60],
|
|
|
|
category: "intro",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should return 400 for missing params (JSON method) 2", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID: badInputVideoID,
|
2021-01-06 01:43:28 +01:00
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should return 400 for missing params (JSON method) 3", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID: badInputVideoID,
|
2021-01-06 01:43:28 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [0],
|
|
|
|
category: "sponsor",
|
|
|
|
}, {
|
|
|
|
segment: [31, 60],
|
|
|
|
category: "intro",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should return 400 for missing params (JSON method) 4", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID: badInputVideoID,
|
2021-01-06 01:43:28 +01:00
|
|
|
segments: [{
|
|
|
|
segment: [9, 10],
|
|
|
|
}, {
|
|
|
|
segment: [31, 60],
|
|
|
|
category: "intro",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should return 400 for missing params (JSON method) 5", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-01-06 01:43:28 +01:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID: badInputVideoID,
|
2021-01-06 01:43:28 +01:00
|
|
|
}),
|
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
2021-07-27 09:03:51 +02:00
|
|
|
|
|
|
|
it("Should return 403 and custom reason for submiting in lockedCategory", async () => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "lockedVideo";
|
2021-07-27 09:03:51 +02:00
|
|
|
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
|
2021-09-17 02:44:12 +02:00
|
|
|
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor", "Custom Reason"]);
|
2021-07-27 09:03:51 +02:00
|
|
|
|
|
|
|
try {
|
2021-09-17 02:44:12 +02:00
|
|
|
const res = await fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-07-27 09:03:51 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-07-27 09:03:51 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [1, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 403);
|
|
|
|
assert.match(await res.text(), /Lock reason: /);
|
|
|
|
assert.match(await res.text(), /Custom Reason/);
|
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should return 403 for submiting in lockedCategory", async () => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "lockedVideo1";
|
2021-07-27 09:03:51 +02:00
|
|
|
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
|
2021-09-17 02:44:12 +02:00
|
|
|
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "intro", ""]);
|
2021-07-27 09:03:51 +02:00
|
|
|
|
|
|
|
try {
|
2021-09-17 02:44:12 +02:00
|
|
|
const res = await fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-07-27 09:03:51 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-07-27 09:03:51 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [1, 10],
|
|
|
|
category: "intro",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 403);
|
|
|
|
assert.doesNotMatch(await res.text(), /Lock reason: /);
|
|
|
|
assert.doesNotMatch(await res.text(), /Custom Reason/);
|
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}).timeout(5000);
|
2021-07-30 08:44:37 +02:00
|
|
|
|
|
|
|
it("Should be able to submit with custom user-agent 1", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
2021-07-30 08:44:37 +02:00
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
2021-08-01 08:57:02 +02:00
|
|
|
"User-Agent": "com.google.android.youtube/5.0"
|
2021-07-30 08:44:37 +02:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
2021-07-30 08:44:37 +02:00
|
|
|
videoID: "userAgent-1",
|
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "userAgent" FROM "sponsorTimes" WHERE "videoID" = ?`, ["userAgent-1"]);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
userAgent: "Vanced/5.0",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-30 08:44:37 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
|
|
|
|
2021-08-01 08:57:02 +02:00
|
|
|
it("Should be able to submit with empty user-agent", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
2021-07-30 08:44:37 +02:00
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
2021-08-01 08:57:02 +02:00
|
|
|
"User-Agent": ""
|
2021-07-30 08:44:37 +02:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
2021-08-01 08:57:02 +02:00
|
|
|
videoID: "userAgent-3",
|
2021-07-30 08:44:37 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-08-01 08:57:02 +02:00
|
|
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "userAgent" FROM "sponsorTimes" WHERE "videoID" = ?`, ["userAgent-3"]);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
userAgent: "",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-30 08:44:37 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
|
|
|
|
2021-08-01 08:57:02 +02:00
|
|
|
it("Should be able to submit with custom userAgent in body", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
fetch(endpoint, {
|
2021-07-30 08:44:37 +02:00
|
|
|
method: "POST",
|
|
|
|
headers: {
|
2021-08-01 08:57:02 +02:00
|
|
|
"Content-Type": "application/json"
|
2021-07-30 08:44:37 +02:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
2021-08-01 08:57:02 +02:00
|
|
|
videoID: "userAgent-4",
|
2021-07-30 08:44:37 +02:00
|
|
|
segments: [{
|
|
|
|
segment: [0, 10],
|
|
|
|
category: "sponsor",
|
|
|
|
}],
|
2021-08-01 08:57:02 +02:00
|
|
|
userAgent: "MeaBot/5.0"
|
2021-07-30 08:44:37 +02:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-08-01 08:57:02 +02:00
|
|
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "userAgent" FROM "sponsorTimes" WHERE "videoID" = ?`, ["userAgent-4"]);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0,
|
|
|
|
endTime: 10,
|
|
|
|
userAgent: "MeaBot/5.0",
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-30 08:44:37 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
2021-08-11 05:12:20 +02:00
|
|
|
|
|
|
|
it("Should be able to submit with commas in timestamps", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "commas-1";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-08-11 05:12:20 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-08-11 05:12:20 +02:00
|
|
|
segments: [{
|
|
|
|
segment: ["0,2", "10,392"],
|
|
|
|
category: "sponsor",
|
|
|
|
}]
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-17 02:44:12 +02:00
|
|
|
const row = await queryDatabase(videoID);
|
2021-08-11 05:12:20 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 0.2,
|
|
|
|
endTime: 10.392
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
2021-08-27 22:44:29 +02:00
|
|
|
|
|
|
|
it("Should be rejected if a POI is at less than 1 second", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "qqwerty";
|
|
|
|
fetch(`${endpoint}?videoID=${videoID}&startTime=0.5&endTime=0.5&category=poi_highlight&userID=${submitUserTwo}`, {
|
2021-08-27 22:44:29 +02:00
|
|
|
method: "POST",
|
|
|
|
})
|
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
2021-08-28 07:39:52 +02:00
|
|
|
|
2021-08-25 01:12:58 +02:00
|
|
|
it("Should not be able to submit with colons in timestamps", (done: Done) => {
|
2021-09-17 02:44:12 +02:00
|
|
|
const videoID = "colon-1";
|
|
|
|
fetch(endpoint, {
|
|
|
|
...postJSON,
|
2021-08-25 01:12:58 +02:00
|
|
|
body: JSON.stringify({
|
2021-09-17 02:44:12 +02:00
|
|
|
userID: submitUserOne,
|
|
|
|
videoID,
|
2021-08-25 01:12:58 +02:00
|
|
|
segments: [{
|
|
|
|
segment: ["0:2.000", "3:10.392"],
|
|
|
|
category: "sponsor",
|
|
|
|
}]
|
|
|
|
}),
|
|
|
|
})
|
2021-08-28 07:39:52 +02:00
|
|
|
.then(res => {
|
2021-08-25 01:12:58 +02:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|