mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
made 400/404 behaviour consistent with API docs
This commit is contained in:
parent
1dcb63f2cc
commit
c92e44bb1d
2 changed files with 21 additions and 9 deletions
|
@ -44,12 +44,14 @@ async function handleGetSegmentInfo(req: Request, res: Response) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const DBSegments = await getSegmentsByUUID(UUIDs);
|
const DBSegments = await getSegmentsByUUID(UUIDs);
|
||||||
if (DBSegments === null || DBSegments === undefined) {
|
// all uuids failed lookup
|
||||||
|
if (DBSegments.length === 0) {
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (DBSegments.length === 0) {
|
// uuids valid but not found
|
||||||
res.sendStatus(404);
|
if (DBSegments[0] === null || DBSegments[0] === undefined) {
|
||||||
|
res.sendStatus(400);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return DBSegments;
|
return DBSegments;
|
||||||
|
|
|
@ -3,6 +3,7 @@ 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';
|
||||||
|
|
||||||
|
const ENOENTID = "0000000000000000000000000000000000000000000000000000000000000000"
|
||||||
const upvotedID = "a000000000000000000000000000000000000000000000000000000000000000"
|
const upvotedID = "a000000000000000000000000000000000000000000000000000000000000000"
|
||||||
const downvotedID = "b000000000000000000000000000000000000000000000000000000000000000"
|
const downvotedID = "b000000000000000000000000000000000000000000000000000000000000000"
|
||||||
const lockedupID = "c000000000000000000000000000000000000000000000000000000000000000"
|
const lockedupID = "c000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
@ -214,10 +215,10 @@ describe('getSegmentInfo', () => {
|
||||||
.catch(err => "Couldn't call endpoint");
|
.catch(err => "Couldn't call endpoint");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 404 if array passed to UUID', (done: Done) => {
|
it('Should return 400 if array passed to UUID', (done: Done) => {
|
||||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=["${upvotedID}", "${downvotedID}"]`)
|
fetch(getbaseURL() + `/api/segmentInfo?UUID=["${upvotedID}", "${downvotedID}"]`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => ("couldn't call endpoint"));
|
.catch(err => ("couldn't call endpoint"));
|
||||||
|
@ -232,19 +233,19 @@ describe('getSegmentInfo', () => {
|
||||||
.catch(err => ("couldn't call endpoint"));
|
.catch(err => ("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 404 if bad UUID passed', (done: Done) => {
|
it('Should return 400 if bad UUID passed', (done: Done) => {
|
||||||
fetch(getbaseURL() + "/api/segmentInfo?UUID=notarealuuid")
|
fetch(getbaseURL() + "/api/segmentInfo?UUID=notarealuuid")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => ("couldn't call endpoint"));
|
.catch(err => ("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return 404 if bad UUIDs passed in array', (done: Done) => {
|
it('Should return 400 if bad UUIDs passed in array', (done: Done) => {
|
||||||
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
|
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => ("couldn't call endpoint"));
|
.catch(err => ("couldn't call endpoint"));
|
||||||
|
@ -299,4 +300,13 @@ describe('getSegmentInfo', () => {
|
||||||
})
|
})
|
||||||
.catch(err => ("couldn't call endpoint"));
|
.catch(err => ("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should return 400 if UUID not found', (done: Done) => {
|
||||||
|
fetch(getbaseURL() + `/api/segmentInfo?UUID=${ENOENTID}`)
|
||||||
|
.then(res => {
|
||||||
|
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||||
|
else done(); // pass
|
||||||
|
})
|
||||||
|
.catch(err => ("couldn't call endpoint"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue