Add test, Fix sql syntax

This commit is contained in:
Haidang666 2021-06-30 08:59:20 +07:00
parent 214ddc9807
commit 081f2d14b7
2 changed files with 5 additions and 4 deletions

View file

@ -9,10 +9,10 @@ CREATE TABLE "sqlb_temp_table_17" (
"reason" TEXT NOT NULL default '' "reason" TEXT NOT NULL default ''
); );
INSERT INTO sqlb_temp_table_17 SELECT "userID","issueTime","issuerUserID","enabled", "" FROM "warnings"; INSERT INTO sqlb_temp_table_17 SELECT "userID","issueTime","issuerUserID","enabled", '' FROM "warnings";
DROP TABLE warnings; DROP TABLE warnings;
ALTER TABLE sqlb_temp_table_17 RENAME TO "warnings";; ALTER TABLE sqlb_temp_table_17 RENAME TO "warnings";
UPDATE "config" SET value = 17 WHERE key = 'version'; UPDATE "config" SET value = 17 WHERE key = 'version';

View file

@ -12,6 +12,7 @@ describe('postWarning', () => {
let json = { let json = {
issuerUserID: 'warning-vip', issuerUserID: 'warning-vip',
userID: 'warning-0', userID: 'warning-0',
reason: 'warning-reason-0'
}; };
fetch(getbaseURL() fetch(getbaseURL()
+ "/api/warnUser", { + "/api/warnUser", {
@ -23,8 +24,8 @@ describe('postWarning', () => {
}) })
.then(async res => { .then(async res => {
if (res.status === 200) { if (res.status === 200) {
let row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]); let row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) { if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID) && row?.reason === json.reason) {
done(); done();
} else { } else {
done("Warning missing from database"); done("Warning missing from database");