getChapterNames

- remove identifier from segmentGen
- add multiGenRandomValue
- add videoInfo query
This commit is contained in:
Michael C
2023-09-27 23:53:18 -04:00
parent 7364499f11
commit 726983bb9b
5 changed files with 55 additions and 57 deletions

View File

@@ -3,59 +3,43 @@ import { db } from "../../src/databases/databases";
import { Postgres } from "../../src/databases/Postgres";
import { client } from "../utils/httpClient";
import { partialDeepEquals } from "../utils/partialDeepEquals";
import { insertChapter } from "../utils/segmentQueryGen";
import { genRandomValue } from "../utils/getRandom";
import { insertVideoInfo } from "../utils/queryGen";
// Only works with Postgres
if (db instanceof Postgres) {
describe("getChapterNames", function () {
const endpoint = "/api/chapterNames";
describe("getChapterNames", function () {
const endpoint = "/api/chapterNames";
const chapterNamesVid1 = genRandomValue("video", "getChapterNames");
const chapterChannelID = genRandomValue("channel", "getChapterNames");
const chapterNames = [
"Weird name",
"A different one",
"Something else",
];
const chapterNamesVid1 = "chapterNamesVid";
const chapterChannelID = "chapterChannelID";
const nameSearch = (query: string, expected: string): Promise<void> => {
const expectedData = [{
description: expected
}];
return client.get(`${endpoint}?description=${query}&channelID=${chapterChannelID}`)
.then(res => {
assert.strictEqual(res.status, 200);
assert.strictEqual(res.data.length, 1);
assert.ok(partialDeepEquals(res.data, expectedData));
});
};
before(async () => {
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", query, [chapterNamesVid1, 60, 80, 2, 0, "chapterNamesVid-1", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Weird name"]);
await db.prepare("run", query, [chapterNamesVid1, 70, 75, 2, 0, "chapterNamesVid-2", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "A different one"]);
await db.prepare("run", query, [chapterNamesVid1, 71, 76, 2, 0, "chapterNamesVid-3", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Something else"]);
before(async function() {
if (!(db instanceof Postgres)) this.skip(); // only works with Postgres
await insertChapter(db, chapterNames[0], { videoID: chapterNamesVid1, startTime: 60, endTime: 80 });
await insertChapter(db, chapterNames[1], { videoID: chapterNamesVid1, startTime: 70, endTime: 75 });
await insertChapter(db, chapterNames[2], { videoID: chapterNamesVid1, startTime: 71, endTime: 76 });
await db.prepare("run", `INSERT INTO "videoInfo" ("videoID", "channelID", "title", "published")
SELECT ?, ?, ?, ?`, [
chapterNamesVid1, chapterChannelID, "", 0
]);
});
it("Search for 'weird'", async () => {
const result = await client.get(`${endpoint}?description=weird&channelID=${chapterChannelID}`);
const expected = [{
description: "Weird name",
}];
assert.strictEqual(result.status, 200);
assert.strictEqual(result.data.length, 3);
assert.ok(partialDeepEquals(result.data, expected));
});
it("Search for 'different'", async () => {
const result = await client.get(`${endpoint}?description=different&channelID=${chapterChannelID}`);
const expected = [{
description: "A different one",
}];
assert.strictEqual(result.status, 200);
assert.strictEqual(result.data.length, 3);
assert.ok(partialDeepEquals(result.data, expected));
});
it("Search for 'something'", async () => {
const result = await client.get(`${endpoint}?description=something&channelID=${chapterChannelID}`);
const expected = [{
description: "Something else",
}];
assert.strictEqual(result.status, 200);
assert.strictEqual(result.data.length, 3);
assert.ok(partialDeepEquals(result.data, expected));
});
await insertVideoInfo(db, chapterNamesVid1, chapterChannelID);
});
}
it("Search for 'weird'", () => nameSearch("weird", chapterNames[0]));
it("Search for 'different'", () => nameSearch("different", chapterNames[1]));
it("Search for 'something'", () => nameSearch("something", chapterNames[2]));
});