mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 04:27:09 +03:00
add 400 conditions
This commit is contained in:
@@ -6,6 +6,8 @@ import {getHash} from '../utils/getHash';
|
|||||||
import { HashedUserID, UserID } from '../types/user.model';
|
import { HashedUserID, UserID } from '../types/user.model';
|
||||||
|
|
||||||
export async function postWarning(req: Request, res: Response): Promise<Response> {
|
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
|
// Collect user input data
|
||||||
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
||||||
const userID: UserID = req.body.userID;
|
const userID: UserID = req.body.userID;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import fetch from 'node-fetch';
|
|||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
describe('getLockCategoriesByHash', () => {
|
describe('getLockCategoriesByHash', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import fetch from 'node-fetch';
|
|||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
describe('getSkipSegments', () => {
|
describe('getSkipSegments', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
|||||||
@@ -108,10 +108,10 @@ describe('getSegmentsByHash', () => {
|
|||||||
.catch(() => done("Couldn't call endpoint"));
|
.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"]')
|
fetch(getbaseURL() + '/api/skipSegments/?categories=["shilling"]')
|
||||||
.then(res => {
|
.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
|
else done(); // pass
|
||||||
})
|
})
|
||||||
.catch(() => done("Couldn't call endpoint"));
|
.catch(() => done("Couldn't call endpoint"));
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import fetch from 'node-fetch';
|
|||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
describe('getUserID', () => {
|
describe('getUserID', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
@@ -398,4 +399,13 @@ describe('getUserID', () => {
|
|||||||
})
|
})
|
||||||
.catch(() => ("couldn't call endpoint"));
|
.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"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {Done, getbaseURL} from '../utils';
|
|||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
import {IDatabase} from '../../src/databases/IDatabase';
|
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) {
|
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
|
||||||
const votes = 0,
|
const votes = 0,
|
||||||
@@ -79,4 +80,18 @@ describe('postPurgeAllSegments', function () {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import fetch from 'node-fetch';
|
|||||||
import {Done, getbaseURL} from '../utils';
|
import {Done, getbaseURL} from '../utils';
|
||||||
import {db} from '../../src/databases/databases';
|
import {db} from '../../src/databases/databases';
|
||||||
import {getHash} from '../../src/utils/getHash';
|
import {getHash} from '../../src/utils/getHash';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
describe('postWarning', () => {
|
describe('postWarning', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
@@ -127,4 +128,19 @@ describe('postWarning', () => {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.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));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user