mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 14:07:09 +03:00
everything to postClearCache
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import fetch from "node-fetch";
|
||||
import {db} from "../../src/databases/databases";
|
||||
import { Done } from "../utils/utils";
|
||||
import { getbaseURL } from "../utils/getBaseURL";
|
||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||
import assert from "assert";
|
||||
import { client } from "../utils/httpClient";
|
||||
|
||||
const ENOENTID = "0".repeat(64);
|
||||
const upvotedID = `a${"0".repeat(63)}`;
|
||||
@@ -27,8 +25,10 @@ const userAgents = {
|
||||
blank: ""
|
||||
};
|
||||
|
||||
const endpoint = "/api/segmentInfo";
|
||||
const singleUUIDLookup = (UUID: string) => client.get(endpoint, { params: { UUID } });
|
||||
|
||||
describe("getSegmentInfo", () => {
|
||||
const endpoint = `${getbaseURL()}/api/segmentInfo`;
|
||||
before(async () => {
|
||||
const insertQuery = `INSERT INTO
|
||||
"sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked",
|
||||
@@ -49,154 +49,146 @@ describe("getSegmentInfo", () => {
|
||||
await db.prepare("run", insertQuery, ["segmentInfoFiller", 5, 6, 1, 0, fillerID5, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||
});
|
||||
|
||||
it("Should be able to retreive upvoted segment", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${upvotedID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive upvoted segment", (done) => {
|
||||
singleUUIDLookup(upvotedID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoUpvoted",
|
||||
votes: 2,
|
||||
userAgent: userAgents.vanced,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive downvoted segment", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${downvotedID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive downvoted segment", (done) => {
|
||||
singleUUIDLookup(downvotedID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoDownvoted",
|
||||
votes: -2,
|
||||
userAgent: userAgents.meabot,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive locked up segment", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${lockedupID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive locked up segment", (done) => {
|
||||
singleUUIDLookup(lockedupID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoLockedup",
|
||||
locked: 1,
|
||||
votes: 2,
|
||||
userAgent: userAgents.mpv,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive infinite vote segment", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${infvotesID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive infinite vote segment", (done) => {
|
||||
singleUUIDLookup(infvotesID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoInfvotes",
|
||||
votes: 100000,
|
||||
userAgent: userAgents.nodesb,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive shadowhidden segment", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${shadowhiddenID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive shadowhidden segment", (done) => {
|
||||
singleUUIDLookup(shadowhiddenID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoShadowhidden",
|
||||
shadowHidden: 1,
|
||||
userAgent: userAgents.blank,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive locked down segment", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${lockeddownID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive locked down segment", (done) => {
|
||||
singleUUIDLookup(lockeddownID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoLockedown",
|
||||
locked: 1,
|
||||
votes: -2,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive hidden segment", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${hiddenID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive hidden segment", (done) => {
|
||||
singleUUIDLookup(hiddenID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoHidden",
|
||||
hidden: 1,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive segment with old ID", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${oldID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive segment with old ID", (done) => {
|
||||
singleUUIDLookup(oldID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoOldID",
|
||||
votes: 1,
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive single segment in array", (done: Done) => {
|
||||
fetch(`${endpoint}?UUIDs=["${upvotedID}"]`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive single segment in array", (done) => {
|
||||
client.get(endpoint, { params: { UUIDs: `["${upvotedID}"]` }})
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const data = res.data;
|
||||
const expected = [{
|
||||
videoID: "segmentInfoUpvoted",
|
||||
votes: 2,
|
||||
}];
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive multiple segments in array", (done: Done) => {
|
||||
fetch(`${endpoint}?UUIDs=["${upvotedID}", "${downvotedID}"]`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive multiple segments in array", (done) => {
|
||||
client.get(endpoint, { params: { UUIDs: `["${upvotedID}", "${downvotedID}"]` }})
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const data = res.data;
|
||||
const expected = [{
|
||||
videoID: "segmentInfoUpvoted",
|
||||
votes: 2,
|
||||
@@ -211,11 +203,11 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${upvotedID}&fakeparam=hello&category=sponsor`)
|
||||
.then(async res => {
|
||||
it("Should be possible to send unexpected query parameters", (done) => {
|
||||
client.get(endpoint, { params: { UUID: upvotedID, fakeparam: "hello", category: "sponsor" }})
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const data = res.data;
|
||||
const expected = [{
|
||||
videoID: "segmentInfoUpvoted",
|
||||
votes: 2,
|
||||
@@ -226,8 +218,8 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should return 400 if array passed to UUID", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=["${upvotedID}", "${downvotedID}"]`)
|
||||
it("Should return 400 if array passed to UUID", (done) => {
|
||||
client.get(`${endpoint}?UUID=["${upvotedID}", "${downvotedID}"]`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -235,8 +227,8 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should return 400 if bad array passed to UUIDs", (done: Done) => {
|
||||
fetch(`${endpoint}?UUIDs=[not-quoted,not-quoted]`)
|
||||
it("Should return 400 if bad array passed to UUIDs", (done) => {
|
||||
client.get(`${endpoint}?UUIDs=[not-quoted,not-quoted]`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -244,8 +236,8 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should return 400 if bad UUID passed", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=notarealuuid`)
|
||||
it("Should return 400 if bad UUID passed", (done) => {
|
||||
client.get(`${endpoint}?UUID=notarealuuid`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -253,8 +245,8 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should return 400 if bad UUIDs passed in array", (done: Done) => {
|
||||
fetch(`${endpoint}?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
|
||||
it("Should return 400 if bad UUIDs passed in array", (done) => {
|
||||
client.get(`${endpoint}?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -262,11 +254,11 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should return good UUID when mixed with bad UUIDs", (done: Done) => {
|
||||
fetch(`${endpoint}?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
|
||||
.then(async res => {
|
||||
it("Should return good UUID when mixed with bad UUIDs", (done) => {
|
||||
client.get(`${endpoint}?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const data = res.data;
|
||||
const expected = [{
|
||||
videoID: "segmentInfoUpvoted",
|
||||
votes: 2,
|
||||
@@ -278,13 +270,13 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should cut off array at 10", function(done: Done) {
|
||||
it("Should cut off array at 10", function(done) {
|
||||
this.timeout(10000);
|
||||
const filledIDArray = `["${upvotedID}", "${downvotedID}", "${lockedupID}", "${shadowhiddenID}", "${lockeddownID}", "${hiddenID}", "${fillerID1}", "${fillerID2}", "${fillerID3}", "${fillerID4}", "${fillerID5}"]`;
|
||||
fetch(`${endpoint}?UUIDs=${filledIDArray}`)
|
||||
.then(async res => {
|
||||
client.get(endpoint, { params: { UUIDs: filledIDArray }})
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const data = res.data;
|
||||
assert.strictEqual(data.length, 10);
|
||||
assert.strictEqual(data[0].videoID, "segmentInfoUpvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
@@ -295,19 +287,18 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should not duplicate reponses", (done: Done) => {
|
||||
fetch(`${endpoint}?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
|
||||
.then(async res => {
|
||||
it("Should not duplicate reponses", (done) => {
|
||||
client.get(`${endpoint}?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(res.data.length, 2);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should return 400 if UUID not found", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${ENOENTID}`)
|
||||
it("Should return 400 if UUID not found", (done) => {
|
||||
client.get(endpoint, { params: { UUID: ENOENTID }})
|
||||
.then(res => {
|
||||
if (res.status !== 400) done(`non 400 response code: ${res.status}`);
|
||||
else done(); // pass
|
||||
@@ -315,11 +306,11 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to retreive multiple segments with multiple parameters", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${upvotedID}&UUID=${downvotedID}`)
|
||||
.then(async res => {
|
||||
it("Should be able to retreive multiple segments with multiple parameters", (done) => {
|
||||
client.get(`${endpoint}?UUID=${upvotedID}&UUID=${downvotedID}`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const data = res.data;
|
||||
const expected = [{
|
||||
videoID: "segmentInfoUpvoted",
|
||||
votes: 2,
|
||||
@@ -334,16 +325,15 @@ describe("getSegmentInfo", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should not parse repeated UUID if UUIDs present", (done: Done) => {
|
||||
fetch(`${endpoint}?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
|
||||
.then(async res => {
|
||||
it("Should not parse repeated UUID if UUIDs present", (done) => {
|
||||
client.get(`${endpoint}?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "segmentInfoUpvoted",
|
||||
votes: 2
|
||||
}];
|
||||
assert.ok(partialDeepEquals(data, expected));
|
||||
assert.ok(partialDeepEquals(res.data, expected));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
|
||||
Reference in New Issue
Block a user