SponsorBlockServer/test/cases/oldGetSponsorTime.ts

71 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-07-12 08:43:46 +02:00
import fetch from "node-fetch";
import {db} from "../../src/databases/databases";
2021-08-03 06:19:37 +02:00
import {Done, getbaseURL, partialDeepEquals} from "../utils";
2021-07-12 08:43:46 +02:00
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
2020-10-17 20:56:54 +02:00
2021-07-12 08:43:46 +02:00
describe("getVideoSponsorTime (Old get method)", () => {
2021-06-22 00:59:56 +02:00
before(async () => {
2021-05-07 01:51:11 +02:00
const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
2021-07-12 08:43:46 +02:00
await db.prepare("run", insertSponsorTimes, ["old-testtesttest", 1, 11, 2, "uuid-0", "testman", 0, 50, "sponsor", 0, getHash("old-testtesttest", 1)]);
await db.prepare("run", insertSponsorTimes, ["old-testtesttest,test", 1, 11, 2, "uuid-1", "testman", 0, 50, "sponsor", 0, getHash("old-testtesttest,test", 1)]);
2020-10-17 20:56:54 +02:00
});
2021-07-12 08:43:46 +02:00
it("Should be able to get a time", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest`)
.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 return 404 if no segment found", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=notarealvideo`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
2021-07-12 08:43:46 +02:00
it("Should be possible to send unexpected query parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
})
.catch(() => done("couldn't callendpoint"));
2020-10-17 20:56:54 +02:00
});
2021-07-12 08:43:46 +02:00
it("Should be able send a comma in a query param", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest,test`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
2021-08-03 06:19:37 +02:00
const expected = {
UUIDs: ["uuid-1"],
};
assert.ok(partialDeepEquals(data, 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 get the correct time", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
2021-08-03 06:19:37 +02:00
const expected = {
sponsorTimes: [[1, 11]],
UUIDs: ["uuid-0"]
};
assert.ok(partialDeepEquals(data, expected));
2021-07-12 08:43:46 +02:00
done();
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
});