2021-09-23 00:52:35 +02:00
|
|
|
import { partialDeepEquals } from "../utils/partialDeepEquals";import { db } from "../../src/databases/databases";
|
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-09-05 01:23:43 +02:00
|
|
|
const videoID1 = "dQw4w9WgXcQ";
|
|
|
|
const videoID2 = "dQw4w9WgXcE";
|
|
|
|
const userID = "testtesttesttesttesttesttesttesttest";
|
2021-09-22 23:50:06 +02:00
|
|
|
const endpoint = "/api/postVideoSponsorTimes";
|
2021-09-05 01:23:43 +02:00
|
|
|
|
2021-07-12 08:43:46 +02:00
|
|
|
describe("postVideoSponsorTime (Old submission method)", () => {
|
2021-09-22 23:50:06 +02:00
|
|
|
it("Should be able to submit a time (GET)", (done) => {
|
2021-09-23 00:52:35 +02:00
|
|
|
client.get(endpoint, { params: { videoID: videoID1, startTime: 1, endTime: 10, userID } })
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-05 01:23:43 +02:00
|
|
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID1]);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 1,
|
|
|
|
endTime: 10,
|
|
|
|
category: "sponsor"
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, 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 submit a time (POST)", (done) => {
|
|
|
|
client({
|
|
|
|
url: endpoint,
|
|
|
|
params: { videoID: videoID2, startTime: 1, endTime: 11, userID },
|
|
|
|
method: "post",
|
2021-01-06 01:43:28 +01:00
|
|
|
})
|
2021-07-12 08:43:46 +02:00
|
|
|
.then(async res => {
|
|
|
|
assert.strictEqual(res.status, 200);
|
2021-09-05 01:23:43 +02:00
|
|
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID2]);
|
2021-08-03 06:19:37 +02:00
|
|
|
const expected = {
|
|
|
|
startTime: 1,
|
|
|
|
endTime: 11,
|
|
|
|
category: "sponsor"
|
|
|
|
};
|
|
|
|
assert.ok(partialDeepEquals(row, expected));
|
2021-07-12 08:43:46 +02:00
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
|
2022-07-06 06:11:45 +02:00
|
|
|
it("Should return 400 for missing video", (done) => {
|
|
|
|
client.get(endpoint, { params: { startTime: 1, endTime: 10, userID } })
|
|
|
|
.then(res => {
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should return 400 for missing userID", (done) => {
|
|
|
|
client.get(endpoint, { params: { videoID: videoID1, startTime: 1, endTime: 10 } })
|
2021-09-22 23:50:06 +02:00
|
|
|
.then(res => {
|
2021-07-12 08:43:46 +02:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2020-10-17 20:56:54 +02:00
|
|
|
});
|
|
|
|
});
|