added warning system

Co-authored-by: Ajay Ramachandran <dev@ajay.app>
This commit is contained in:
Joe Dowd
2020-09-15 23:56:10 +01:00
committed by GitHub
parent b52a862f4f
commit 075cb9d5f2
8 changed files with 187 additions and 9 deletions

View File

@@ -16,6 +16,11 @@ describe('getUserInfo', () => {
db.exec(startOfSponsorTimesQuery + "('zzzxxxyyy', 1, 11, 2, 'uuid000006', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 0)");
db.exec(startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000007', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 1)");
db.exec(startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000008', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 1)");
db.exec("INSERT INTO warnings (userID, issueTime, issuerUserID) VALUES ('" + getHash('getuserinfo_warning_0') + "', 10, 'getuserinfo_vip')");
db.exec("INSERT INTO warnings (userID, issueTime, issuerUserID) VALUES ('" + getHash('getuserinfo_warning_1') + "', 10, 'getuserinfo_vip')");
db.exec("INSERT INTO warnings (userID, issueTime, issuerUserID) VALUES ('" + getHash('getuserinfo_warning_1') + "', 10, 'getuserinfo_vip')");
});
it('Should be able to get a 200', (done) => {
@@ -26,7 +31,7 @@ describe('getUserInfo', () => {
done('couldn\'t call endpoint');
} else {
if (res.statusCode !== 200) {
done('non 200');
done('non 200 (' + res.statusCode + ')');
} else {
done(); // pass
}
@@ -62,18 +67,79 @@ describe('getUserInfo', () => {
} else {
const data = JSON.parse(body);
if (data.userName !== 'Username user 01') {
return done('Returned incorrect userName "' + data.userName + '"');
done('Returned incorrect userName "' + data.userName + '"');
} else if (data.minutesSaved !== 5) {
done('Returned incorrect minutesSaved "' + data.minutesSaved + '"');
} else if (data.viewCount !== 30) {
done('Returned incorrect viewCount "' + data.viewCount + '"');
} else if (data.segmentCount !== 3) {
done('Returned incorrect segmentCount "' + data.segmentCount + '"');
} else {
done(); // pass
}
if (data.minutesSaved !== 5) {
return done('Returned incorrect minutesSaved "' + data.minutesSaved + '"');
}
}
});
});
it('Should get warning data', (done) => {
request.get(utils.getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_0', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 1) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
} else {
done(); // pass
}
if (data.viewCount !== 30) {
return done('Returned incorrect viewCount "' + data.viewCount + '"');
}
}
});
});
it('Should get multiple warnings', (done) => {
request.get(utils.getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_1', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 2) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 2);
} else {
done(); // pass
}
if (data.segmentCount !== 3) {
return done('Returned incorrect segmentCount "' + data.segmentCount + '"');
}
}
});
});
it('Should not get warnings if noe', (done) => {
request.get(utils.getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_2', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 0) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 0);
} else {
done(); // pass
}
done(); // pass
}
}
});

53
test/cases/postWarning.js Normal file
View File

@@ -0,0 +1,53 @@
var request = require('request');
var utils = require('../utils.js');
var db = require('../../src/databases/databases.js').db;
var getHash = require('../../src/utils/getHash.js');
describe('postWarning', () => {
before(() => {
db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("warning-vip") + "')");
});
it('Should update the database version when starting the application', (done) => {
let version = db.prepare('get', 'SELECT key, value FROM config where key = ?', ['version']).value;
if (version > 3) done();
else done('Version isn\'t greater than 3. Version is ' + version);
});
it('Should be able to create warning if vip (exp 200)', (done) => {
let json = {
issuerUserID: 'warning-vip',
userID: 'warning-0'
};
request.post(utils.getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
}
});
});
it('Should not be able to create warning if vip (exp 403)', (done) => {
let json = {
issuerUserID: 'warning-not-vip',
userID: 'warning-1'
};
request.post(utils.getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
}
});
});
});