mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 13:37:01 +03:00
add segment generator
- getIsUserVIP - postClearCache - update boilerplate
This commit is contained in:
@@ -1,54 +1,42 @@
|
||||
import { db } from "../../src/databases/databases";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { genUsers, User } from "../utils/genUser";
|
||||
import { client } from "../utils/httpClient";
|
||||
import assert from "assert";
|
||||
import { insertVip } from "../utils/queryGen";
|
||||
|
||||
const VIPUser = "isUserVIPVIP";
|
||||
const normalUser = "isUserVIPNormal";
|
||||
const endpoint = "/api/isUserVIP";
|
||||
const vipUserRequest = (userID: string) => client.get(endpoint, { params: { userID } });
|
||||
const checkVipStatus = (user: User, expected: boolean) =>
|
||||
vipUserRequest(user.privID)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
assert.strictEqual(res.data.vip, expected);
|
||||
});
|
||||
|
||||
const cases = [
|
||||
"vip",
|
||||
"normal",
|
||||
];
|
||||
const users = genUsers("endpoint", cases);
|
||||
|
||||
describe("getIsUserVIP", () => {
|
||||
before(() => {
|
||||
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(VIPUser)]);
|
||||
before(async () => {
|
||||
await insertVip(db, users["vip"].pubID);
|
||||
});
|
||||
|
||||
it("Should be able to get a 200", (done) => {
|
||||
vipUserRequest(VIPUser)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200, "response should be 200");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
// status checks
|
||||
it("Should be able to get a 200", () =>
|
||||
vipUserRequest(users["vip"].privID)
|
||||
.then(res => assert.strictEqual(res.status, 200))
|
||||
);
|
||||
|
||||
|
||||
it("Should get a 400 if no userID", (done) => {
|
||||
it("Should get a 400 if no userID", () =>
|
||||
client.get(endpoint)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400, "response should be 400");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
.then(res => assert.strictEqual(res.status, 400, "response should be 400"))
|
||||
);
|
||||
|
||||
it("Should say a VIP is a VIP", (done) => {
|
||||
vipUserRequest(VIPUser)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
assert.strictEqual(res.data.vip, true);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should say a normal user is not a VIP", (done) => {
|
||||
vipUserRequest(normalUser)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
assert.strictEqual(res.data.vip, false);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
// user checks
|
||||
it("Should say a VIP is a VIP", () => checkVipStatus(users["vip"], true));
|
||||
it("Should say a normal user is not a VIP", () => checkVipStatus(users["normal"], false));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user