everything up to purgeAllSegments

This commit is contained in:
Michael C
2021-09-04 19:23:43 -04:00
parent 1823a91d54
commit 6e55f9d979
15 changed files with 320 additions and 308 deletions

View File

@@ -4,22 +4,24 @@ import {getHash} from "../../src/utils/getHash";
import {db} from "../../src/databases/databases";
import assert from "assert";
const fakeHash = "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35";
describe("getLockCategoriesByHash", () => {
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-getLockCategories")]);
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP")]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "hashedVideoID") VALUES (?, ?, ?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-1", "sponsor", "1-reason-short", "67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-1", "interaction", "1-reason-longer", "67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "sponsor", "1-reason-short", getHash("getLockHash1", 1)]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "interaction", "1-reason-longer", getHash("getLockHash1", 1)]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-2", "preview", "2-reason", "dff09120437b4bd594dffae5f3cde3cfc5f6099fb01d0ef4051919b2908d9a50"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash2", "preview", "2-reason", getHash("getLockHash2", 1)]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-3", "nonmusic", "3-reason", "bf1b122fd5630e0df8626d00c4a95c58954ad715e5595b0f75a19ac131e28928"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash3", "nonmusic", "3-reason", getHash("getLockHash3", 1)]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-1", "outro", "fake1-reason", "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-2", "intro", "fake2-longer-reason", "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-2", "preview", "fake2-short", "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-1", "outro", "fake1-reason", fakeHash]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "intro", "fake2-longer-reason", fakeHash]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "preview", "fake2-short", fakeHash]);
});
it("Database should be greater or equal to version 20", async () => {
@@ -30,13 +32,15 @@ describe("getLockCategoriesByHash", () => {
});
it("Should be able to get multiple locks in one object", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/67a65`)
const videoID = "getLockHash1";
const hash = getHash(videoID, 1);
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,4)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
const expected = [{
videoID: "getLockHash-1",
hash: getHash("getLockHash-1", 1),
videoID,
hash,
categories: [
"sponsor",
"interaction"
@@ -50,13 +54,15 @@ describe("getLockCategoriesByHash", () => {
});
it("Should be able to get single lock", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/dff09`)
const videoID = "getLockHash2";
const hash = getHash(videoID, 1);
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,6)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
const expected = [{
videoID: "getLockHash-2",
hash: getHash("getLockHash-2", 1),
videoID,
hash,
categories: [
"preview"
],
@@ -69,13 +75,15 @@ describe("getLockCategoriesByHash", () => {
});
it("Should be able to get by half full hash", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/bf1b122fd5630e0df8626d00c4a95c58`)
const videoID = "getLockHash3";
const hash = getHash(videoID, 1);
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,32)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
const expected = [{
videoID: "getLockHash-3",
hash: getHash("getLockHash-3", 1),
videoID,
hash,
categories: [
"nonmusic"
],
@@ -88,20 +96,20 @@ describe("getLockCategoriesByHash", () => {
});
it("Should be able to get multiple by similar hash with multiple categories", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/b05a`)
fetch(`${getbaseURL()}/api/lockCategories/${fakeHash.substring(0,5)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
const expected = [{
videoID: "fakehash-1",
hash: "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35",
hash: fakeHash,
categories: [
"outro"
],
reason: "fake1-reason"
}, {
videoID: "fakehash-2",
hash: "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450",
hash: fakeHash,
categories: [
"intro",
"preview"
@@ -142,7 +150,7 @@ describe("getLockCategoriesByHash", () => {
});
it("should return 400 if full hash sent", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35`)
fetch(`${getbaseURL()}/api/lockCategories/${fakeHash}`)
.then(res => {
assert.strictEqual(res.status, 400);
done();