2021-07-12 08:43:46 +02:00
|
|
|
import fetch from "node-fetch";
|
|
|
|
import {Done, getbaseURL} from "../utils";
|
|
|
|
import {db} from "../../src/databases/databases";
|
|
|
|
import {getHash} from "../../src/utils/getHash";
|
|
|
|
import assert from "assert";
|
2021-06-18 23:46:18 +02:00
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
describe("postClearCache", () => {
|
2021-06-18 23:46:18 +02:00
|
|
|
before(async () => {
|
2021-07-12 08:43:46 +02:00
|
|
|
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('${getHash("clearing-vip")}')`);
|
2021-07-04 07:34:31 +02:00
|
|
|
const startOfQuery = '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", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0, '" + getHash("clear-test", 1) + "')`);
|
2021-06-18 23:46:18 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to clear cache for existing video", (done: Done) => {
|
|
|
|
fetch(`${getbaseURL()
|
|
|
|
}/api/clearCache?userID=clearing-vip&videoID=clear-test`, {
|
|
|
|
method: "POST"
|
2021-06-18 23:46:18 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-18 23:46:18 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should be able to clear cache for nonexistent video", (done: Done) => {
|
|
|
|
fetch(`${getbaseURL()
|
|
|
|
}/api/clearCache?userID=clearing-vip&videoID=dne-video`, {
|
|
|
|
method: "POST"
|
2021-06-18 23:46:18 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-18 23:46:18 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should get 403 as non-vip", (done: Done) => {
|
|
|
|
fetch(`${getbaseURL()
|
|
|
|
}/api/clearCache?userID=regular-user&videoID=clear-tes`, {
|
|
|
|
method: "POST"
|
2021-06-18 23:46:18 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 403);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-18 23:46:18 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should give 400 with missing videoID", (done: Done) => {
|
|
|
|
fetch(`${getbaseURL()
|
|
|
|
}/api/clearCache?userID=clearing-vip`, {
|
|
|
|
method: "POST"
|
2021-06-18 23:46:18 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-18 23:46:18 +02:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
it("Should give 400 with missing userID", (done: Done) => {
|
|
|
|
fetch(`${getbaseURL()
|
|
|
|
}/api/clearCache?userID=clearing-vip`, {
|
|
|
|
method: "POST"
|
2021-06-18 23:46:18 +02:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-18 23:46:18 +02:00
|
|
|
});
|
|
|
|
});
|