mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
everything to postClearCache
This commit is contained in:
parent
94e1e8c377
commit
c779c2c19e
21 changed files with 750 additions and 860 deletions
41
package-lock.json
generated
41
package-lock.json
generated
|
@ -11,6 +11,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/lru-diskcache": "^1.1.9",
|
"@ajayyy/lru-diskcache": "^1.1.9",
|
||||||
"@types/request": "^2.48.7",
|
"@types/request": "^2.48.7",
|
||||||
|
"axios": "^0.21.4",
|
||||||
"better-sqlite3": "^7.4.3",
|
"better-sqlite3": "^7.4.3",
|
||||||
"cron": "^1.8.2",
|
"cron": "^1.8.2",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
@ -1111,6 +1112,14 @@
|
||||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||||
},
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "0.21.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
|
||||||
|
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.14.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/babel-runtime": {
|
"node_modules/babel-runtime": {
|
||||||
"version": "6.26.0",
|
"version": "6.26.0",
|
||||||
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
|
||||||
|
@ -2570,6 +2579,25 @@
|
||||||
"integrity": "sha512-XprP7lDrVT+kE2c2YlfiV+IfS9zxukiIOvNamPNsImNhXadSsQEbosItdL9bUQlCZXR13SvPk20BjWSWLA7m4A==",
|
"integrity": "sha512-XprP7lDrVT+kE2c2YlfiV+IfS9zxukiIOvNamPNsImNhXadSsQEbosItdL9bUQlCZXR13SvPk20BjWSWLA7m4A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.14.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
|
||||||
|
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/form-data": {
|
"node_modules/form-data": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
|
||||||
|
@ -6660,6 +6688,14 @@
|
||||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||||
},
|
},
|
||||||
|
"axios": {
|
||||||
|
"version": "0.21.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
|
||||||
|
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
|
||||||
|
"requires": {
|
||||||
|
"follow-redirects": "^1.14.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"babel-runtime": {
|
"babel-runtime": {
|
||||||
"version": "6.26.0",
|
"version": "6.26.0",
|
||||||
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
|
||||||
|
@ -7785,6 +7821,11 @@
|
||||||
"integrity": "sha512-XprP7lDrVT+kE2c2YlfiV+IfS9zxukiIOvNamPNsImNhXadSsQEbosItdL9bUQlCZXR13SvPk20BjWSWLA7m4A==",
|
"integrity": "sha512-XprP7lDrVT+kE2c2YlfiV+IfS9zxukiIOvNamPNsImNhXadSsQEbosItdL9bUQlCZXR13SvPk20BjWSWLA7m4A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"follow-redirects": {
|
||||||
|
"version": "1.14.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
|
||||||
|
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g=="
|
||||||
|
},
|
||||||
"form-data": {
|
"form-data": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ajayyy/lru-diskcache": "^1.1.9",
|
"@ajayyy/lru-diskcache": "^1.1.9",
|
||||||
"@types/request": "^2.48.7",
|
"@types/request": "^2.48.7",
|
||||||
|
"axios": "^0.21.4",
|
||||||
"better-sqlite3": "^7.4.3",
|
"better-sqlite3": "^7.4.3",
|
||||||
"cron": "^1.8.2",
|
"cron": "^1.8.2",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import fetch from "node-fetch";
|
import axios from "axios";
|
||||||
import {Logger} from "../utils/logger";
|
import {Logger} from "../utils/logger";
|
||||||
import {config} from "../config";
|
import {config} from "../config";
|
||||||
import {getIP} from "../utils/getIP";
|
import {getIP} from "../utils/getIP";
|
||||||
|
@ -6,7 +6,7 @@ import {getHash} from "../utils/getHash";
|
||||||
import {NextFunction, Request, Response} from "express";
|
import {NextFunction, Request, Response} from "express";
|
||||||
|
|
||||||
export function userCounter(req: Request, res: Response, next: NextFunction): void {
|
export function userCounter(req: Request, res: Response, next: NextFunction): void {
|
||||||
fetch(`${config.userCounterURL}/api/v1/addIP?hashedIP=${getHash(getIP(req), 1)}`, {method: "POST"})
|
axios.post(`${config.userCounterURL}/api/v1/addIP?hashedIP=${getHash(getIP(req), 1)}`)
|
||||||
.catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
|
.catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {db} from "../databases/databases";
|
||||||
import {config} from "../config";
|
import {config} from "../config";
|
||||||
import {Request, Response} from "express";
|
import {Request, Response} from "express";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
|
import axios from "axios";
|
||||||
import {Logger} from "../utils/logger";
|
import {Logger} from "../utils/logger";
|
||||||
|
|
||||||
// A cache of the number of chrome web store users
|
// A cache of the number of chrome web store users
|
||||||
|
@ -44,10 +45,9 @@ export async function getTotalStats(req: Request, res: Response): Promise<void>
|
||||||
|
|
||||||
function updateExtensionUsers() {
|
function updateExtensionUsers() {
|
||||||
if (config.userCounterURL) {
|
if (config.userCounterURL) {
|
||||||
fetch(`${config.userCounterURL}/api/v1/userCount`)
|
axios.get(`${config.userCounterURL}/api/v1/userCount`)
|
||||||
.then(res => res.json())
|
.then(res => {
|
||||||
.then(data => {
|
apiUsersCache = Math.max(apiUsersCache, res.data.userCount);
|
||||||
apiUsersCache = Math.max(apiUsersCache, data.userCount);
|
|
||||||
})
|
})
|
||||||
.catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
|
.catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done} from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
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 { client } from "../utils/httpClient";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
const endpoint = `${getbaseURL()}/api/isUserVIP`;
|
|
||||||
const VIPUser = "isUserVIPVIP";
|
const VIPUser = "isUserVIPVIP";
|
||||||
const normalUser = "isUserVIPNormal";
|
const normalUser = "isUserVIPNormal";
|
||||||
|
const endpoint = "/api/isUserVIP";
|
||||||
|
const vipUserRequest = (userID: string) => client.get(endpoint, { params: { userID }});
|
||||||
|
|
||||||
describe("getIsUserVIP", () => {
|
describe("getIsUserVIP", () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(VIPUser)]);
|
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(VIPUser)]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done) => {
|
||||||
fetch(`${endpoint}?userID=${VIPUser}`)
|
vipUserRequest(VIPUser)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200, "response should be 200");
|
assert.strictEqual(res.status, 200, "response should be 200");
|
||||||
done();
|
done();
|
||||||
|
@ -24,8 +23,8 @@ describe("getIsUserVIP", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Should get a 400 if no userID", (done: Done) => {
|
it("Should get a 400 if no userID", (done) => {
|
||||||
fetch(endpoint)
|
client.get(endpoint)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400, "response should be 400");
|
assert.strictEqual(res.status, 400, "response should be 400");
|
||||||
done();
|
done();
|
||||||
|
@ -33,23 +32,21 @@ describe("getIsUserVIP", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should say a VIP is a VIP", (done: Done) => {
|
it("Should say a VIP is a VIP", (done) => {
|
||||||
fetch(`${endpoint}?userID=${VIPUser}`)
|
vipUserRequest(VIPUser)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
assert.strictEqual(res.data.vip, true);
|
||||||
assert.strictEqual(data.vip, true);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should say a normal user is not a VIP", (done: Done) => {
|
it("Should say a normal user is not a VIP", (done) => {
|
||||||
fetch(`${endpoint}?userID=${normalUser}`)
|
vipUserRequest(normalUser)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
assert.strictEqual(res.data.vip, false);
|
||||||
assert.strictEqual(data.vip, false);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
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";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
const endpoint = "/api/lockCategories";
|
||||||
|
const getLockCategories = (videoID: string) => client.get(endpoint, { params: { videoID } });
|
||||||
|
|
||||||
describe("getLockCategories", () => {
|
describe("getLockCategories", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/lockCategories`;
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||||
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesVIP")]);
|
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesVIP")]);
|
||||||
|
@ -26,11 +24,10 @@ describe("getLockCategories", () => {
|
||||||
assert.ok(version > 20, `Version isn't greater than 20. Version is ${version}`);
|
assert.ok(version > 20, `Version isn't greater than 20. Version is ${version}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple locks", (done: Done) => {
|
it("Should be able to get multiple locks", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getLock1`)
|
getLockCategories("getLock1")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
categories: [
|
categories: [
|
||||||
"sponsor",
|
"sponsor",
|
||||||
|
@ -38,31 +35,30 @@ describe("getLockCategories", () => {
|
||||||
],
|
],
|
||||||
reason: "1-longer-reason"
|
reason: "1-longer-reason"
|
||||||
};
|
};
|
||||||
assert.deepStrictEqual(data, expected);
|
assert.deepStrictEqual(res.data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get single locks", (done: Done) => {
|
it("Should be able to get single locks", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getLock2`)
|
getLockCategories("getLock2")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
categories: [
|
categories: [
|
||||||
"preview"
|
"preview"
|
||||||
],
|
],
|
||||||
reason: "2-reason"
|
reason: "2-reason"
|
||||||
};
|
};
|
||||||
assert.deepStrictEqual(data, expected);
|
assert.deepStrictEqual(res.data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 404 if no lock exists", (done: Done) => {
|
it("should return 404 if no lock exists", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getLockNull`)
|
getLockCategories("getLockNull")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -70,8 +66,8 @@ describe("getLockCategories", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 400 if no videoID specified", (done: Done) => {
|
it("should return 400 if no videoID specified", (done) => {
|
||||||
fetch(endpoint)
|
client.get(endpoint)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
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";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const fakeHash = "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35";
|
const fakeHash = "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35";
|
||||||
|
const endpoint = "/api/lockCategories";
|
||||||
|
const getLockCategories = (hash: string) => client.get(`${endpoint}/${hash}`);
|
||||||
|
|
||||||
describe("getLockCategoriesByHash", () => {
|
describe("getLockCategoriesByHash", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/lockCategories`;
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||||
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP")]);
|
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP")]);
|
||||||
|
@ -33,13 +32,12 @@ describe("getLockCategoriesByHash", () => {
|
||||||
`Version isn't greater than 20. Version is ${version}`);
|
`Version isn't greater than 20. Version is ${version}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple locks in one object", (done: Done) => {
|
it("Should be able to get multiple locks in one object", (done) => {
|
||||||
const videoID = "getLockHash1";
|
const videoID = "getLockHash1";
|
||||||
const hash = getHash(videoID, 1);
|
const hash = getHash(videoID, 1);
|
||||||
fetch(`${endpoint}/${hash.substring(0,4)}`)
|
getLockCategories(hash.substring(0,4))
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID,
|
videoID,
|
||||||
hash,
|
hash,
|
||||||
|
@ -49,19 +47,18 @@ describe("getLockCategoriesByHash", () => {
|
||||||
],
|
],
|
||||||
reason: "1-reason-longer"
|
reason: "1-reason-longer"
|
||||||
}];
|
}];
|
||||||
assert.deepStrictEqual(data, expected);
|
assert.deepStrictEqual(res.data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get single lock", (done: Done) => {
|
it("Should be able to get single lock", (done) => {
|
||||||
const videoID = "getLockHash2";
|
const videoID = "getLockHash2";
|
||||||
const hash = getHash(videoID, 1);
|
const hash = getHash(videoID, 1);
|
||||||
fetch(`${endpoint}/${hash.substring(0,6)}`)
|
getLockCategories(hash.substring(0,6))
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID,
|
videoID,
|
||||||
hash,
|
hash,
|
||||||
|
@ -70,19 +67,18 @@ describe("getLockCategoriesByHash", () => {
|
||||||
],
|
],
|
||||||
reason: "2-reason"
|
reason: "2-reason"
|
||||||
}];
|
}];
|
||||||
assert.deepStrictEqual(data, expected);
|
assert.deepStrictEqual(res.data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get by half full hash", (done: Done) => {
|
it("Should be able to get by half full hash", (done) => {
|
||||||
const videoID = "getLockHash3";
|
const videoID = "getLockHash3";
|
||||||
const hash = getHash(videoID, 1);
|
const hash = getHash(videoID, 1);
|
||||||
fetch(`${endpoint}/${hash.substring(0,32)}`)
|
getLockCategories(hash.substring(0,32))
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID,
|
videoID,
|
||||||
hash,
|
hash,
|
||||||
|
@ -91,17 +87,16 @@ describe("getLockCategoriesByHash", () => {
|
||||||
],
|
],
|
||||||
reason: "3-reason"
|
reason: "3-reason"
|
||||||
}];
|
}];
|
||||||
assert.deepStrictEqual(data, expected);
|
assert.deepStrictEqual(res.data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple by similar hash with multiple categories", (done: Done) => {
|
it("Should be able to get multiple by similar hash with multiple categories", (done) => {
|
||||||
fetch(`${endpoint}/${fakeHash.substring(0,5)}`)
|
getLockCategories(fakeHash.substring(0,5))
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "fakehash-1",
|
videoID: "fakehash-1",
|
||||||
hash: fakeHash,
|
hash: fakeHash,
|
||||||
|
@ -118,14 +113,14 @@ describe("getLockCategoriesByHash", () => {
|
||||||
],
|
],
|
||||||
reason: "fake2-longer-reason"
|
reason: "fake2-longer-reason"
|
||||||
}];
|
}];
|
||||||
assert.deepStrictEqual(data, expected);
|
assert.deepStrictEqual(res.data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 404 once hash prefix varies", (done: Done) => {
|
it("should return 404 once hash prefix varies", (done) => {
|
||||||
fetch(`${endpoint}/b05aa`)
|
getLockCategories("b05aa")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -133,8 +128,8 @@ describe("getLockCategoriesByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 404 if no lock exists", (done: Done) => {
|
it("should return 404 if no lock exists", (done) => {
|
||||||
fetch(`${endpoint}/aaaaaa`)
|
getLockCategories("aaaaaa")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -142,8 +137,8 @@ describe("getLockCategoriesByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 400 if no videoID specified", (done: Done) => {
|
it("should return 400 if full hash sent", (done) => {
|
||||||
fetch(`${endpoint}/`)
|
getLockCategories(fakeHash)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -151,8 +146,8 @@ describe("getLockCategoriesByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 400 if full hash sent", (done: Done) => {
|
it("should return 400 if hash too short", (done) => {
|
||||||
fetch(`${endpoint}/${fakeHash}`)
|
getLockCategories("00")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -160,17 +155,8 @@ describe("getLockCategoriesByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 400 if hash too short", (done: Done) => {
|
it("should return 400 if no hash specified", (done) => {
|
||||||
fetch(`${endpoint}/00`)
|
getLockCategories("")
|
||||||
.then(res => {
|
|
||||||
assert.strictEqual(res.status, 400);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(err => done(err));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return 400 if no hash specified", (done: Done) => {
|
|
||||||
fetch(endpoint)
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -1,29 +1,27 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
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 {deepStrictEqual} from "assert";
|
import {deepStrictEqual} from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
const endpoint = "/api/getSavedTimeForUser";
|
||||||
|
|
||||||
describe("getSavedTimeForUser", () => {
|
describe("getSavedTimeForUser", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/getSavedTimeForUser`;
|
const user1 = "getSavedTimeForUserUser";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "shadowHidden") VALUES';
|
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "shadowHidden") VALUES';
|
||||||
await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
["getSavedTimeForUser", 1, 11, 2, "gstfu0", getHash("getSavedTimeForUserUser"), 0, 50, 0]);
|
["getSavedTimeForUser", 1, 11, 2, "gstfu0", getHash(user1), 0, 50, 0]);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done) => {
|
||||||
fetch(`${endpoint}?userID=getSavedTimeForUserUser`)
|
client.get(endpoint, { params: { userID: user1 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
const data = await res.json();
|
|
||||||
// (end-start)*minute * views
|
// (end-start)*minute * views
|
||||||
const savedMinutes = ((11-1)/60) * 50;
|
const savedMinutes = ((11-1)/60) * 50;
|
||||||
const expected = {
|
const expected = {
|
||||||
timeSaved: savedMinutes
|
timeSaved: savedMinutes
|
||||||
};
|
};
|
||||||
deepStrictEqual(data, expected);
|
deepStrictEqual(res.data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch((err) => done(err));
|
.catch((err) => done(err));
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import { Done } from "../utils/utils";
|
import { client } from "../utils/httpClient";
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
describe("getSearchSegments", () => {
|
describe("getSearchSegments", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/searchSegments`;
|
const endpoint = "/api/searchSegments";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "views", "locked", "hidden", "shadowHidden", "timeSubmitted", "UUID", "userID", "category", "actionType") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "views", "locked", "hidden", "shadowHidden", "timeSubmitted", "UUID", "userID", "category", "actionType") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", query, ["searchTest0", 0, 1, 2, 0, 0, 0, 0, 1, "search-normal", "searchTestUser", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest0", 0, 1, 2, 0, 0, 0, 0, 1, "search-normal", "searchTestUser", "sponsor", "skip"]);
|
||||||
|
@ -34,11 +32,11 @@ describe("getSearchSegments", () => {
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to show all segments under searchTest0", (done: Done) => {
|
it("Should be able to show all segments under searchTest0", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest0`)
|
client.get(endpoint, { params: { videoID: "searchTest0" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 5);
|
assert.strictEqual(data.segmentCount, 5);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -52,11 +50,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter by category", (done: Done) => {
|
it("Should be able to filter by category", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest0&category=selfpromo`)
|
client.get(endpoint, { params: { videoID: "searchTest0", category: "selfpromo" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 1);
|
assert.strictEqual(data.segmentCount, 1);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -66,11 +64,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter by category", (done: Done) => {
|
it("Should be able to filter by category", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest0&category=selfpromo`)
|
client.get(endpoint, { params: { videoID: "searchTest0", category: "selfpromo" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 1);
|
assert.strictEqual(data.segmentCount, 1);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -80,11 +78,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter by lock status", (done: Done) => {
|
it("Should be able to filter by lock status", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest0&locked=false`)
|
client.get(endpoint, { params: { videoID: "searchTest0", locked: false }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 4);
|
assert.strictEqual(data.segmentCount, 4);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -97,11 +95,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter by hide status", (done: Done) => {
|
it("Should be able to filter by hide status", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest0&hidden=false`)
|
client.get(endpoint, { params: { videoID: "searchTest0", hidden: false }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 4);
|
assert.strictEqual(data.segmentCount, 4);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -114,11 +112,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter by ignored status", (done: Done) => {
|
it("Should be able to filter by ignored status", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest0&ignored=false`)
|
client.get(endpoint, { params: { videoID: "searchTest0", ignored: false }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 3);
|
assert.strictEqual(data.segmentCount, 3);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -130,11 +128,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter segments by min views", (done: Done) => {
|
it("Should be able to filter segments by min views", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest1&minViews=6`)
|
client.get(endpoint, { params: { videoID: "searchTest1", minViews: 6 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 1);
|
assert.strictEqual(data.segmentCount, 1);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -144,11 +142,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter segments by max views", (done: Done) => {
|
it("Should be able to filter segments by max views", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest1&maxViews=10`)
|
client.get(endpoint, { params: { videoID: "searchTest1", maxViews: 10 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 1);
|
assert.strictEqual(data.segmentCount, 1);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -158,11 +156,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter segments by min and max views", (done: Done) => {
|
it("Should be able to filter segments by min and max views", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest1&maxViews=10&minViews=1`)
|
client.get(endpoint, { params: { videoID: "searchTest1", maxViews: 10, minViews: 1 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 1);
|
assert.strictEqual(data.segmentCount, 1);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -172,11 +170,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter segments by min votes", (done: Done) => {
|
it("Should be able to filter segments by min votes", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest2&minVotes=0`)
|
client.get(endpoint, { params: { videoID: "searchTest2", minVotes: 0 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 2);
|
assert.strictEqual(data.segmentCount, 2);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -187,11 +185,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter segments by max votes", (done: Done) => {
|
it("Should be able to filter segments by max votes", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest2&maxVotes=10`)
|
client.get(endpoint, { params: { videoID: "searchTest2", maxVotes: 10 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 2);
|
assert.strictEqual(data.segmentCount, 2);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -202,11 +200,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to filter segments by both min and max votes", (done: Done) => {
|
it("Should be able to filter segments by both min and max votes", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest2&maxVotes=10&minVotes=0`)
|
client.get(endpoint, { params: { videoID: "searchTest2", maxVotes: 10, minVotes: 0 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 1);
|
assert.strictEqual(data.segmentCount, 1);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -216,11 +214,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get first page of results", (done: Done) => {
|
it("Should be able to get first page of results", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest4`)
|
client.get(endpoint, { params: { videoID: "searchTest4" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 12);
|
assert.strictEqual(data.segmentCount, 12);
|
||||||
assert.strictEqual(data.page, 0);
|
assert.strictEqual(data.page, 0);
|
||||||
|
@ -239,11 +237,11 @@ describe("getSearchSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get second page of results", (done: Done) => {
|
it("Should be able to get second page of results", (done) => {
|
||||||
fetch(`${endpoint}?videoID=searchTest4&page=1`)
|
client.get(endpoint, { params: { videoID: "searchTest4", page: 1 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const segments = data.segments;
|
const segments = data.segments;
|
||||||
assert.strictEqual(data.segmentCount, 12);
|
assert.strictEqual(data.segmentCount, 12);
|
||||||
assert.strictEqual(data.page, 1);
|
assert.strictEqual(data.page, 1);
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const ENOENTID = "0".repeat(64);
|
const ENOENTID = "0".repeat(64);
|
||||||
const upvotedID = `a${"0".repeat(63)}`;
|
const upvotedID = `a${"0".repeat(63)}`;
|
||||||
|
@ -27,8 +25,10 @@ const userAgents = {
|
||||||
blank: ""
|
blank: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const endpoint = "/api/segmentInfo";
|
||||||
|
const singleUUIDLookup = (UUID: string) => client.get(endpoint, { params: { UUID } });
|
||||||
|
|
||||||
describe("getSegmentInfo", () => {
|
describe("getSegmentInfo", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/segmentInfo`;
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertQuery = `INSERT INTO
|
const insertQuery = `INSERT INTO
|
||||||
"sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked",
|
"sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked",
|
||||||
|
@ -49,154 +49,146 @@ describe("getSegmentInfo", () => {
|
||||||
await db.prepare("run", insertQuery, ["segmentInfoFiller", 5, 6, 1, 0, fillerID5, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoFiller", 5, 6, 1, 0, fillerID5, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive upvoted segment", (done: Done) => {
|
it("Should be able to retreive upvoted segment", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${upvotedID}`)
|
singleUUIDLookup(upvotedID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoUpvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
userAgent: userAgents.vanced,
|
userAgent: userAgents.vanced,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive downvoted segment", (done: Done) => {
|
it("Should be able to retreive downvoted segment", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${downvotedID}`)
|
singleUUIDLookup(downvotedID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoDownvoted",
|
videoID: "segmentInfoDownvoted",
|
||||||
votes: -2,
|
votes: -2,
|
||||||
userAgent: userAgents.meabot,
|
userAgent: userAgents.meabot,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive locked up segment", (done: Done) => {
|
it("Should be able to retreive locked up segment", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${lockedupID}`)
|
singleUUIDLookup(lockedupID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoLockedup",
|
videoID: "segmentInfoLockedup",
|
||||||
locked: 1,
|
locked: 1,
|
||||||
votes: 2,
|
votes: 2,
|
||||||
userAgent: userAgents.mpv,
|
userAgent: userAgents.mpv,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive infinite vote segment", (done: Done) => {
|
it("Should be able to retreive infinite vote segment", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${infvotesID}`)
|
singleUUIDLookup(infvotesID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoInfvotes",
|
videoID: "segmentInfoInfvotes",
|
||||||
votes: 100000,
|
votes: 100000,
|
||||||
userAgent: userAgents.nodesb,
|
userAgent: userAgents.nodesb,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive shadowhidden segment", (done: Done) => {
|
it("Should be able to retreive shadowhidden segment", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${shadowhiddenID}`)
|
singleUUIDLookup(shadowhiddenID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoShadowhidden",
|
videoID: "segmentInfoShadowhidden",
|
||||||
shadowHidden: 1,
|
shadowHidden: 1,
|
||||||
userAgent: userAgents.blank,
|
userAgent: userAgents.blank,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive locked down segment", (done: Done) => {
|
it("Should be able to retreive locked down segment", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${lockeddownID}`)
|
singleUUIDLookup(lockeddownID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoLockedown",
|
videoID: "segmentInfoLockedown",
|
||||||
locked: 1,
|
locked: 1,
|
||||||
votes: -2,
|
votes: -2,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive hidden segment", (done: Done) => {
|
it("Should be able to retreive hidden segment", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${hiddenID}`)
|
singleUUIDLookup(hiddenID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoHidden",
|
videoID: "segmentInfoHidden",
|
||||||
hidden: 1,
|
hidden: 1,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive segment with old ID", (done: Done) => {
|
it("Should be able to retreive segment with old ID", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${oldID}`)
|
singleUUIDLookup(oldID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoOldID",
|
videoID: "segmentInfoOldID",
|
||||||
votes: 1,
|
votes: 1,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive single segment in array", (done: Done) => {
|
it("Should be able to retreive single segment in array", (done) => {
|
||||||
fetch(`${endpoint}?UUIDs=["${upvotedID}"]`)
|
client.get(endpoint, { params: { UUIDs: `["${upvotedID}"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoUpvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
}];
|
}];
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive multiple segments in array", (done: Done) => {
|
it("Should be able to retreive multiple segments in array", (done) => {
|
||||||
fetch(`${endpoint}?UUIDs=["${upvotedID}", "${downvotedID}"]`)
|
client.get(endpoint, { params: { UUIDs: `["${upvotedID}", "${downvotedID}"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoUpvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
|
@ -211,11 +203,11 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
it("Should be possible to send unexpected query parameters", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${upvotedID}&fakeparam=hello&category=sponsor`)
|
client.get(endpoint, { params: { UUID: upvotedID, fakeparam: "hello", category: "sponsor" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoUpvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
|
@ -226,8 +218,8 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if array passed to UUID", (done: Done) => {
|
it("Should return 400 if array passed to UUID", (done) => {
|
||||||
fetch(`${endpoint}?UUID=["${upvotedID}", "${downvotedID}"]`)
|
client.get(`${endpoint}?UUID=["${upvotedID}", "${downvotedID}"]`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -235,8 +227,8 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if bad array passed to UUIDs", (done: Done) => {
|
it("Should return 400 if bad array passed to UUIDs", (done) => {
|
||||||
fetch(`${endpoint}?UUIDs=[not-quoted,not-quoted]`)
|
client.get(`${endpoint}?UUIDs=[not-quoted,not-quoted]`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -244,8 +236,8 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if bad UUID passed", (done: Done) => {
|
it("Should return 400 if bad UUID passed", (done) => {
|
||||||
fetch(`${endpoint}?UUID=notarealuuid`)
|
client.get(`${endpoint}?UUID=notarealuuid`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -253,8 +245,8 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if bad UUIDs passed in array", (done: Done) => {
|
it("Should return 400 if bad UUIDs passed in array", (done) => {
|
||||||
fetch(`${endpoint}?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
|
client.get(`${endpoint}?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -262,11 +254,11 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return good UUID when mixed with bad UUIDs", (done: Done) => {
|
it("Should return good UUID when mixed with bad UUIDs", (done) => {
|
||||||
fetch(`${endpoint}?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
|
client.get(`${endpoint}?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoUpvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
|
@ -278,13 +270,13 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should cut off array at 10", function(done: Done) {
|
it("Should cut off array at 10", function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
const filledIDArray = `["${upvotedID}", "${downvotedID}", "${lockedupID}", "${shadowhiddenID}", "${lockeddownID}", "${hiddenID}", "${fillerID1}", "${fillerID2}", "${fillerID3}", "${fillerID4}", "${fillerID5}"]`;
|
const filledIDArray = `["${upvotedID}", "${downvotedID}", "${lockedupID}", "${shadowhiddenID}", "${lockeddownID}", "${hiddenID}", "${fillerID1}", "${fillerID2}", "${fillerID3}", "${fillerID4}", "${fillerID5}"]`;
|
||||||
fetch(`${endpoint}?UUIDs=${filledIDArray}`)
|
client.get(endpoint, { params: { UUIDs: filledIDArray }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 10);
|
assert.strictEqual(data.length, 10);
|
||||||
assert.strictEqual(data[0].videoID, "segmentInfoUpvoted");
|
assert.strictEqual(data[0].videoID, "segmentInfoUpvoted");
|
||||||
assert.strictEqual(data[0].votes, 2);
|
assert.strictEqual(data[0].votes, 2);
|
||||||
|
@ -295,19 +287,18 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not duplicate reponses", (done: Done) => {
|
it("Should not duplicate reponses", (done) => {
|
||||||
fetch(`${endpoint}?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
|
client.get(`${endpoint}?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
assert.strictEqual(res.data.length, 2);
|
||||||
assert.strictEqual(data.length, 2);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if UUID not found", (done: Done) => {
|
it("Should return 400 if UUID not found", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${ENOENTID}`)
|
client.get(endpoint, { params: { UUID: ENOENTID }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status !== 400) done(`non 400 response code: ${res.status}`);
|
if (res.status !== 400) done(`non 400 response code: ${res.status}`);
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
|
@ -315,11 +306,11 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive multiple segments with multiple parameters", (done: Done) => {
|
it("Should be able to retreive multiple segments with multiple parameters", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${upvotedID}&UUID=${downvotedID}`)
|
client.get(`${endpoint}?UUID=${upvotedID}&UUID=${downvotedID}`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoUpvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
|
@ -334,16 +325,15 @@ describe("getSegmentInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not parse repeated UUID if UUIDs present", (done: Done) => {
|
it("Should not parse repeated UUID if UUIDs present", (done) => {
|
||||||
fetch(`${endpoint}?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
|
client.get(`${endpoint}?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "segmentInfoUpvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2
|
votes: 2
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { getService } from "../../src/utils/getService";
|
import { getService } from "../../src/utils/getService";
|
||||||
import { Service } from "../../src/types/segments.model";
|
import { Service } from "../../src/types/segments.model";
|
||||||
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
describe("getService", () => {
|
describe("getService", () => {
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
describe("getSkipSegments", () => {
|
describe("getSkipSegments", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/skipSegments`;
|
const endpoint = "/api/skipSegments";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", query, ["getSkipSegmentID0", 1, 11, 2, 0, "uuid01", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0]);
|
await db.prepare("run", query, ["getSkipSegmentID0", 1, 11, 2, 0, "uuid01", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0]);
|
||||||
|
@ -28,12 +26,11 @@ describe("getSkipSegments", () => {
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should be able to get a time by category 1", (done) => {
|
||||||
it("Should be able to get a time by category 1", (done: Done) => {
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "sponsor" }})
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor`)
|
.then(res => {
|
||||||
.then(async res => {
|
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
assert.strictEqual(data[0].segment[0], 1);
|
assert.strictEqual(data[0].segment[0], 1);
|
||||||
assert.strictEqual(data[0].segment[1], 11);
|
assert.strictEqual(data[0].segment[1], 11);
|
||||||
|
@ -45,11 +42,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category and action type", (done: Done) => {
|
it("Should be able to get a time by category and action type", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionType=mute`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "sponsor", actionType: "mute" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [12, 14],
|
segment: [12, 14],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
|
@ -63,11 +60,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category and getSkipSegmentMultiple action types", (done: Done) => {
|
it("Should be able to get a time by category and getSkipSegmentMultiple action types", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionType=mute&actionType=skip`)
|
client.get(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionType=mute&actionType=skip`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
|
@ -83,11 +80,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category and getSkipSegmentMultiple action types (JSON array)", (done: Done) => {
|
it("Should be able to get a time by category and getSkipSegmentMultiple action types (JSON array)", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionTypes=["mute","skip"]`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "sponsor", actionTypes: `["mute","skip"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
|
@ -102,11 +99,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category for a different service 1", (done: Done) => {
|
it("Should be able to get a time by category for a different service 1", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID1&category=sponsor&service=PeerTube`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID1", category: "sponsor", service: "PeerTube" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
|
@ -120,28 +117,29 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category 2", (done: Done) => {
|
it("Should be able to get a time by category 2", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=intro`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "intro" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "uuid03"
|
UUID: "uuid03"
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data.length, 1);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by categories array", (done: Done) => {
|
it("Should be able to get a time by categories array", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor"]`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `["sponsor"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
|
@ -149,17 +147,17 @@ describe("getSkipSegments", () => {
|
||||||
videoDuration: 100
|
videoDuration: 100
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data.length, 1);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by categories array 2", (done: Done) => {
|
it("Should be able to get a time by categories array 2", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["intro"]`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `["intro"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
|
@ -167,14 +165,13 @@ describe("getSkipSegments", () => {
|
||||||
videoDuration: 101
|
videoDuration: 101
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data.length, 1);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 404 if all submissions are hidden", (done: Done) => {
|
it("Should return 404 if all submissions are hidden", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID6`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID6" }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -182,11 +179,12 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get getSkipSegmentMultiple times by category", (done: Done) => {
|
it("Should be able to get getSkipSegmentMultiple times by category", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentMultiple&categories=["intro"]`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentMultiple", categories: `["intro"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
|
@ -197,17 +195,17 @@ describe("getSkipSegments", () => {
|
||||||
UUID: "uuid41",
|
UUID: "uuid41",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data.length, 2);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get getSkipSegmentMultiple times by getSkipSegmentMultiple categories", (done: Done) => {
|
it("Should be able to get getSkipSegmentMultiple times by getSkipSegmentMultiple categories", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor", "intro"]`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `["sponsor", "intro"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
|
@ -218,17 +216,16 @@ describe("getSkipSegments", () => {
|
||||||
UUID: "uuid03",
|
UUID: "uuid03",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data.length, 2);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
it("Should be possible to send unexpected query parameters", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&fakeparam=hello&category=sponsor`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", fakeparam: "hello", category: "sponsor" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
|
@ -241,11 +238,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Low voted submissions should be hidden", (done: Done) => {
|
it("Low voted submissions should be hidden", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID3&category=sponsor`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID3", category: "sponsor" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
|
@ -258,8 +255,8 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 404 if no segment found", (done: Done) => {
|
it("Should return 404 if no segment found", (done) => {
|
||||||
fetch(`${endpoint}?videoID=notarealvideo`)
|
client.get(endpoint, { params: { videoID: "notarealvideo" }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -267,8 +264,8 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if bad categories argument", (done: Done) => {
|
it("Should return 400 if bad categories argument", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=[not-quoted,not-quoted]`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `[not-quoted,not-quoted]` }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -276,11 +273,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able send a comma in a query param", (done: Done) => {
|
it("Should be able send a comma in a query param", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID2&category=sponsor`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID2", category: "sponsor" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
|
@ -293,11 +290,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should always get getSkipSegmentLocked segment", (done: Done) => {
|
it("Should always get getSkipSegmentLocked segment", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentLocked&category=intro`)
|
client.get(endpoint, { params: { videoID: "getSkipSegmentLocked", category: "intro" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
|
@ -310,11 +307,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get getSkipSegmentMultiple categories with repeating parameters", (done: Done) => {
|
it("Should be able to get getSkipSegmentMultiple categories with repeating parameters", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&category=intro`)
|
client.get(`${endpoint}?category=sponsor&category=intro`, { params: { videoID: "getSkipSegmentID0" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
|
@ -331,11 +328,11 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get, categories param overriding repeating category", (done: Done) => {
|
it("Should be able to get, categories param overriding repeating category", (done) => {
|
||||||
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor"]&category=intro`)
|
client.get(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor"]&category=intro`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
|
@ -348,13 +345,13 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get specific segments with requiredSegments", (done: Done) => {
|
it("Should be able to get specific segments with requiredSegments", (done) => {
|
||||||
const required2 = "requiredSegmentVid2";
|
const required2 = "requiredSegmentVid2";
|
||||||
const required3 = "requiredSegmentVid3";
|
const required3 = "requiredSegmentVid3";
|
||||||
fetch(`${endpoint}?videoID=requiredSegmentVid&requiredSegments=["${required2}","${required3}"]`)
|
client.get(endpoint, { params: { videoID: "requiredSegmentVid", requiredSegments: `["${required2}","${required3}"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
UUID: required2,
|
UUID: required2,
|
||||||
|
@ -367,13 +364,13 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get specific segments with repeating requiredSegment", (done: Done) => {
|
it("Should be able to get specific segments with repeating requiredSegment", (done) => {
|
||||||
const required2 = "requiredSegmentVid2";
|
const required2 = "requiredSegmentVid2";
|
||||||
const required3 = "requiredSegmentVid3";
|
const required3 = "requiredSegmentVid3";
|
||||||
fetch(`${endpoint}?videoID=requiredSegmentVid&requiredSegment=${required2}&requiredSegment=${required3}`)
|
client.get(`${endpoint}?videoID=requiredSegmentVid&requiredSegment=${required2}&requiredSegment=${required3}`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
UUID: required2,
|
UUID: required2,
|
||||||
|
@ -386,9 +383,9 @@ describe("getSkipSegments", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get 400 if no videoID passed in", (done: Done) => {
|
it("Should get 400 if no videoID passed in", (done) => {
|
||||||
fetch(`${endpoint}`)
|
client.get(endpoint)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import { Done, postJSON } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
import {getHash} from "../../src/utils/getHash";
|
import {getHash} from "../../src/utils/getHash";
|
||||||
import {ImportMock,} from "ts-mock-imports";
|
import {ImportMock,} from "ts-mock-imports";
|
||||||
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
|
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
|
||||||
import {YouTubeApiMock} from "../youtubeMock";
|
import {YouTubeApiMock} from "../youtubeMock";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
||||||
const sinonStub = mockManager.mock("listVideos");
|
const sinonStub = mockManager.mock("listVideos");
|
||||||
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
||||||
|
|
||||||
describe("getSkipSegmentsByHash", () => {
|
describe("getSkipSegmentsByHash", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/skipSegments`;
|
const endpoint = "/api/skipSegments";
|
||||||
const getSegmentsByHash0Hash = "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910";
|
const getSegmentsByHash0Hash = "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910";
|
||||||
const requiredSegmentVidHash = "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61";
|
const requiredSegmentVidHash = "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -34,8 +32,8 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, "requiredSegmentVid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash]);
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, "requiredSegmentVid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done) => {
|
||||||
fetch(`${endpoint}/3272f?categories=["sponsor", "intro"]`)
|
client.get(`${endpoint}/3272f`, { params: { categories: `["sponsor", "intro"]` }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
|
@ -43,46 +41,42 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 404 if no segments are found even if a video for the given hash is known", (done: Done) => {
|
it("Should return 404 if no segments are found even if a video for the given hash is known", (done) => {
|
||||||
fetch(`${endpoint}/3272f?categories=["shilling"]`)
|
client.get(`${endpoint}/3272f`, { params: { categories: `["shilling"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
const expected = "[]";
|
assert.equal(res.data.length, 0);
|
||||||
const body = await res.text();
|
|
||||||
assert.strictEqual(body, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get an empty array if no videos", (done: Done) => {
|
it("Should be able to get an empty array if no videos", (done) => {
|
||||||
fetch(`${endpoint}/11111?categories=["shilling"]`)
|
client.get(`${endpoint}/11111`, { params: { categories: `["shilling"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
const body = await res.text();
|
const body = res.data;
|
||||||
const expected = "[]";
|
assert.strictEqual(body.length, 0);
|
||||||
assert.strictEqual(JSON.parse(body).length, 0);
|
|
||||||
assert.strictEqual(body, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get an empty array if only hidden videos", (done: Done) => {
|
it("Should be able to get an empty array if only hidden videos", (done) => {
|
||||||
fetch(`${endpoint}/f3a1?categories=["sponsor"]`)
|
client.get(`${endpoint}/f3a1`, { params: { categories:`["sponsor"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
if (res.status !== 404) done(`non 404 status code, was ${res.status}`);
|
if (res.status !== 404) done(`non 404 status code, was ${res.status}`);
|
||||||
else {
|
else {
|
||||||
const body = await res.text();
|
const body = res.data;
|
||||||
if (JSON.parse(body).length === 0 && body === "[]") done(); // pass
|
if (body.length === 0) done(); // pass
|
||||||
else done("non empty array returned");
|
else done("non empty array returned");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 prefix too short", (done: Done) => {
|
it("Should return 400 prefix too short", (done) => {
|
||||||
fetch(`${endpoint}/11?categories=["shilling"]`)
|
client.get(`${endpoint}/11`, { params: { categories: `["shilling"]` }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -90,10 +84,10 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 prefix too long", (done: Done) => {
|
it("Should return 400 prefix too long", (done) => {
|
||||||
const prefix = "1".repeat(50);
|
const prefix = "1".repeat(50);
|
||||||
assert.ok(prefix.length > 33, "failed to generate long enough string");
|
assert.ok(prefix.length > 33, "failed to generate long enough string");
|
||||||
fetch(`${endpoint}/${prefix}?categories=["shilling"]`)
|
client.get(`${endpoint}/${prefix}`, { params: { categories: `["shilling"]` }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -101,9 +95,9 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 404 prefix in range", (done: Done) => {
|
it("Should return 404 prefix in range", (done) => {
|
||||||
const prefix = "1".repeat(5);
|
const prefix = "1".repeat(5);
|
||||||
fetch(`${endpoint}/${prefix}?categories=["shilling"]`)
|
client.get(`${endpoint}/${prefix}`, { params: { categories: `["shilling"]` }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -111,8 +105,8 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for no hash", (done: Done) => {
|
it("Should return 400 for no hash", (done) => {
|
||||||
fetch(`${endpoint}/?categories=["shilling"]`)
|
client.get(`${endpoint}`, { params: { categories: `["shilling"]` }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -120,8 +114,8 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for bad format categories", (done: Done) => {
|
it("Should return 400 for bad format categories", (done) => {
|
||||||
fetch(`${endpoint}/fdaf?categories=shilling`)
|
client.get(`${endpoint}/fdaf`, { params: { categories: "shilling" }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -129,11 +123,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple videos", (done: Done) => {
|
it("Should be able to get multiple videos", (done) => {
|
||||||
fetch(`${endpoint}/fdaf?categories=["sponsor","intro"]`)
|
client.get(`${endpoint}/fdaf`, { params: { categories: `["sponsor","intro"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
assert.strictEqual(data[0].segments.length, 2);
|
assert.strictEqual(data[0].segments.length, 2);
|
||||||
assert.strictEqual(data[1].segments.length, 1);
|
assert.strictEqual(data[1].segments.length, 1);
|
||||||
|
@ -142,12 +136,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get 200 for no categories (default sponsor)", (done: Done) => {
|
it("Should be able to get 200 for no categories (default sponsor)", (done) => {
|
||||||
fetch(`${endpoint}/fdaf`)
|
client.get(`${endpoint}/fdaf`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
|
@ -158,6 +151,7 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}]
|
}]
|
||||||
}];
|
}];
|
||||||
|
assert.strictEqual(data.length, 2);
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data[0].segments.length, 1);
|
assert.strictEqual(data[0].segments.length, 1);
|
||||||
assert.strictEqual(data[1].segments.length, 1);
|
assert.strictEqual(data[1].segments.length, 1);
|
||||||
|
@ -166,11 +160,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get 200 for no categories (default sponsor) with action type", (done: Done) => {
|
it("Should be able to get 200 for no categories (default sponsor) with action type", (done) => {
|
||||||
fetch(`${endpoint}/fdaf?actionType=skip`)
|
client.get(`${endpoint}/fdaf`, { params: { actionType: "skip" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
assert.strictEqual(data[0].segments.length, 1);
|
assert.strictEqual(data[0].segments.length, 1);
|
||||||
assert.strictEqual(data[1].segments.length, 1);
|
assert.strictEqual(data[1].segments.length, 1);
|
||||||
|
@ -190,11 +184,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get 200 for no categories (default sponsor) with multiple action types", (done: Done) => {
|
it("Should be able to get 200 for no categories (default sponsor) with multiple action types", (done) => {
|
||||||
fetch(`${endpoint}/fdaf?actionType=skip&actionType=mute`)
|
client.get(`${endpoint}/fdaf?actionType=skip&actionType=mute`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
assert.strictEqual(data[0].segments.length, 2);
|
assert.strictEqual(data[0].segments.length, 2);
|
||||||
assert.strictEqual(data[1].segments.length, 1);
|
assert.strictEqual(data[1].segments.length, 1);
|
||||||
|
@ -216,11 +210,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get 200 for no categories (default sponsor) with multiple action types (JSON array)", (done: Done) => {
|
it("Should be able to get 200 for no categories (default sponsor) with multiple action types (JSON array)", (done) => {
|
||||||
fetch(`${endpoint}/fdaf?actionTypes=["skip","mute"]`)
|
client.get(`${endpoint}/fdaf?actionTypes=["skip","mute"]`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
|
@ -240,11 +234,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get 200 for no categories (default sponsor) for a non YouTube service", (done: Done) => {
|
it("Should be able to get 200 for no categories (default sponsor) for a non YouTube service", (done) => {
|
||||||
fetch(`${endpoint}/fdaf?service=PeerTube`)
|
client.get(`${endpoint}/fdaf`, { params: { service: "PeerTube" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
|
@ -258,11 +252,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should only return one segment when fetching highlight segments", (done: Done) => {
|
it("Should only return one segment when fetching highlight segments", (done) => {
|
||||||
fetch(`${endpoint}/c962?category=poi_highlight`)
|
client.get(`${endpoint}/c962`, { params: { category: "poi_highlight" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
assert.strictEqual(data[0].segments.length, 1);
|
assert.strictEqual(data[0].segments.length, 1);
|
||||||
done();
|
done();
|
||||||
|
@ -270,24 +264,21 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to post a segment and get it using endpoint", (done: Done) => {
|
it("Should be able to post a segment and get it using endpoint", (done) => {
|
||||||
const testID = "abc123goodVideo";
|
const testID = "abc123goodVideo";
|
||||||
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
|
client.post("/api/skipSegments", {
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: "test-qwertyuiopasdfghjklzxcvbnm",
|
userID: "test-qwertyuiopasdfghjklzxcvbnm",
|
||||||
videoID: testID,
|
videoID: testID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [13, 17],
|
segment: [13, 17],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(() => {
|
||||||
fetch(`${endpoint}/${getHash(testID, 1).substring(0, 3)}`)
|
client.get(`${endpoint}/${getHash(testID, 1).substring(0, 3)}`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
|
@ -303,11 +294,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(`(post) ${err}`));
|
.catch(err => done(`(post) ${err}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple categories with repeating parameters", (done: Done) => {
|
it("Should be able to get multiple categories with repeating parameters", (done) => {
|
||||||
fetch(`${endpoint}/fdaff4?&category=sponsor&category=intro`)
|
client.get(`${endpoint}/fdaff4?&category=sponsor&category=intro`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
|
@ -326,11 +317,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get specific segments with requiredSegments", (done: Done) => {
|
it("Should be able to get specific segments with requiredSegments", (done) => {
|
||||||
fetch(`${endpoint}/d518?requiredSegments=["requiredSegmentVid-2","requiredSegmentVid-3"]`)
|
client.get(`${endpoint}/d518?requiredSegments=["requiredSegmentVid-2","requiredSegmentVid-3"]`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
|
@ -346,11 +337,11 @@ describe("getSkipSegmentsByHash", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get specific segments with repeating requiredSegment", (done: Done) => {
|
it("Should be able to get specific segments with repeating requiredSegment", (done) => {
|
||||||
fetch(`${endpoint}/d518?requiredSegment=requiredSegmentVid-2&requiredSegment=requiredSegmentVid-3`)
|
client.get(`${endpoint}/d518?requiredSegment=requiredSegmentVid-2&requiredSegment=requiredSegmentVid-3`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
assert.strictEqual(data[0].segments.length, 2);
|
assert.strictEqual(data[0].segments.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
let dbVersion: number;
|
let dbVersion: number;
|
||||||
|
|
||||||
describe("getStatus", () => {
|
describe("getStatus", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/status`;
|
const endpoint = "/api/status";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
|
dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get status", (done: Done) => {
|
it("Should be able to get status", (done) => {
|
||||||
fetch(endpoint)
|
client.get(endpoint)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.ok(data.uptime); // uptime should be greater than 1s
|
assert.ok(data.uptime); // uptime should be greater than 1s
|
||||||
assert.strictEqual(data.commit, "test");
|
assert.strictEqual(data.commit, "test");
|
||||||
assert.strictEqual(data.db, Number(dbVersion));
|
assert.strictEqual(data.db, Number(dbVersion));
|
||||||
|
@ -26,57 +24,52 @@ describe("getStatus", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get uptime only", (done: Done) => {
|
it("Should be able to get uptime only", (done) => {
|
||||||
fetch(`${endpoint}/uptime`)
|
client.get(`${endpoint}/uptime`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
assert.ok(Number(res.data) >= 1); // uptime should be greater than 1s
|
||||||
assert.ok(Number(data) >= 1); // uptime should be greater than 1s
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get commit only", (done: Done) => {
|
it("Should be able to get commit only", (done) => {
|
||||||
fetch(`${endpoint}/commit`)
|
client.get(`${endpoint}/commit`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
assert.strictEqual(res.data, "test"); // commit should be test
|
||||||
assert.strictEqual(data, "test"); // commit should be test
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get db only", (done: Done) => {
|
it("Should be able to get db only", (done) => {
|
||||||
fetch(`${endpoint}/db`)
|
client.get(`${endpoint}/db`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
assert.strictEqual(Number(res.data), Number(dbVersion)); // commit should be test
|
||||||
assert.strictEqual(Number(data), Number(dbVersion)); // commit should be test
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get startTime only", (done: Done) => {
|
it("Should be able to get startTime only", (done) => {
|
||||||
fetch(`${endpoint}/startTime`)
|
client.get(`${endpoint}/startTime`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
assert.ok(Number(data) <= now); // startTime should be more than now
|
assert.ok(Number(res.data) <= now); // startTime should be more than now
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get processTime only", (done: Done) => {
|
it("Should be able to get processTime only", (done) => {
|
||||||
fetch(`${endpoint}/processTime`)
|
client.get(`${endpoint}/processTime`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.text();
|
assert.ok(Number(res.data) >= 0);
|
||||||
assert.ok(Number(data) >= 0);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
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";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
|
||||||
|
const endpoint = "/api/userID";
|
||||||
|
const getUserName = (username: string): Promise<AxiosResponse> => client.get(endpoint, { params: { username }});
|
||||||
|
|
||||||
describe("getUserID", () => {
|
describe("getUserID", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/userID`;
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
|
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
|
||||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_01"), "fuzzy user 01"]);
|
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_01"), "fuzzy user 01"]);
|
||||||
|
@ -23,17 +24,17 @@ describe("getUserID", () => {
|
||||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_12"), "a"]);
|
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_12"), "a"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done) => {
|
||||||
fetch(`${endpoint}?username=fuzzy+user+01`)
|
getUserName("fuzzy user 01")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 400 (No username parameter)", (done: Done) => {
|
it("Should be able to get a 400 (No username parameter)", (done) => {
|
||||||
fetch(endpoint)
|
client.get(endpoint)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -41,17 +42,17 @@ describe("getUserID", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200 (username is public id)", (done: Done) => {
|
it("Should be able to get a 200 (username is public id)", (done) => {
|
||||||
fetch(`${endpoint}?username=${getHash("getuserid_user_06")}`)
|
client.get(endpoint, { params: { username: getHash("getuserid_user_06") }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 400 (username longer than 64 chars)", (done: Done) => {
|
it("Should be able to get a 400 (username longer than 64 chars)", (done) => {
|
||||||
fetch(`${endpoint}?username=${getHash("getuserid_user_06")}0`)
|
client.get(endpoint, { params: { username: `${getHash("getuserid_user_06")}0` }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -59,24 +60,23 @@ describe("getUserID", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get single username", (done: Done) => {
|
it("Should be able to get single username", (done) => {
|
||||||
fetch(`${endpoint}?username=fuzzy+user+01`)
|
client.get(endpoint, { params: { username: "fuzzy user 01" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "fuzzy user 01",
|
userName: "fuzzy user 01",
|
||||||
userID: getHash("getuserid_user_01")
|
userID: getHash("getuserid_user_01")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple fuzzy user info from start", (done: Done) => {
|
it("Should be able to get multiple fuzzy user info from start", (done) => {
|
||||||
fetch(`${endpoint}?username=fuzzy+user`)
|
getUserName("fuzzy user")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "fuzzy user 01",
|
userName: "fuzzy user 01",
|
||||||
|
@ -85,16 +85,15 @@ describe("getUserID", () => {
|
||||||
userName: "fuzzy user 02",
|
userName: "fuzzy user 02",
|
||||||
userID: getHash("getuserid_user_02")
|
userID: getHash("getuserid_user_02")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple fuzzy user info from middle", (done: Done) => {
|
it("Should be able to get multiple fuzzy user info from middle", (done) => {
|
||||||
fetch(`${endpoint}?username=user`)
|
getUserName("user")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "fuzzy user 01",
|
userName: "fuzzy user 01",
|
||||||
|
@ -106,48 +105,45 @@ describe("getUserID", () => {
|
||||||
userName: "specific user 03",
|
userName: "specific user 03",
|
||||||
userID: getHash("getuserid_user_03")
|
userID: getHash("getuserid_user_03")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get with public ID", (done: Done) => {
|
it("Should be able to get with public ID", (done) => {
|
||||||
const userID = getHash("getuserid_user_06");
|
const userID = getHash("getuserid_user_06");
|
||||||
fetch(`${endpoint}?username=${userID}`)
|
getUserName(userID)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: userID,
|
userName: userID,
|
||||||
userID
|
userID
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get with fuzzy public ID", (done: Done) => {
|
it("Should be able to get with fuzzy public ID", (done) => {
|
||||||
const userID = getHash("getuserid_user_06");
|
const userID = getHash("getuserid_user_06");
|
||||||
fetch(`${endpoint}?username=${userID.substr(10,60)}`)
|
getUserName(userID.substr(10,60))
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: userID,
|
userName: userID,
|
||||||
userID
|
userID
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get repeating username", (done: Done) => {
|
it("Should be able to get repeating username", (done) => {
|
||||||
fetch(`${endpoint}?username=repeating`)
|
getUserName("repeating")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "repeating",
|
userName: "repeating",
|
||||||
|
@ -156,16 +152,15 @@ describe("getUserID", () => {
|
||||||
userName: "repeating",
|
userName: "repeating",
|
||||||
userID: getHash("getuserid_user_05")
|
userID: getHash("getuserid_user_05")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get repeating fuzzy username", (done: Done) => {
|
it("Should be able to get repeating fuzzy username", (done) => {
|
||||||
fetch(`${endpoint}?username=peat`)
|
getUserName("peat")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "repeating",
|
userName: "repeating",
|
||||||
|
@ -174,45 +169,42 @@ describe("getUserID", () => {
|
||||||
userName: "repeating",
|
userName: "repeating",
|
||||||
userID: getHash("getuserid_user_05")
|
userID: getHash("getuserid_user_05")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should avoid ReDOS with _", (done: Done) => {
|
it("should avoid ReDOS with _", (done) => {
|
||||||
fetch(`${endpoint}?username=_redos_`)
|
getUserName("_redos_")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "_redos_",
|
userName: "_redos_",
|
||||||
userID: getHash("getuserid_user_09")
|
userID: getHash("getuserid_user_09")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should avoid ReDOS with %", (done: Done) => {
|
it("should avoid ReDOS with %", (done) => {
|
||||||
fetch(`${endpoint}?username=%redos%`)
|
getUserName("%redos%")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "%redos%",
|
userName: "%redos%",
|
||||||
userID: getHash("getuserid_user_08")
|
userID: getHash("getuserid_user_08")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 404 if escaped backslashes present", (done: Done) => {
|
it("should return 404 if escaped backslashes present", (done) => {
|
||||||
fetch(`${endpoint}?username=%redos\\\\_`)
|
getUserName("%redos\\\\_")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -220,8 +212,8 @@ describe("getUserID", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 404 if backslashes present", (done: Done) => {
|
it("should return 404 if backslashes present", (done) => {
|
||||||
fetch(`${endpoint}?username=\\%redos\\_`)
|
getUserName(`\\%redos\\_`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -229,23 +221,22 @@ describe("getUserID", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return user if just backslashes", (done: Done) => {
|
it("should return user if just backslashes", (done) => {
|
||||||
fetch(`${endpoint}?username=\\\\\\`)
|
getUserName(`\\\\\\`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "\\\\\\",
|
userName: "\\\\\\",
|
||||||
userID: getHash("getuserid_user_11")
|
userID: getHash("getuserid_user_11")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not allow usernames more than 64 characters", (done: Done) => {
|
it("should not allow usernames more than 64 characters", (done) => {
|
||||||
fetch(`${endpoint}?username=${"0".repeat(65)}`)
|
getUserName("0".repeat(65))
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -253,8 +244,8 @@ describe("getUserID", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not allow usernames less than 3 characters", (done: Done) => {
|
it("should not allow usernames less than 3 characters", (done) => {
|
||||||
fetch(`${endpoint}?username=aa`)
|
getUserName("aa")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -262,24 +253,23 @@ describe("getUserID", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow exact match", (done: Done) => {
|
it("should allow exact match", (done) => {
|
||||||
fetch(`${endpoint}?username=a&exact=true`)
|
client.get(endpoint, { params: { username: "a", exact: true }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "a",
|
userName: "a",
|
||||||
userID: getHash("getuserid_user_12")
|
userID: getHash("getuserid_user_12")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get repeating username with exact username", (done: Done) => {
|
it("Should be able to get repeating username with exact username", (done) => {
|
||||||
fetch(`${endpoint}?username=repeating&exact=true`)
|
client.get(endpoint, { params: { username: "repeating", exact: true }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "repeating",
|
userName: "repeating",
|
||||||
|
@ -288,16 +278,15 @@ describe("getUserID", () => {
|
||||||
userName: "repeating",
|
userName: "repeating",
|
||||||
userID: getHash("getuserid_user_05")
|
userID: getHash("getuserid_user_05")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not get exact unless explicitly set to true", (done: Done) => {
|
it("Should not get exact unless explicitly set to true", (done) => {
|
||||||
fetch(`${endpoint}?username=user&exact=1`)
|
client.get(endpoint, { params: { username: "user", exact: 1 }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
userName: "fuzzy user 01",
|
userName: "fuzzy user 01",
|
||||||
|
@ -309,15 +298,14 @@ describe("getUserID", () => {
|
||||||
userName: "specific user 03",
|
userName: "specific user 03",
|
||||||
userID: getHash("getuserid_user_03")
|
userID: getHash("getuserid_user_03")
|
||||||
}];
|
}];
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 400 if no username parameter specified", (done: Done) => {
|
it("should return 400 if no username parameter specified", (done) => {
|
||||||
fetch(endpoint)
|
client.get(endpoint)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
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";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
describe("getUserInfo", () => {
|
describe("getUserInfo", () => {
|
||||||
const endpoint = `${getbaseURL()}/api/userInfo`;
|
const endpoint = "/api/userInfo";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
|
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
|
||||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserinfo_user_01"), "Username user 01"]);
|
await db.prepare("run", insertUserNameQuery, [getHash("getuserinfo_user_01"), "Username user 01"]);
|
||||||
|
@ -36,8 +34,8 @@ describe("getUserInfo", () => {
|
||||||
await db.prepare("run", insertBanQuery, [getHash("getuserinfo_ban_01")]);
|
await db.prepare("run", insertBanQuery, [getHash("getuserinfo_ban_01")]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_user_01`)
|
client.get(endpoint, { params: { userID: "getuserinfo_user_01" }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
|
@ -45,8 +43,8 @@ describe("getUserInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 400 (No userID parameter)", (done: Done) => {
|
it("Should be able to get a 400 (No userID parameter)", (done) => {
|
||||||
fetch(endpoint)
|
client.get(endpoint, { params: { userID: "" }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -54,9 +52,9 @@ describe("getUserInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get user info", (done: Done) => {
|
it("Should be able to get user info", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_user_01`)
|
client.get(endpoint, { params: { userID: "getuserinfo_user_01" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = {
|
const expected = {
|
||||||
userName: "Username user 01",
|
userName: "Username user 01",
|
||||||
|
@ -72,98 +70,91 @@ describe("getUserInfo", () => {
|
||||||
warnings: 0,
|
warnings: 0,
|
||||||
warningReason: ""
|
warningReason: ""
|
||||||
};
|
};
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get warning data", (done: Done) => {
|
it("Should get warning data", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_0&value=warnings`)
|
client.get(endpoint, { params: { userID: "getuserinfo_warning_0", value: "warnings" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warnings: 1
|
warnings: 1
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get warning data with public ID", (done: Done) => {
|
it("Should get warning data with public ID", (done) => {
|
||||||
fetch(`${endpoint}?publicUserID=${getHash("getuserinfo_warning_0")}&values=["warnings"]`)
|
client.get(endpoint, { params: { publicUserID: getHash("getuserinfo_warning_0"), values: `["warnings"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warnings: 1
|
warnings: 1
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get multiple warnings", (done: Done) => {
|
it("Should get multiple warnings", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_1&value=warnings`)
|
client.get(endpoint, { params: { userID: "getuserinfo_warning_1", value: "warnings" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warnings: 2
|
warnings: 2
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not get warnings if none", (done: Done) => {
|
it("Should not get warnings if none", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_2&value=warnings`)
|
client.get(endpoint, { params: { userID: "getuserinfo_warning_2", value: "warnings" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warnings: 0,
|
warnings: 0,
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should done(userID for userName (No userName set)", (done: Done) => {
|
it("Should done(userID for userName (No userName set)", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_user_02&value=userName`)
|
client.get(endpoint, { params: { userID: "getuserinfo_user_02", value: "userName" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
userName: "c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f"
|
userName: "c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f"
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return null segment if none", (done: Done) => {
|
it("Should return null segment if none", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_null&value=lastSegmentID`)
|
client.get(endpoint, { params: { userID: "getuserinfo_null", value: "lastSegmentID" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
assert.strictEqual(res.data.lastSegmentID, null);
|
||||||
assert.strictEqual(data.lastSegmentID, null);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return zeroes if userid does not exist", (done: Done) => {
|
it("Should return zeroes if userid does not exist", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_null&value=lastSegmentID`)
|
client.get(endpoint, { params: { userID: "getuserinfo_null", value: "lastSegmentID" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
for (const value in data) {
|
for (const value in data) {
|
||||||
if (data[value] === null && value !== "lastSegmentID") {
|
if (data[value] === null && value !== "lastSegmentID") {
|
||||||
done(`returned null for ${value}`);
|
done(`returned null for ${value}`);
|
||||||
|
@ -174,115 +165,108 @@ describe("getUserInfo", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get warning reason from from single enabled warning", (done: Done) => {
|
it("Should get warning reason from from single enabled warning", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_0&values=["warningReason"]`)
|
client.get(endpoint, { params: { userID: "getuserinfo_warning_0", values: `["warningReason"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warningReason: "warning0-0",
|
warningReason: "warning0-0",
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get most recent warning from two enabled warnings", (done: Done) => {
|
it("Should get most recent warning from two enabled warnings", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_1&value=warningReason`)
|
client.get(endpoint, { params: { userID: "getuserinfo_warning_1", value: "warningReason" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warningReason: "warning1-1"
|
warningReason: "warning1-1"
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not get disabled warning", (done: Done) => {
|
it("Should not get disabled warning", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_2&values=["warnings","warningReason"]`)
|
client.get(endpoint, { params: { userID: "getuserinfo_warning_2", values: `["warnings","warningReason"]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warnings: 0,
|
warnings: 0,
|
||||||
warningReason: ""
|
warningReason: ""
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not get newer disabled warning", (done: Done) => {
|
it("Should not get newer disabled warning", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_3&value=warnings&value=warningReason`)
|
client.get(`${endpoint}?userID=getuserinfo_warning_3&value=warnings&value=warningReason`)
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
warnings: 1,
|
warnings: 1,
|
||||||
warningReason: "warning3-0"
|
warningReason: "warning3-0"
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get 400 if bad values specified", (done: Done) => {
|
it("Should get 400 if bad values specified", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_warning_3&value=invalid-value`)
|
client.get(endpoint, { params: { userID: "getuserinfo_warning_3", value: "invalid-value" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get ban data for banned user (only appears when specifically requested)", (done: Done) => {
|
it("Should get ban data for banned user (only appears when specifically requested)", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_ban_01&value=banned`)
|
client.get(endpoint, { params: { userID: "getuserinfo_ban_01", value: "banned" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
banned: true
|
banned: true
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get ban data for unbanned user (only appears when specifically requested)", (done: Done) => {
|
it("Should get ban data for unbanned user (only appears when specifically requested)", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_notban_01&value=banned`)
|
client.get(endpoint, { params: { userID: "getuserinfo_notban_01", value: "banned" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
banned: false
|
banned: false
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should throw 400 on bad json in values", (done: Done) => {
|
it("Should throw 400 on bad json in values", (done) => {
|
||||||
fetch(`${endpoint}?userID=x&values=[userID]`)
|
client.get(endpoint, { params: { userID: "x", values: `[userID]` }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 200 on userID not found", (done: Done) => {
|
it("Should return 200 on userID not found", (done) => {
|
||||||
fetch(`${endpoint}?userID=notused-userid`)
|
client.get(endpoint, { params: { userID: "notused-userid" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
minutesSaved: 0,
|
minutesSaved: 0,
|
||||||
segmentCount: 0,
|
segmentCount: 0,
|
||||||
|
@ -294,15 +278,15 @@ describe("getUserInfo", () => {
|
||||||
reputation: 0,
|
reputation: 0,
|
||||||
vip: false,
|
vip: false,
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done(); // pass
|
done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should only count long segments as 10 minutes", (done: Done) => {
|
it("Should only count long segments as 10 minutes", (done) => {
|
||||||
fetch(`${endpoint}?userID=getuserinfo_user_03`)
|
client.get(endpoint, { params: { userID: "getuserinfo_user_03" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = {
|
const expected = {
|
||||||
userName: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
userName: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
||||||
|
@ -318,8 +302,7 @@ describe("getUserInfo", () => {
|
||||||
warnings: 0,
|
warnings: 0,
|
||||||
warningReason: ""
|
warningReason: ""
|
||||||
};
|
};
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
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";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
describe("getUserStats", () => {
|
describe("getUserStats", () => {
|
||||||
|
const endpoint = "/api/userStats";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
|
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
|
||||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserstats_user_01"), "Username user 01"]);
|
await db.prepare("run", insertUserNameQuery, [getHash("getuserstats_user_01"), "Username user 01"]);
|
||||||
|
@ -24,8 +23,8 @@ describe("getUserStats", () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 400 (No userID parameter)", (done: Done) => {
|
it("Should be able to get a 400 (No userID parameter)", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/userStats`)
|
client.get(endpoint)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -33,9 +32,9 @@ describe("getUserStats", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get all user info", (done: Done) => {
|
it("Should be able to get all user info", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/userStats?userID=getuserstats_user_01&fetchCategoryStats=true&fetchActionTypeStats=true`)
|
client.get(endpoint, { params: { userID: "getuserstats_user_01", fetchCategoryStats: true, fetchActionTypeStats: true }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const expected = {
|
const expected = {
|
||||||
userName: "Username user 01",
|
userName: "Username user 01",
|
||||||
|
@ -59,18 +58,17 @@ describe("getUserStats", () => {
|
||||||
segmentCount: 8
|
segmentCount: 8
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const data = await res.json();
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get all zeroes for invalid userid", (done: Done) => {
|
it("Should be able to get all zeroes for invalid userid", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/userStats?userID=getuserstats_user_invalid`)
|
client.get(endpoint, { params: { userID: "getuserstats_user_invalid" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
for (const value in data.overallStats) {
|
for (const value in data.overallStats) {
|
||||||
if (data[value]) {
|
if (data[value]) {
|
||||||
done(`returned non-zero for ${value}`);
|
done(`returned non-zero for ${value}`);
|
||||||
|
@ -81,11 +79,11 @@ describe("getUserStats", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get all zeroes for only ignored segments", (done: Done) => {
|
it("Should be able to get all zeroes for only ignored segments", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/userStats?userID=getuserstats_user_02`)
|
client.get(endpoint, { params: { userID: "getuserstats_user_02" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
for (const value in data.overallStats) {
|
for (const value in data.overallStats) {
|
||||||
if (data[value]) {
|
if (data[value]) {
|
||||||
done(`returned non-zero for ${value}`);
|
done(`returned non-zero for ${value}`);
|
||||||
|
@ -96,11 +94,11 @@ describe("getUserStats", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not get extra stats if not requested", (done: Done) => {
|
it("Should not get extra stats if not requested", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/userStats?userID=getuserstats_user_01`)
|
client.get(endpoint, { params: { userID: "getuserstats_user_01" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
// check for categoryCount
|
// check for categoryCount
|
||||||
if (data.categoryCount || data.actionTypeCount) {
|
if (data.categoryCount || data.actionTypeCount) {
|
||||||
done("returned extra stats");
|
done("returned extra stats");
|
||||||
|
@ -110,11 +108,11 @@ describe("getUserStats", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should get parts of extra stats if not requested", (done: Done) => {
|
it("Should get parts of extra stats if not requested", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/userStats?userID=getuserstats_user_01&fetchActionTypeStats=true`)
|
client.get(endpoint, { params: { userID: "getuserstats_user_01", fetchActionTypeStats: true }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
// check for categoryCount
|
// check for categoryCount
|
||||||
if (data.categoryCount && !data.actionTypeCount) {
|
if (data.categoryCount && !data.actionTypeCount) {
|
||||||
done("returned extra stats");
|
done("returned extra stats");
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done, postJSON } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
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";
|
import assert from "assert";
|
||||||
import {LockCategory } from "../../src/types/segments.model";
|
import {LockCategory } from "../../src/types/segments.model";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const stringDeepEquals = (a: string[] ,b: string[]): boolean => {
|
const stringDeepEquals = (a: string[] ,b: string[]): boolean => {
|
||||||
let result = true;
|
let result = true;
|
||||||
|
@ -14,8 +12,8 @@ const stringDeepEquals = (a: string[] ,b: string[]): boolean => {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const endpoint = `${getbaseURL()}/api/lockCategories`;
|
const endpoint = "/api/lockCategories";
|
||||||
const submitEndpoint = `${getbaseURL()}/api/skipSegments`;
|
const submitEndpoint = "/api/skipSegments";
|
||||||
const checkLockCategories = (videoID: string): Promise<LockCategory[]> => db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', [videoID]);
|
const checkLockCategories = (videoID: string): Promise<LockCategory[]> => db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', [videoID]);
|
||||||
const lockVIPUser = "lockCategoriesRecordsVIPUser";
|
const lockVIPUser = "lockCategoriesRecordsVIPUser";
|
||||||
const lockVIPUserHash = getHash(lockVIPUser);
|
const lockVIPUserHash = getHash(lockVIPUser);
|
||||||
|
@ -44,7 +42,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
assert.ok(version > 1);
|
assert.ok(version > 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit categories not in video (http response)", (done: Done) => {
|
it("Should be able to submit categories not in video (http response)", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "no-segments-video-id",
|
videoID: "no-segments-video-id",
|
||||||
userID: "lockCategoriesRecordsVIPUser",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
|
@ -63,20 +61,16 @@ describe("lockCategoriesRecords", () => {
|
||||||
"shilling",
|
"shilling",
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
.then(res => {
|
||||||
body: JSON.stringify(json)
|
|
||||||
})
|
|
||||||
.then(async res => {
|
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data, expected);
|
||||||
assert.deepStrictEqual(data, expected);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit categories not in video (sql check)", (done: Done) => {
|
it("Should be able to submit categories not in video (sql check)", (done) => {
|
||||||
const videoID = "no-segments-video-id-1";
|
const videoID = "no-segments-video-id-1";
|
||||||
const json = {
|
const json = {
|
||||||
videoID,
|
videoID,
|
||||||
|
@ -90,10 +84,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
"intro",
|
"intro",
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json)
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await checkLockCategories(videoID);
|
const result = await checkLockCategories(videoID);
|
||||||
|
@ -111,7 +102,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit categories not in video with reason (http response)", (done: Done) => {
|
it("Should be able to submit categories not in video with reason (http response)", (done) => {
|
||||||
const videoID = "no-segments-video-id";
|
const videoID = "no-segments-video-id";
|
||||||
const json = {
|
const json = {
|
||||||
videoID,
|
videoID,
|
||||||
|
@ -126,7 +117,6 @@ describe("lockCategoriesRecords", () => {
|
||||||
],
|
],
|
||||||
reason: "new reason"
|
reason: "new reason"
|
||||||
};
|
};
|
||||||
|
|
||||||
const expected = {
|
const expected = {
|
||||||
submitted: [
|
submitted: [
|
||||||
"outro",
|
"outro",
|
||||||
|
@ -135,20 +125,16 @@ describe("lockCategoriesRecords", () => {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
.then(res => {
|
||||||
body: JSON.stringify(json)
|
|
||||||
})
|
|
||||||
.then(async res => {
|
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
assert.deepStrictEqual(res.data.submitted, expected.submitted);
|
||||||
assert.deepStrictEqual(data.submitted, expected.submitted);
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit categories not in video with reason (sql check)", (done: Done) => {
|
it("Should be able to submit categories not in video with reason (sql check)", (done) => {
|
||||||
const videoID = "no-segments-video-id-1";
|
const videoID = "no-segments-video-id-1";
|
||||||
const json = {
|
const json = {
|
||||||
videoID,
|
videoID,
|
||||||
|
@ -170,10 +156,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
"intro"
|
"intro"
|
||||||
];
|
];
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json)
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await checkLockCategories(videoID);
|
const result = await checkLockCategories(videoID);
|
||||||
|
@ -192,7 +175,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit categories with _ in the category", (done: Done) => {
|
it("Should be able to submit categories with _ in the category", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "underscore",
|
videoID: "underscore",
|
||||||
userID: lockVIPUser,
|
userID: lockVIPUser,
|
||||||
|
@ -200,10 +183,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
"word_word",
|
"word_word",
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await checkLockCategories("underscore");
|
const result = await checkLockCategories("underscore");
|
||||||
|
@ -213,7 +193,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit categories with upper and lower case in the category", (done: Done) => {
|
it("Should be able to submit categories with upper and lower case in the category", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "bothCases",
|
videoID: "bothCases",
|
||||||
userID: lockVIPUser,
|
userID: lockVIPUser,
|
||||||
|
@ -221,10 +201,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
"wordWord",
|
"wordWord",
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await checkLockCategories("bothCases");
|
const result = await checkLockCategories("bothCases");
|
||||||
|
@ -234,7 +211,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to submit categories with $ in the category", (done: Done) => {
|
it("Should not be able to submit categories with $ in the category", (done) => {
|
||||||
const videoID = "specialChar";
|
const videoID = "specialChar";
|
||||||
const json = {
|
const json = {
|
||||||
videoID,
|
videoID,
|
||||||
|
@ -244,10 +221,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await checkLockCategories(videoID);
|
const result = await checkLockCategories(videoID);
|
||||||
|
@ -257,11 +231,8 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for missing params", (done: Done) => {
|
it("Should return 400 for missing params", (done) => {
|
||||||
fetch(endpoint, {
|
client.post(endpoint, {})
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({}),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -269,16 +240,13 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for no categories", (done: Done) => {
|
it("Should return 400 for no categories", (done) => {
|
||||||
const json: any = {
|
const json: any = {
|
||||||
videoID: "test",
|
videoID: "test",
|
||||||
userID: "test",
|
userID: "test",
|
||||||
categories: [],
|
categories: [],
|
||||||
};
|
};
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -286,17 +254,14 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for no userID", (done: Done) => {
|
it("Should return 400 for no userID", (done) => {
|
||||||
const json: any = {
|
const json = {
|
||||||
videoID: "test",
|
videoID: "test",
|
||||||
userID: null,
|
userID: null,
|
||||||
categories: ["sponsor"],
|
categories: ["sponsor"],
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -304,17 +269,14 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for no videoID", (done: Done) => {
|
it("Should return 400 for no videoID", (done) => {
|
||||||
const json: any = {
|
const json = {
|
||||||
videoID: null,
|
videoID: null,
|
||||||
userID: "test",
|
userID: "test",
|
||||||
categories: ["sponsor"],
|
categories: ["sponsor"],
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -322,17 +284,14 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 object categories", (done: Done) => {
|
it("Should return 400 object categories", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "test",
|
videoID: "test",
|
||||||
userID: "test",
|
userID: "test",
|
||||||
categories: {},
|
categories: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -340,17 +299,14 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 bad format categories", (done: Done) => {
|
it("Should return 400 bad format categories", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "test",
|
videoID: "test",
|
||||||
userID: "test",
|
userID: "test",
|
||||||
categories: "sponsor",
|
categories: "sponsor",
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
@ -358,7 +314,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 403 if user is not VIP", (done: Done) => {
|
it("Should return 403 if user is not VIP", (done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "test",
|
videoID: "test",
|
||||||
userID: "test",
|
userID: "test",
|
||||||
|
@ -367,10 +323,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.post(endpoint, json)
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
|
@ -378,7 +331,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to delete a lockCategories record", (done: Done) => {
|
it("Should be able to delete a lockCategories record", (done) => {
|
||||||
const videoID = "delete-record";
|
const videoID = "delete-record";
|
||||||
const json = {
|
const json = {
|
||||||
videoID,
|
videoID,
|
||||||
|
@ -388,13 +341,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.delete(endpoint, { data: json })
|
||||||
method: "DELETE",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await checkLockCategories(videoID);
|
const result = await checkLockCategories(videoID);
|
||||||
|
@ -404,7 +351,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to delete one lockCategories record without removing another", (done: Done) => {
|
it("Should be able to delete one lockCategories record without removing another", (done) => {
|
||||||
const videoID = "delete-record-1";
|
const videoID = "delete-record-1";
|
||||||
const json = {
|
const json = {
|
||||||
videoID,
|
videoID,
|
||||||
|
@ -414,13 +361,7 @@ describe("lockCategoriesRecords", () => {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(endpoint, {
|
client.delete(endpoint, { data: json })
|
||||||
method: "DELETE",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(json),
|
|
||||||
})
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const result = await checkLockCategories(videoID);
|
const result = await checkLockCategories(videoID);
|
||||||
|
@ -437,29 +378,24 @@ describe("lockCategoriesRecords", () => {
|
||||||
*/
|
*/
|
||||||
const lockedVideoID = "lockCategoryVideo";
|
const lockedVideoID = "lockCategoryVideo";
|
||||||
const testSubmitUser = "testman42-qwertyuiopasdfghjklzxcvbnm";
|
const testSubmitUser = "testman42-qwertyuiopasdfghjklzxcvbnm";
|
||||||
it("Should not be able to submit a segment to a video with a lock-category record (single submission)", (done: Done) => {
|
it("Should not be able to submit a segment to a video with a lock-category record (single submission)", (done) => {
|
||||||
fetch(submitEndpoint, {
|
client.post(submitEndpoint, {
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: testSubmitUser,
|
userID: testSubmitUser,
|
||||||
videoID: lockedVideoID,
|
videoID: lockedVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [20, 40],
|
segment: [20, 40],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not be able to submit segments to a video where any of the submissions with a no-segment record", (done: Done) => {
|
it("Should not be able to submit segments to a video where any of the submissions with a no-segment record", (done) => {
|
||||||
fetch(submitEndpoint, {
|
client.post(submitEndpoint, {
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: testSubmitUser,
|
userID: testSubmitUser,
|
||||||
videoID: lockedVideoID,
|
videoID: lockedVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
|
@ -468,10 +404,9 @@ describe("lockCategoriesRecords", () => {
|
||||||
}, {
|
}, {
|
||||||
segment: [50, 60],
|
segment: [50, 60],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}]
|
||||||
},),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
@ -479,45 +414,39 @@ describe("lockCategoriesRecords", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Should be able to submit a segment to a video with a different no-segment record", (done: Done) => {
|
it("Should be able to submit a segment to a video with a different no-segment record", (done) => {
|
||||||
fetch(submitEndpoint, {
|
client.post(submitEndpoint, {
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: testSubmitUser,
|
userID: testSubmitUser,
|
||||||
videoID: lockedVideoID,
|
videoID: lockedVideoID,
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [20, 40],
|
segment: [20, 40],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit a segment to a video with no no-segment records", (done: Done) => {
|
it("Should be able to submit a segment to a video with no no-segment records", (done) => {
|
||||||
fetch(submitEndpoint, {
|
client.post(submitEndpoint, {
|
||||||
...postJSON,
|
|
||||||
body: JSON.stringify({
|
|
||||||
userID: testSubmitUser,
|
userID: testSubmitUser,
|
||||||
videoID: "normalVideo",
|
videoID: "normalVideo",
|
||||||
segments: [{
|
segments: [{
|
||||||
segment: [20, 40],
|
segment: [20, 40],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
}],
|
}],
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be able to get existing category lock", (done: Done) => {
|
it("should be able to get existing category lock", (done) => {
|
||||||
const expected = {
|
const expected = {
|
||||||
categories: [
|
categories: [
|
||||||
"sponsor",
|
"sponsor",
|
||||||
|
@ -526,10 +455,10 @@ describe("lockCategoriesRecords", () => {
|
||||||
"shilling"
|
"shilling"
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
fetch(`${endpoint}?videoID=no-segments-video-id`)
|
client.get(endpoint, { params: {videoID: "no-segments-video-id" }})
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = res.data;
|
||||||
assert.ok(stringDeepEquals(data.categories, expected.categories));
|
assert.ok(stringDeepEquals(data.categories, expected.categories));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const endpoint = `${getbaseURL()}/api/getVideoSponsorTimes`;
|
const endpoint = "/api/getVideoSponsorTimes";
|
||||||
|
const getOldSponsorTime = (videoID: string) => client.get(endpoint, { params: { videoID } });
|
||||||
|
|
||||||
describe("getVideoSponsorTime (Old get method)", () => {
|
describe("getVideoSponsorTime (Old get method)", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -14,8 +13,8 @@ describe("getVideoSponsorTime (Old get method)", () => {
|
||||||
await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime1,test", 1, 11, 2, "oldGetSponsorTime01", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]);
|
await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime1,test", 1, 11, 2, "oldGetSponsorTime01", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time", (done: Done) => {
|
it("Should be able to get a time", (done) => {
|
||||||
fetch(`${endpoint}?videoID=oldGetSponsorTime0`)
|
getOldSponsorTime("oldGetSponsorTime0")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
|
@ -23,8 +22,8 @@ describe("getVideoSponsorTime (Old get method)", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 404 if no segment found", (done: Done) => {
|
it("Should return 404 if no segment found", (done) => {
|
||||||
fetch(`${endpoint}?videoID=notarealvideo`)
|
getOldSponsorTime("notarealvideo")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
@ -33,8 +32,8 @@ describe("getVideoSponsorTime (Old get method)", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
it("Should be possible to send unexpected query parameters", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0&fakeparam=hello`)
|
client.get(endpoint, { params: { videoID: "oldGetSponsorTime0", fakeparam: "hello" }})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
|
@ -42,30 +41,28 @@ describe("getVideoSponsorTime (Old get method)", () => {
|
||||||
.catch(() => done("couldn't callendpoint"));
|
.catch(() => done("couldn't callendpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able send a comma in a query param", (done: Done) => {
|
it("Should be able send a comma in a query param", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime1,test`)
|
getOldSponsorTime("oldGetSponsorTime1,test")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
UUIDs: ["oldGetSponsorTime01"],
|
UUIDs: ["oldGetSponsorTime01"],
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get the correct time", (done: Done) => {
|
it("Should be able to get the correct time", (done) => {
|
||||||
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0`)
|
getOldSponsorTime("oldGetSponsorTime0")
|
||||||
.then(async res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
|
||||||
const expected = {
|
const expected = {
|
||||||
sponsorTimes: [[1, 11]],
|
sponsorTimes: [[1, 11]],
|
||||||
UUIDs: ["oldGetSponsorTime00"]
|
UUIDs: ["oldGetSponsorTime00"]
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(res.data, expected));
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
import fetch from "node-fetch";
|
|
||||||
import { Done } from "../utils/utils";
|
|
||||||
import { getbaseURL } from "../utils/getBaseURL";
|
|
||||||
import { partialDeepEquals } from "../utils/partialDeepEquals";import {db} from "../../src/databases/databases";
|
import { partialDeepEquals } from "../utils/partialDeepEquals";import {db} from "../../src/databases/databases";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
const videoID1 = "dQw4w9WgXcQ";
|
const videoID1 = "dQw4w9WgXcQ";
|
||||||
const videoID2 = "dQw4w9WgXcE";
|
const videoID2 = "dQw4w9WgXcE";
|
||||||
const userID = "testtesttesttesttesttesttesttesttest";
|
const userID = "testtesttesttesttesttesttesttesttest";
|
||||||
|
const endpoint = "/api/postVideoSponsorTimes";
|
||||||
|
|
||||||
describe("postVideoSponsorTime (Old submission method)", () => {
|
describe("postVideoSponsorTime (Old submission method)", () => {
|
||||||
it("Should be able to submit a time (GET)", (done: Done) => {
|
it("Should be able to submit a time (GET)", (done) => {
|
||||||
fetch(`${getbaseURL()
|
client.get(endpoint, { params: { videoID: videoID1, startTime: 1, endTime: 10, userID }})
|
||||||
}/api/postVideoSponsorTimes?videoID=${videoID1}&startTime=1&endTime=10&userID=${userID}`)
|
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID1]);
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID1]);
|
||||||
|
@ -26,13 +24,11 @@ describe("postVideoSponsorTime (Old submission method)", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to submit a time (POST)", (done: Done) => {
|
it("Should be able to submit a time (POST)", (done) => {
|
||||||
fetch(`${getbaseURL()
|
client({
|
||||||
}/api/postVideoSponsorTimes?videoID=${videoID2}&startTime=1&endTime=11&userID=${userID}`, {
|
url: endpoint,
|
||||||
method: "POST",
|
params: { videoID: videoID2, startTime: 1, endTime: 11, userID },
|
||||||
headers: {
|
method: "post",
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
|
@ -48,10 +44,9 @@ describe("postVideoSponsorTime (Old submission method)", () => {
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 for missing params", (done: Done) => {
|
it("Should return 400 for missing params", (done) => {
|
||||||
fetch(`${getbaseURL()
|
client.post(endpoint, { params: { startTime: 1, endTime: 10, userID }})
|
||||||
}/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=${userID}`)
|
.then(res => {
|
||||||
.then(async res => {
|
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|
13
test/utils/httpClient.ts
Normal file
13
test/utils/httpClient.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { config } from "../../src/config";
|
||||||
|
import axios, { AxiosRequestConfig } from "axios";
|
||||||
|
|
||||||
|
export function getbaseURL(): string {
|
||||||
|
return `http://localhost:${config.port}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const defaultConfig: AxiosRequestConfig = {
|
||||||
|
baseURL: getbaseURL(),
|
||||||
|
validateStatus: (status) => status < 500
|
||||||
|
};
|
||||||
|
|
||||||
|
export const client = axios.create(defaultConfig);
|
Loading…
Reference in a new issue