remaining tests

This commit is contained in:
Michael C
2021-09-22 23:18:31 -04:00
parent a028eaa41a
commit 4e50f0ab4b
9 changed files with 743 additions and 762 deletions

View File

@@ -1,13 +1,12 @@
import fetch from "node-fetch";
import { Done } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { db } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import assert from "assert";
import { client } from "../utils/httpClient";
const VIPUser = "clearCacheVIP";
const regularUser = "regular-user";
const endpoint = `${getbaseURL()}/api/clearCache`;
const endpoint = "/api/clearCache";
const postClearCache = (userID: string, videoID: string) => client({ method: "post", url: endpoint, params: { userID, videoID } });
describe("postClearCache", () => {
before(async () => {
@@ -16,10 +15,8 @@ describe("postClearCache", () => {
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(`${endpoint}?userID=${VIPUser}&videoID=clear-test`, {
method: "POST"
})
it("Should be able to clear cache for existing video", (done) => {
postClearCache(VIPUser, "clear-test")
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -27,10 +24,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should be able to clear cache for nonexistent video", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}&videoID=dne-video`, {
method: "POST"
})
it("Should be able to clear cache for nonexistent video", (done) => {
postClearCache(VIPUser, "dne-video")
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -38,10 +33,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should get 403 as non-vip", (done: Done) => {
fetch(`${endpoint}?userID=${regularUser}&videoID=clear-tes`, {
method: "POST"
})
it("Should get 403 as non-vip", (done) => {
postClearCache(regularUser, "clear-test")
.then(async res => {
assert.strictEqual(res.status, 403);
done();
@@ -49,10 +42,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should give 400 with missing videoID", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}`, {
method: "POST"
})
it("Should give 400 with missing videoID", (done) => {
client.post(endpoint, { params: { userID: VIPUser } })
.then(async res => {
assert.strictEqual(res.status, 400);
done();
@@ -60,10 +51,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should give 400 with missing userID", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}`, {
method: "POST"
})
it("Should give 400 with missing userID", (done) => {
client.post(endpoint, { params: { videoID: "clear-test" } })
.then(async res => {
assert.strictEqual(res.status, 400);
done();