everything up to purgeAllSegments

This commit is contained in:
Michael C
2021-09-04 19:23:43 -04:00
parent 1823a91d54
commit 6e55f9d979
15 changed files with 320 additions and 308 deletions

View File

@@ -4,16 +4,19 @@ import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
const VIPUser = "clearCacheVIP";
const regularUser = "regular-user";
describe("postClearCache", () => {
before(async () => {
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('${getHash("clearing-vip")}')`);
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES';
await db.prepare("run", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0, '" + getHash("clear-test", 1) + "')`);
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('${getHash(VIPUser)}')`);
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden") VALUES';
await db.prepare("run", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0)`);
});
it("Should be able to clear cache for existing video", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip&videoID=clear-test`, {
}/api/clearCache?userID=${VIPUser}&videoID=clear-test`, {
method: "POST"
})
.then(res => {
@@ -25,7 +28,7 @@ describe("postClearCache", () => {
it("Should be able to clear cache for nonexistent video", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip&videoID=dne-video`, {
}/api/clearCache?userID=${VIPUser}&videoID=dne-video`, {
method: "POST"
})
.then(res => {
@@ -37,7 +40,7 @@ describe("postClearCache", () => {
it("Should get 403 as non-vip", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=regular-user&videoID=clear-tes`, {
}/api/clearCache?userID=${regularUser}&videoID=clear-tes`, {
method: "POST"
})
.then(async res => {
@@ -49,7 +52,7 @@ describe("postClearCache", () => {
it("Should give 400 with missing videoID", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip`, {
}/api/clearCache?userID=${VIPUser}`, {
method: "POST"
})
.then(async res => {
@@ -61,7 +64,7 @@ describe("postClearCache", () => {
it("Should give 400 with missing userID", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip`, {
}/api/clearCache?userID=${VIPUser}`, {
method: "POST"
})
.then(async res => {