mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-12 22:47:12 +03:00
Merge pull request #316 from mchangrh/400-on-noparam
Return 400 if no parameters specified
This commit is contained in:
@@ -4,7 +4,6 @@ import {getHash} from '../../src/utils/getHash';
|
||||
import {db} from '../../src/databases/databases';
|
||||
import assert from 'assert';
|
||||
|
||||
|
||||
describe('getLockCategoriesByHash', () => {
|
||||
before(async () => {
|
||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||
@@ -144,4 +143,22 @@ describe('getLockCategoriesByHash', () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if hash too short', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/00')
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if no hash specified', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/')
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -340,4 +340,13 @@ describe('getSkipSegments', () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should get 400 if no videoID passed in', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments')
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, 'YouTubeAPI');
|
||||
const sinonStub = mockManager.mock('listVideos');
|
||||
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
||||
|
||||
describe('getSegmentsByHash', () => {
|
||||
describe('getSkipSegmentsByHash', () => {
|
||||
before(async () => {
|
||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", query, ['getSegmentsByHash-0', 1, 10, 2, 'getSegmentsByHash-0-0', 'testman', 0, 50, 'sponsor', 'skip', 'YouTube', 0, 0, 'fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910']);
|
||||
@@ -106,10 +106,10 @@ describe('getSegmentsByHash', () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
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 => {
|
||||
assert.strictEqual(res.status, 404);
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
|
||||
@@ -313,4 +313,13 @@ describe('getUserID', () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
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"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,4 +81,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));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -102,4 +102,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));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user