SponsorBlockServer/test/cases/oldGetSponsorTime.ts

70 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 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-09-05 01:23:43 +02:00
const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime0", 1, 11, 2, "oldGetSponsorTime00", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]);
await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime1,test", 1, 11, 2, "oldGetSponsorTime01", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]);
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) => {
2021-09-05 01:23:43 +02:00
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0`)
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 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) => {
2021-09-05 01:23:43 +02:00
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0&fakeparam=hello`)
2021-07-12 08:43:46 +02:00
.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) => {
2021-09-05 01:23:43 +02:00
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime1,test`)
2021-07-12 08:43:46 +02:00
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
2021-08-03 06:19:37 +02:00
const expected = {
2021-09-05 01:23:43 +02:00
UUIDs: ["oldGetSponsorTime01"],
2021-08-03 06:19:37 +02:00
};
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) => {
2021-09-05 01:23:43 +02:00
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0`)
2021-07-12 08:43:46 +02:00
.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]],
2021-09-05 01:23:43 +02:00
UUIDs: ["oldGetSponsorTime00"]
2021-08-03 06:19:37 +02:00
};
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
});
});