add 400 conditions

This commit is contained in:
Michael C
2021-07-10 16:30:30 -04:00
parent 596dbf4ac8
commit e8d0da3ce3
7 changed files with 47 additions and 3 deletions

View File

@@ -6,6 +6,8 @@ import {getHash} from '../utils/getHash';
import { HashedUserID, UserID } from '../types/user.model';
export async function postWarning(req: Request, res: Response): Promise<Response> {
// exit early if no body passed in
if (!req.body.userID && !req.body.issuerUserID) return res.status(400).json({"message": "Missing parameters"});
// Collect user input data
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
const userID: UserID = req.body.userID;

View File

@@ -2,7 +2,7 @@ import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {db} from '../../src/databases/databases';
import assert from 'assert';
describe('getLockCategoriesByHash', () => {
before(async () => {

View File

@@ -2,6 +2,7 @@ import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
describe('getSkipSegments', () => {
before(async () => {

View File

@@ -108,10 +108,10 @@ describe('getSegmentsByHash', () => {
.catch(() => done("Couldn't call endpoint"));
});
it('Should return 404 for no hash', (done: Done) => {
it('Should return 400 for no hash', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/?categories=["shilling"]')
.then(res => {
if (res.status !== 404) done("expected 404, got " + res.status);
if (res.status !== 400) done("expected 400, got " + res.status);
else done(); // pass
})
.catch(() => done("Couldn't call endpoint"));

View File

@@ -2,6 +2,7 @@ import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
describe('getUserID', () => {
before(async () => {
@@ -398,4 +399,13 @@ describe('getUserID', () => {
})
.catch(() => ("couldn't call endpoint"));
});
it('should return 400 if no username parameter specified', (done: Done) => {
fetch(getbaseURL() + '/api/userID')
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(() => ("couldn't call endpoint"));
});
});

View File

@@ -3,6 +3,7 @@ import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import {IDatabase} from '../../src/databases/IDatabase';
import assert from 'assert';
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
const votes = 0,
@@ -79,4 +80,18 @@ describe('postPurgeAllSegments', function () {
})
.catch(err => done(err));
});
it('Should return 400 if missing body', function (done: Done) {
fetch(`${baseURL}${route}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
})
.then(async res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
});

View File

@@ -2,6 +2,7 @@ import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
describe('postWarning', () => {
before(async () => {
@@ -127,4 +128,19 @@ describe('postWarning', () => {
})
.catch(err => done(err));
});
it('Should return 400 if missing body', (done: Done) => {
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
})
.then(async res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
});