Skip to content

Commit

Permalink
reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Ianyourgod committed Feb 23, 2024
1 parent d39c645 commit 7873403
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 49 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ Please report any security vulnerabilities using GitHub's security tab on the re
- [Windows](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/)
- [Mac](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/)
- [Linux](https://docs.mongodb.com/manual/administration/install-on-linux/)
2. run `mongosh` in your terminal to start the MongoDB shell
1. run `use pm_userdata` to create the database
2. run `db.createCollection('users')` to create the users collection & save the new db
3. Run `npm i`. if this doesn't work run it with --force
4. Run `npm run dev` to start the server in development mode.
2. Run `npm i`. if this doesn't work run it with --force
3. Run `npm run dev` to start the server in development mode.
80 changes: 74 additions & 6 deletions api/db/UMTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ async function tests() {

await manager.reset(true);

////////////////////
// Create account //
////////////////////

let createAccountSuccess = await manager.createAccount('test', 'password');
if (!createAccountSuccess) {
console.log("[ FAIL ]".red, "Failed to create account");
Expand All @@ -21,6 +25,10 @@ async function tests() {
}
console.log("[ PASS ]".green, "Failed to create account with same username");

////////////////////
// Password Login //
////////////////////

let passwordLoginSuccess = await manager.loginWithPassword('test', 'password');
if (!passwordLoginSuccess) {
console.log("[ FAIL ]".red, "Failed to login with password");
Expand All @@ -37,6 +45,10 @@ async function tests() {

let token = await manager.loginWithPassword('test', 'password');

/////////////////
// Token Login //
/////////////////

let tokenLoginSuccess = await manager.loginWithToken('test', token);
if (!tokenLoginSuccess) {
console.log("[ FAIL ]".red, "Failed to login with token");
Expand All @@ -51,13 +63,28 @@ async function tests() {
}
console.log("[ PASS ]".green, "Failed to login with wrong token");

/////////////////////
// Get ID/Username //
/////////////////////

let getID = await manager.getIDByUsername('test');
if (!getID) {
console.log("[ FAIL ]".red, "Failed to get ID by username");
return false;
}
console.log("[ PASS ]".green, "Got ID by username");

let getUsernameByID = await manager.getUsernameByID(getID);
if (getUsernameByID !== 'test') {
console.log("[ FAIL ]".red, "Failed to get username by ID");
return false;
}
console.log("[ PASS ]".green, "Got username by ID");

/////////////////
// User Exists //
/////////////////

let existsByUsername = await manager.existsByUsername('test');
if (!existsByUsername) {
console.log("[ FAIL ]".red, "Failed to check if user exists by username");
Expand All @@ -72,12 +99,9 @@ async function tests() {
}
console.log("[ PASS ]".green, "Checked if user exists by ID");

let getUsernameByID = await manager.getUsernameByID(getID);
if (getUsernameByID !== 'test') {
console.log("[ FAIL ]".red, "Failed to get username by ID");
return false;
}
console.log("[ PASS ]".green, "Got username by ID");
//////////////////////
// Change User Data //
//////////////////////

let changeUsername = await manager.changeUsername(getID, 'newtest');
if (!await manager.existsByUsername("newtest")) {
Expand All @@ -86,6 +110,13 @@ async function tests() {
}
console.log("[ PASS ]".green, "Changed username");

let logout = await manager.logout('newtest');
if (await manager.loginWithToken('newtest', token)) {
console.log("[ FAIL ]".red, "Failed to logout");
return false;
}
console.log("[ PASS ]".green, "Logged out");

let changePassword = await manager.changePassword('newtest', 'newpassword');
token = await manager.loginWithPassword('newtest', 'newpassword');
if (!token) {
Expand Down Expand Up @@ -158,6 +189,43 @@ async function tests() {
}
console.log("[ PASS ]".green, "Set/get banned");

///////////////
// Reporting //
///////////////

let userToReport = await manager.createAccount('imstupid', 'password');

let report = await manager.report(
0,
await manager.getIDByUsername("imstupid"),
"they are stupid",
await manager.getIDByUsername("newtest")
);

let getReportsByType = await manager.getReportsByType(0);
if (getReportsByType.length !== 1) {
console.log("[ FAIL ]".red, "Failed to get reports by type");
return false;
}

let getReportsByReporter = await manager.getReportsByReporter(await manager.getIDByUsername("newtest"));
if (getReportsByReporter.length !== 1) {
console.log("[ FAIL ]".red, "Failed to get reports by reporter");
return false;
}

let getReportsByReported = await manager.getReportsByReportee(await manager.getIDByUsername("imstupid"));
if (getReportsByReported.length !== 1) {
console.log("[ FAIL ]".red, "Failed to get reports by reportee");
return false;
}

let deleteReport = await manager.deleteReport(getReportsByType[0].id);
if ((await manager.getReportsByType(0)).length !== 0) {
console.log("[ FAIL ]".red, "Failed to delete report");
return false;
}

return true;
}

Expand Down
Loading

0 comments on commit 7873403

Please sign in to comment.