mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 14:07:09 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into getLockCategories/reason
This commit is contained in:
@@ -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 () => {
|
||||
@@ -31,156 +31,139 @@ describe('getLockCategoriesByHash', () => {
|
||||
it('Should be able to get multiple locks in one object', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/67a65')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done(`Returned incorrect number of videos "${data.length}"`);
|
||||
} else if (data[0].videoID !== "getLockHash-1") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[0].hash !== getHash("getLockHash-1", 1)) {
|
||||
done(`Returned incorrect hash "${data[0].hash}"`);
|
||||
} else if (data[0].categories[0] !== "sponsor") {
|
||||
done(`Returned incorrect category "${data[0].categories[0]}"`);
|
||||
} else if (data[0].categories[1] !== "interaction") {
|
||||
done(`Returned incorrect category "${data[0].categories[1]}"`);
|
||||
} else if (data[0].reason !== "1-reason-longer") {
|
||||
done(`Returned incorrect reason "${data[0].reason}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "getLockHash-1",
|
||||
hash: getHash("getLockHash-1", 1),
|
||||
categories: [
|
||||
"sponsor",
|
||||
"interaction"
|
||||
],
|
||||
reason: "1-reason-longer"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get single lock', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/dff09')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of videos "' + data.length + '"');
|
||||
} else if (data[0].videoID !== "getLockHash-2") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[0].hash !== getHash("getLockHash-2", 1)) {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[0].hash}"`);
|
||||
} else if (data[0].categories.length !== 1) {
|
||||
done(`Returned incorrect number of categories "${data[0].categories.length}"`);
|
||||
} else if (data[0].categories[0] !== "preview") {
|
||||
done(`Returned incorrect category "${data[0].categories[0]}"`);
|
||||
} else if (data[0].reason !== "2-reason") {
|
||||
done(`Returned incorrect reason "${data[0].reason}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "getLockHash-2",
|
||||
hash: getHash("getLockHash-2", 1),
|
||||
categories: [
|
||||
"preview"
|
||||
],
|
||||
reason: "2-reason"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get by half full hash', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/bf1b122fd5630e0df8626d00c4a95c58')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of videos "' + data.length + '"');
|
||||
} else if (data[0].videoID !== "getLockHash-3") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[0].hash !== getHash("getLockHash-3", 1)) {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[0].hash}"`);
|
||||
} else if (data[0].categories.length !== 1) {
|
||||
done(`Returned incorrect number of categories "${data[0].categories.length}"`);
|
||||
} else if (data[0].categories[0] !== "nonmusic") {
|
||||
done(`Returned incorrect category "${data[0].categories[0]}"`);
|
||||
} else if (data[0].reason !== "3-reason") {
|
||||
done(`Returned incorrect reason "${data[0].reason}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "getLockHash-3",
|
||||
hash: getHash("getLockHash-3", 1),
|
||||
categories: [
|
||||
"nonmusic"
|
||||
],
|
||||
reason: "3-reason"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get multiple by similar hash with multiple categories', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/b05a')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 2) {
|
||||
done(`Returned incorrect number of locks "${data.length}"`);
|
||||
} else if (data[0].videoID !== "fakehash-1") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[1].videoID !== "fakehash-2") {
|
||||
done(`Returned incorrect videoID "${data[1].videoID}"`);
|
||||
} else if (data[0].hash !== "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35") {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[0].hash}"`);
|
||||
} else if (data[1].hash !== "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450") {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[1].hash}"`);
|
||||
} else if (data[0].categories.length !== 1) {
|
||||
done(`Returned incorrect number of categories "${data[0].categories.length}"`);
|
||||
} else if (data[1].categories.length !== 2) {
|
||||
done(`Returned incorrect number of categories "${data[1].categories.length}"`);
|
||||
} else if (data[0].categories[0] !== "outro") {
|
||||
done(`Returned incorrect category "${data[0].category}"`);
|
||||
} else if (data[1].categories[0] !== "intro") {
|
||||
done(`Returned incorrect category "${data[1].category}"`);
|
||||
} else if (data[1].categories[1] !== "preview") {
|
||||
done(`Returned incorrect category "${data[1].category}"`);
|
||||
} else if (data[0].reason !== "fake1-reason") {
|
||||
done(`Returned incorrect reason "${data[0].reason}"`);
|
||||
} else if (data[1].reason !== "fake2-longer-reason") {
|
||||
done(`Returned incorrect reason "${data[1].reason}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "fakehash-1",
|
||||
hash: "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35",
|
||||
categories: [
|
||||
"outro"
|
||||
],
|
||||
reason: "fake1-reason"
|
||||
}, {
|
||||
videoID: "fakehash-2",
|
||||
hash: "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450",
|
||||
categories: [
|
||||
"intro",
|
||||
"preview"
|
||||
],
|
||||
reason: "fake2-longer-reason"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 404 once hash prefix varies', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/aaaaaa')
|
||||
fetch(getbaseURL() + '/api/lockCategories/b05aa')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done('non 404 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 404 if no lock exists', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/aaaaaa')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done('non 404 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if no videoID specified', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if full hash sent', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user