add service to table only have videoID

This commit is contained in:
Haidang666
2021-09-30 13:56:55 +07:00
parent 99d72b92e4
commit 356974b478
18 changed files with 188 additions and 60 deletions

View File

@@ -4,19 +4,21 @@ import assert from "assert";
import { client } from "../utils/httpClient";
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 } });
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") VALUES (?, ?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock1", "sponsor", "1-short"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock1", "interaction", "1-longer-reason"]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "service") VALUES (?, ?, ?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock1", "sponsor", "1-short", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock1", "interaction", "1-longer-reason", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock2", "preview", "2-reason"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock2", "preview", "2-reason", "YouTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock3", "nonmusic", "3-reason"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock3", "nonmusic", "3-reason", "PeerTube"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock3", "sponsor", "3-reason", "YouTube"]);
});
it("Should update the database version when starting the application", async () => {
@@ -74,4 +76,69 @@ describe("getLockCategories", () => {
})
.catch(err => done(err));
});
it("Should be able to get multiple locks with service", (done) => {
getLockCategoriesWithService("getLock1", "YouTube")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"sponsor",
"interaction"
],
reason: "1-longer-reason"
};
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get single locks with service", (done) => {
getLockCategoriesWithService("getLock3", "PeerTube")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"nonmusic"
],
reason: "3-reason"
};
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("Should be able to get single locks with service", (done) => {
getLockCategoriesWithService("getLock3", "Youtube")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"sponsor"
],
reason: "3-reason"
};
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
it("should return result from Youtube service if service not match", (done) => {
getLockCategoriesWithService("getLock3", "Dailymotion")
.then(res => {
assert.strictEqual(res.status, 200);
const expected = {
categories: [
"sponsor"
],
reason: "3-reason"
};
assert.deepStrictEqual(res.data, expected);
done();
})
.catch(err => done(err));
});
});