add getIP test cases, misc others

This commit is contained in:
Michael C
2022-09-21 19:39:03 -04:00
parent 6499381b4f
commit a00048aaac
7 changed files with 240 additions and 4 deletions

View File

@@ -10,6 +10,10 @@ const checkUserVIP = (publicID: string) => db.prepare("get", `SELECT "userID" FR
const adminPrivateUserID = "testUserId";
const permVIP1 = "addVIP_permaVIPOne";
const publicPermVIP1 = getHash(permVIP1) as HashedUserID;
const permVIP2 = "addVIP_permaVIPTwo";
const publicPermVIP2 = getHash(permVIP2) as HashedUserID;
const permVIP3 = "addVIP_permaVIPThree";
const publicPermVIP3 = getHash(permVIP3) as HashedUserID;
const endpoint = "/api/addUserAsVIP";
const addUserAsVIP = (userID: string, enabled: boolean, adminUserID = adminPrivateUserID) => client({
@@ -41,6 +45,16 @@ describe("addVIP test", function() {
})
.catch(err => done(err));
});
it("Should be able to add second user as VIP", (done) => {
addUserAsVIP(publicPermVIP2, true)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await checkUserVIP(publicPermVIP2);
assert.ok(row);
done();
})
.catch(err => done(err));
});
it("Should return 403 with invalid adminID", (done) => {
addUserAsVIP(publicPermVIP1, true, "Invalid_Admin_User_ID")
.then(res => {
@@ -89,4 +103,39 @@ describe("addVIP test", function() {
})
.catch(err => done(err));
});
it("Should remove VIP if enabled is false", (done) => {
client({
method: "POST",
url: endpoint,
params: {
userID: publicPermVIP2,
adminUserID: adminPrivateUserID,
enabled: "invalid-text"
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await checkUserVIP(publicPermVIP2);
assert.ok(!row);
done();
})
.catch(err => done(err));
});
it("Should remove VIP if enabled is missing", (done) => {
client({
method: "POST",
url: endpoint,
params: {
userID: publicPermVIP3,
adminUserID: adminPrivateUserID
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await checkUserVIP(publicPermVIP3);
assert.ok(!row);
done();
})
.catch(err => done(err));
});
});