SponsorBlockServer/test/cases/getIsUserVIP.ts

53 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-07-12 08:43:46 +02:00
import fetch from "node-fetch";
import {getbaseURL, Done} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
2020-10-17 20:56:54 +02:00
2021-07-12 08:43:46 +02:00
describe("getIsUserVIP", () => {
2021-03-02 03:37:35 +01:00
before((done: Done) => {
2021-05-07 01:51:11 +02:00
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("supertestman")]).then(done);
2020-10-17 20:56:54 +02:00
});
2021-07-12 08:43:46 +02:00
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=supertestman`)
.then(res => {
assert.strictEqual(res.status, 200, "response should be 200");
done();
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
2021-07-12 08:43:46 +02:00
it("Should get a 400 if no userID", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP`)
.then(res => {
assert.strictEqual(res.status, 400, "response should be 400");
done();
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
2021-07-12 08:43:46 +02:00
it("Should say a VIP is a VIP", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=supertestman`)
.then(async res => {
assert.strictEqual(res.status, 200);
2021-01-06 01:43:28 +01:00
const data = await res.json();
2021-07-07 09:47:08 +02:00
assert.strictEqual(data.vip, true);
done();
2021-07-12 08:43:46 +02:00
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
2021-07-12 08:43:46 +02:00
it("Should say a normal user is not a VIP", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=regulartestman`)
.then(async res => {
assert.strictEqual(res.status, 200);
2021-01-06 01:43:28 +01:00
const data = await res.json();
2021-07-07 09:47:08 +02:00
assert.strictEqual(data.vip, false);
done();
2021-07-12 08:43:46 +02:00
})
.catch(err => done(err));
2020-10-17 20:56:54 +02:00
});
});