2021-09-23 00:52:35 +02:00
|
|
|
import { db } from "../../src/databases/databases";
|
2021-09-21 08:02:17 +02:00
|
|
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
2021-07-12 08:43:46 +02:00
|
|
|
import assert from "assert";
|
2021-09-22 23:50:06 +02:00
|
|
|
import { client } from "../utils/httpClient";
|
2020-10-17 20:56:54 +02:00
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
describe("getSkipSegments", () => {
|
2021-09-22 23:50:06 +02:00
|
|
|
const endpoint = "/api/skipSegments";
|
2021-03-02 03:37:35 +01:00
|
|
|
before(async () => {
|
2021-11-06 21:09:55 +01:00
|
|
|
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, ["getSkipSegmentID0", 1, 11, 1, 0, "uuid01", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentID0", 12, 14, 2, 0, "uuid02", "testman", 0, 50, "sponsor", "mute", "YouTube", 100, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentID0", 20, 33, 2, 0, "uuid03", "testman", 0, 50, "intro", "skip", "YouTube", 101, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentID1", 1, 11, 2, 0, "uuid10", "testman", 0, 50, "sponsor", "skip", "PeerTube", 120, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentID2", 1, 11, 2, 1, "uuid20", "testman", 0, 50, "sponsor", "skip", "YouTube", 140, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentID3", 1, 11, 2, 0, "uuid30", "testman", 0, 50, "sponsor", "skip", "YouTube", 200, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentID3", 7, 22, -3, 0, "uuid31", "testman", 0, 50, "sponsor", "skip", "YouTube", 300, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentMultiple", 1, 11, 2, 0, "uuid40", "testman", 0, 50, "intro", "skip", "YouTube", 400, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentMultiple", 20, 33, 2, 0, "uuid41", "testman", 0, 50, "intro", "skip", "YouTube", 500, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentLocked", 20, 33, 2, 1, "uuid50", "testman", 0, 50, "intro", "skip", "YouTube", 230, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentLocked", 20, 34, 100000, 0, "uuid51", "testman", 0, 50, "intro", "skip", "YouTube", 190, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["getSkipSegmentID6", 20, 34, 100000, 0, "uuid60", "testman", 0, 50, "sponsor", "skip", "YouTube", 190, 1, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, 0, "requiredSegmentVid1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, 0, "requiredSegmentVid2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, 0, "requiredSegmentVid3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, 0, "requiredSegmentVid4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]);
|
2022-07-16 15:02:32 +02:00
|
|
|
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 0, 0, "requiredSegmentVid-hidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 1, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 0, 0, "requiredSegmentVid-shadowhidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 1, ""]);
|
2021-11-06 21:09:55 +01:00
|
|
|
await db.prepare("run", query, ["chapterVid", 60, 80, 2, 0, "chapterVid-1", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 1"]);
|
|
|
|
await db.prepare("run", query, ["chapterVid", 70, 75, 2, 0, "chapterVid-2", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 2"]);
|
2021-12-21 04:22:45 +01:00
|
|
|
await db.prepare("run", query, ["chapterVid", 71, 75, 2, 0, "chapterVid-3", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 3"]);
|
2021-12-01 00:58:37 +01:00
|
|
|
await db.prepare("run", query, ["requiredSegmentHashVid", 10, 20, -2, 0, "1d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]);
|
|
|
|
await db.prepare("run", query, ["requiredSegmentHashVid", 20, 30, -2, 0, "1ebde8e8ae03096b6c866aa2c8cc7ee1d720ca1fca27bea3f39a6a1b876577e71", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]);
|
2021-03-02 03:37:35 +01:00
|
|
|
return;
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by category 1", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "sponsor" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
|
|
|
assert.strictEqual(data[0].segment[0], 1);
|
|
|
|
assert.strictEqual(data[0].segment[1], 11);
|
|
|
|
assert.strictEqual(data[0].category, "sponsor");
|
2021-09-05 01:23:43 +02:00
|
|
|
assert.strictEqual(data[0].UUID, "uuid01");
|
2021-10-15 06:14:59 +02:00
|
|
|
assert.strictEqual(data[0].votes, 1);
|
|
|
|
assert.strictEqual(data[0].locked, 0);
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data[0].videoDuration, 100);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by category and action type", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "sponsor", actionType: "mute" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [12, 14],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid02",
|
2021-08-03 06:19:37 +02:00
|
|
|
videoDuration: 100
|
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-06 06:19:16 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by category and getSkipSegmentMultiple action types", (done) => {
|
|
|
|
client.get(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionType=mute&actionType=skip`)
|
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid01",
|
2021-08-03 06:19:37 +02:00
|
|
|
videoDuration: 100
|
|
|
|
}, {
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid02"
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 2);
|
2021-08-03 06:19:37 +02:00
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-06 06:19:16 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by category and getSkipSegmentMultiple action types (JSON array)", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "sponsor", actionTypes: `["mute","skip"]` } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid01",
|
2021-08-03 06:19:37 +02:00
|
|
|
videoDuration: 100
|
|
|
|
}, {
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid02"
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-06 06:19:16 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by category for a different service 1", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID1", category: "sponsor", service: "PeerTube" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid10",
|
2021-08-03 06:19:37 +02:00
|
|
|
videoDuration: 120
|
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-03-20 02:31:16 +01:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by category 2", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", category: "intro" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [20, 33],
|
|
|
|
category: "intro",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid03"
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by categories array", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `["sponsor"]` } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid01",
|
2021-08-03 06:19:37 +02:00
|
|
|
videoDuration: 100
|
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get a time by categories array 2", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `["intro"]` } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [20, 33],
|
|
|
|
category: "intro",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid03",
|
2021-08-03 06:19:37 +02:00
|
|
|
videoDuration: 101
|
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-03-30 01:16:18 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should return 404 if all submissions are hidden", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID6" } })
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 404);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get getSkipSegmentMultiple times by category", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentMultiple", categories: `["intro"]` } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 2);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "intro",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid40",
|
2021-08-03 06:19:37 +02:00
|
|
|
}, {
|
|
|
|
segment: [20, 33],
|
|
|
|
category: "intro",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid41",
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get getSkipSegmentMultiple times by getSkipSegmentMultiple categories", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `["sponsor", "intro"]` } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 2);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid01",
|
2021-08-03 06:19:37 +02:00
|
|
|
}, {
|
|
|
|
segment: [20, 33],
|
|
|
|
category: "intro",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid03",
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be possible to send unexpected query parameters", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", fakeparam: "hello", category: "sponsor" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid01",
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Low voted submissions should be hidden", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID3", category: "sponsor" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid30",
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should return 404 if no segment found", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "notarealvideo" } })
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 404);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should return 400 if bad categories argument", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID0", categories: `[not-quoted,not-quoted]` } })
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-16 05:01:26 +02:00
|
|
|
});
|
2020-10-17 20:56:54 +02:00
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able send a comma in a query param", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentID2", category: "sponsor" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid20",
|
2021-10-15 06:14:59 +02:00
|
|
|
votes: 2,
|
|
|
|
locked: 1
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should always get getSkipSegmentLocked segment", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "getSkipSegmentLocked", category: "intro" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [20, 33],
|
|
|
|
category: "intro",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid50",
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-02-19 02:24:04 +01:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get getSkipSegmentMultiple categories with repeating parameters", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(`${endpoint}?category=sponsor&category=intro`, { params: { videoID: "getSkipSegmentID0" } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 2);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid01",
|
2021-08-03 06:19:37 +02:00
|
|
|
}, {
|
|
|
|
segment: [20, 33],
|
|
|
|
category: "intro",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid03",
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-21 06:33:48 +02:00
|
|
|
});
|
2021-06-24 07:37:51 +02:00
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get, categories param overriding repeating category", (done) => {
|
|
|
|
client.get(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor"]&category=intro`)
|
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 1);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
|
|
|
segment: [1, 11],
|
|
|
|
category: "sponsor",
|
2021-09-05 01:23:43 +02:00
|
|
|
UUID: "uuid01",
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-06-24 07:37:51 +02:00
|
|
|
});
|
2021-07-04 20:15:17 +02:00
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get specific segments with requiredSegments", (done) => {
|
2021-09-17 05:59:19 +02:00
|
|
|
const required2 = "requiredSegmentVid2";
|
|
|
|
const required3 = "requiredSegmentVid3";
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: "requiredSegmentVid", requiredSegments: `["${required2}","${required3}"]` } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 2);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
2021-09-17 05:59:19 +02:00
|
|
|
UUID: required2,
|
2021-08-03 06:19:37 +02:00
|
|
|
}, {
|
2021-09-17 05:59:19 +02:00
|
|
|
UUID: required3,
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-04 20:15:17 +02:00
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to get specific segments with repeating requiredSegment", (done) => {
|
2021-09-17 05:59:19 +02:00
|
|
|
const required2 = "requiredSegmentVid2";
|
|
|
|
const required3 = "requiredSegmentVid3";
|
2021-09-22 23:50:06 +02:00
|
|
|
client.get(`${endpoint}?videoID=requiredSegmentVid&requiredSegment=${required2}&requiredSegment=${required3}`)
|
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-22 23:50:06 +02:00
|
|
|
const data = res.data;
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(data.length, 2);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = [{
|
2021-09-17 05:59:19 +02:00
|
|
|
UUID: required2,
|
2021-08-03 06:19:37 +02:00
|
|
|
}, {
|
2021-09-17 05:59:19 +02:00
|
|
|
UUID: required3,
|
2021-08-03 06:19:37 +02:00
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-04 20:15:17 +02:00
|
|
|
});
|
2021-07-07 23:39:16 +02:00
|
|
|
|
2021-11-06 21:09:55 +01:00
|
|
|
it("Should be able to get overlapping chapter segments if very different", (done) => {
|
|
|
|
client.get(`${endpoint}?videoID=chapterVid&category=chapter&actionType=chapter`)
|
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 2);
|
|
|
|
const expected = [{
|
|
|
|
UUID: "chapterVid-1",
|
|
|
|
description: "Chapter 1"
|
|
|
|
}, {
|
|
|
|
UUID: "chapterVid-2",
|
|
|
|
description: "Chapter 2"
|
|
|
|
}];
|
|
|
|
const expected2 = [{
|
|
|
|
UUID: "chapterVid-1",
|
|
|
|
description: "Chapter 1"
|
|
|
|
}, {
|
|
|
|
UUID: "chapterVid-3",
|
|
|
|
description: "Chapter 3"
|
|
|
|
}];
|
|
|
|
|
|
|
|
assert.ok(partialDeepEquals(data, expected, false) || partialDeepEquals(data, expected2));
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
|
|
|
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should get 400 if no videoID passed in", (done) => {
|
|
|
|
client.get(endpoint)
|
|
|
|
.then(res => {
|
2021-07-22 23:50:39 +02:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2021-07-07 23:39:16 +02:00
|
|
|
});
|
2021-12-01 00:58:37 +01:00
|
|
|
|
|
|
|
it("Should be able to get requiredSegment by partial", (done) => {
|
|
|
|
const required1 = "1d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa";
|
|
|
|
const required2 = "1ebde8e8ae03096b6c866aa2c8cc7ee1d720ca1fca27bea3f39a6a1b876577e71";
|
|
|
|
client.get(`${endpoint}?videoID=requiredSegmentHashVid&requiredSegment=${required1.slice(0,8)}&requiredSegment=${required2.slice(0,8)}`)
|
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 2);
|
|
|
|
const expected = [{
|
|
|
|
UUID: required1,
|
|
|
|
}, {
|
|
|
|
UUID: required2,
|
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
2022-07-16 15:02:32 +02:00
|
|
|
|
|
|
|
it("Should be able to get hidden segments with requiredSegments", (done) => {
|
|
|
|
const required3 = "requiredSegmentVid3";
|
|
|
|
const requiredHidden = "requiredSegmentVid-hidden";
|
|
|
|
client.get(endpoint, { params: { videoID: "requiredSegmentVid", requiredSegments: `["${requiredHidden}","${required3}"]` } })
|
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 2);
|
|
|
|
const expected = [{
|
|
|
|
UUID: requiredHidden,
|
|
|
|
}, {
|
|
|
|
UUID: required3,
|
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should be able to get shadowhidden segments with requiredSegments", (done) => {
|
|
|
|
const required2 = "requiredSegmentVid2";
|
|
|
|
const requiredShadowHidden = "requiredSegmentVid-shadowhidden";
|
|
|
|
client.get(endpoint, { params: { videoID: "requiredSegmentVid", requiredSegments: `["${required2}","${requiredShadowHidden}"]` } })
|
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
const data = res.data;
|
|
|
|
assert.strictEqual(data.length, 2);
|
|
|
|
const expected = [{
|
|
|
|
UUID: required2,
|
|
|
|
}, {
|
|
|
|
UUID: requiredShadowHidden,
|
|
|
|
}];
|
|
|
|
assert.ok(partialDeepEquals(data, expected));
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|