everything to postClearCache

This commit is contained in:
Michael C
2021-09-22 17:50:06 -04:00
parent 94e1e8c377
commit c779c2c19e
21 changed files with 750 additions and 860 deletions

View File

@@ -1,21 +1,20 @@
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 { client } from "../utils/httpClient";
import assert from "assert";
const endpoint = `${getbaseURL()}/api/isUserVIP`;
const VIPUser = "isUserVIPVIP";
const normalUser = "isUserVIPNormal";
const endpoint = "/api/isUserVIP";
const vipUserRequest = (userID: string) => client.get(endpoint, { params: { userID }});
describe("getIsUserVIP", () => {
before(() => {
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(VIPUser)]);
});
it("Should be able to get a 200", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}`)
it("Should be able to get a 200", (done) => {
vipUserRequest(VIPUser)
.then(res => {
assert.strictEqual(res.status, 200, "response should be 200");
done();
@@ -24,8 +23,8 @@ describe("getIsUserVIP", () => {
});
it("Should get a 400 if no userID", (done: Done) => {
fetch(endpoint)
it("Should get a 400 if no userID", (done) => {
client.get(endpoint)
.then(res => {
assert.strictEqual(res.status, 400, "response should be 400");
done();
@@ -33,23 +32,21 @@ describe("getIsUserVIP", () => {
.catch(err => done(err));
});
it("Should say a VIP is a VIP", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}`)
.then(async res => {
it("Should say a VIP is a VIP", (done) => {
vipUserRequest(VIPUser)
.then(res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.vip, true);
assert.strictEqual(res.data.vip, true);
done();
})
.catch(err => done(err));
});
it("Should say a normal user is not a VIP", (done: Done) => {
fetch(`${endpoint}?userID=${normalUser}`)
.then(async res => {
it("Should say a normal user is not a VIP", (done) => {
vipUserRequest(normalUser)
.then(res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.vip, false);
assert.strictEqual(res.data.vip, false);
done();
})
.catch(err => done(err));