getLockCategories

This commit is contained in:
Michael C
2022-01-06 23:56:27 -05:00
parent 9ca01407e8
commit 0584492b8c
2 changed files with 81 additions and 25 deletions

View File

@@ -4,27 +4,28 @@ import assert from "assert";
import { client } from "../utils/httpClient";
import { mixedDeepEquals } from "../utils/partialDeepEquals";
const endpoint = "/api/lockCategories";
const getLockCategories = (videoID: string) => client.get(endpoint, { params: { videoID } });
const getLockCategoriesWithService = (videoID: string, service: string) => client.get(endpoint, { params: { videoID, service } });
const defaultActionTypes = ["skip", "mute"];
const getLockCategories = (videoID: string, actionTypes = defaultActionTypes, service = "YouTube") => client.get(endpoint, { params: { videoID, actionTypes, service } });
describe("getLockCategories", () => {
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesVIP")]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "service") VALUES (?, ?, ?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory1", "sponsor", "1-short", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory1", "interaction", "1-longer-reason", "YouTube"]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType","category", "reason", "service") VALUES (?, ?, ?, ?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory1", "skip", "sponsor", "1-short", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory1", "mute", "interaction", "1-longer-reason", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory2", "preview", "2-reason", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory2", "skip", "preview", "2-reason", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory3", "nonmusic", "3-reason", "PeerTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory3", "sponsor", "3-reason", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory3", "mute", "nonmusic", "3-reason", "PeerTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory3", "skip", "sponsor", "3-reason", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLockCategory3", "full", "outro", "3-longer-reason", "YouTube"]);
});
it("Should update the database version when starting the application", async () => {
const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
assert.ok(version > 20, `Version isn't greater than 20. Version is ${version}`);
assert.ok(version >= 29, `Version isn't greater than 29. Version is ${version}`);
});
it("Should be able to get multiple locks", (done) => {
@@ -36,7 +37,8 @@ describe("getLockCategories", () => {
"sponsor",
"interaction"
],
reason: "1-longer-reason"
reason: "1-longer-reason",
actionTypes: defaultActionTypes
};
assert.ok(mixedDeepEquals(res.data, expected));
done();
@@ -52,7 +54,8 @@ describe("getLockCategories", () => {
categories: [
"preview"
],
reason: "2-reason"
reason: "2-reason",
actionTypes: defaultActionTypes
};
assert.deepStrictEqual(res.data, expected);
done();
@@ -79,7 +82,7 @@ describe("getLockCategories", () => {
});
it("Should be able to get multiple locks with service", (done) => {
getLockCategoriesWithService("getLockCategory1", "YouTube")
getLockCategories("getLockCategory1", defaultActionTypes, "YouTube")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
@@ -87,7 +90,8 @@ describe("getLockCategories", () => {
"sponsor",
"interaction"
],
reason: "1-longer-reason"
reason: "1-longer-reason",
actionTypes: defaultActionTypes
};
assert.ok(mixedDeepEquals(res.data, expected));
done();
@@ -96,14 +100,15 @@ describe("getLockCategories", () => {
});
it("Should be able to get single locks with service", (done) => {
getLockCategoriesWithService("getLockCategory3", "PeerTube")
getLockCategories("getLockCategory3", defaultActionTypes, "PeerTube")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"nonmusic"
],
reason: "3-reason"
reason: "3-reason",
actionTypes: defaultActionTypes
};
assert.deepStrictEqual(res.data, expected);
done();
@@ -112,14 +117,15 @@ describe("getLockCategories", () => {
});
it("Should be able to get single locks with service", (done) => {
getLockCategoriesWithService("getLockCategory3", "Youtube")
getLockCategories("getLockCategory3", defaultActionTypes, "Youtube")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"sponsor"
],
reason: "3-reason"
reason: "3-reason",
actionTypes: defaultActionTypes
};
assert.deepStrictEqual(res.data, expected);
done();
@@ -128,14 +134,61 @@ describe("getLockCategories", () => {
});
it("should return result from Youtube service if service not match", (done) => {
getLockCategoriesWithService("getLockCategory3", "Dailymotion")
getLockCategories("getLockCategory3", defaultActionTypes, "Dailymotion")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"sponsor"
],
reason: "3-reason"
reason: "3-reason",
actionTypes: defaultActionTypes
};
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("should return 404 if invalid actionTypes specified", (done) => {
getLockCategories("getLockCategory1", ["ban"])
.then(res => {
assert.strictEqual(res.status, 404);
done();
})
.catch(err => done(err));
});
it("should be able to get with specific actionType", (done) => {
getLockCategories("getLockCategory1", ["mute"])
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"sponsor",
"interaction"
],
reason: "1-longer-reason",
actionTypes: ["mute"]
};
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get skip, mute, full", (done) => {
const actionTypes = [...defaultActionTypes, "full"]
getLockCategories("getLockCategory3",actionTypes )
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"nonmusic",
"outro"
],
reason: "3-longer-reason",
actionTypes
};
assert.deepStrictEqual(res.data, expected);
done();