SponsorBlockServer/test/cases/oldGetSponsorTime.ts

71 lines
2.7 KiB
TypeScript
Raw Normal View History

2021-09-23 00:52:35 +02:00
import { db } from "../../src/databases/databases";
import { partialDeepEquals } from "../utils/partialDeepEquals";
2021-07-12 08:43:46 +02:00
import assert from "assert";
2021-09-22 23:50:06 +02:00
import { client } from "../utils/httpClient";
2020-10-17 20:56:54 +02:00
2021-09-22 23:50:06 +02:00
const endpoint = "/api/getVideoSponsorTimes";
const getOldSponsorTime = (videoID: string) => client.get(endpoint, { params: { videoID } });
2021-09-17 05:59:19 +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-09-22 23:50:06 +02:00
it("Should be able to get a time", (done) => {
getOldSponsorTime("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-09-22 23:50:06 +02:00
it("Should return 404 if no segment found", (done) => {
getOldSponsorTime("notarealvideo")
2021-07-12 08:43:46 +02:00
.then(res => {
assert.strictEqual(res.status, 404);
done();
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
2021-09-22 23:50:06 +02:00
it("Should be possible to send unexpected query parameters", (done) => {
2021-09-23 00:52:35 +02:00
client.get(endpoint, { params: { 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-09-22 23:50:06 +02:00
it("Should be able send a comma in a query param", (done) => {
getOldSponsorTime("oldGetSponsorTime1,test")
.then(res => {
2021-07-12 08:43:46 +02:00
assert.strictEqual(res.status, 200);
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
};
2021-09-22 23:50:06 +02:00
assert.ok(partialDeepEquals(res.data, expected));
2021-07-12 08:43:46 +02:00
done();
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
2021-09-22 23:50:06 +02:00
it("Should be able to get the correct time", (done) => {
getOldSponsorTime("oldGetSponsorTime0")
.then(res => {
2021-07-12 08:43:46 +02:00
assert.strictEqual(res.status, 200);
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
};
2021-09-22 23:50:06 +02:00
assert.ok(partialDeepEquals(res.data, expected));
2021-07-12 08:43:46 +02:00
done();
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
});