Don't allow duplicate warnings

This commit is contained in:
Ajay Ramachandran
2020-12-29 13:31:15 -05:00
parent baa4e73ba5
commit 432cc42cba
2 changed files with 33 additions and 2 deletions

View File

@@ -32,6 +32,30 @@ describe('postWarning', () => {
});
});
it('Should be not be able to create a duplicate warning if vip', (done: Done) => {
let json = {
issuerUserID: 'warning-vip',
userID: 'warning-0',
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 409) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
done("Warning missing from database");
}
} else {
console.log(body);
done("Status code was " + res.statusCode);
}
});
});
it('Should be able to remove warning if vip', (done: Done) => {
let json = {
issuerUserID: 'warning-vip',