mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-01-28 05:10:47 +03:00
Update tests to use promises
This commit is contained in:
@@ -15,9 +15,9 @@ describe('postSkipSegments', () => {
|
||||
before(() => {
|
||||
let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES";
|
||||
|
||||
db.exec(startOfQuery + "('80percent_video', 0, 1000, 0, '80percent-uuid-0', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')");
|
||||
db.exec(startOfQuery + "('80percent_video', 1001, 1005, 0, '80percent-uuid-1', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')");
|
||||
db.exec(startOfQuery + "('80percent_video', 0, 5000, -2, '80percent-uuid-2', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')");
|
||||
db.prepare("run", startOfQuery + "('80percent_video', 0, 1000, 0, '80percent-uuid-0', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')");
|
||||
db.prepare("run", startOfQuery + "('80percent_video', 1001, 1005, 0, '80percent-uuid-1', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')");
|
||||
db.prepare("run", startOfQuery + "('80percent_video', 0, 5000, -2, '80percent-uuid-2', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')");
|
||||
|
||||
const now = Date.now();
|
||||
const warnVip01Hash = getHash("warn-vip01");
|
||||
@@ -27,20 +27,20 @@ describe('postSkipSegments', () => {
|
||||
const MILLISECONDS_IN_HOUR = 3600000;
|
||||
const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires;
|
||||
const startOfWarningQuery = 'INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES';
|
||||
db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 1000)) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 2000)) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + now + "', '" + warnVip01Hash + "', 0)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 0)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 1000)) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 2000)) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + now + "', '" + warnVip01Hash + "', 0)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 0)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)");
|
||||
db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)");
|
||||
|
||||
db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUserSubmission") + "')");
|
||||
db.prepare("run", "INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUserSubmission") + "')");
|
||||
});
|
||||
|
||||
it('Should be able to submit a single time (Params method)', (done: Done) => {
|
||||
@@ -51,7 +51,7 @@ describe('postSkipSegments', () => {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
|
||||
if (row.startTime === 2 && row.endTime === 10 && row.category === "sponsor") {
|
||||
@@ -82,7 +82,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', "SELECT startTime, endTime, locked, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]);
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor") {
|
||||
@@ -113,7 +113,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', "SELECT startTime, endTime, locked, category FROM sponsorTimes WHERE videoID = ?", ["vipuserIDSubmission"]);
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 1 && row.category === "sponsor") {
|
||||
@@ -147,7 +147,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
|
||||
let success = true;
|
||||
@@ -194,7 +194,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]);
|
||||
let success = true;
|
||||
@@ -243,7 +243,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]);
|
||||
let success = true;
|
||||
@@ -291,7 +291,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]);
|
||||
let success = rows.length == 2;
|
||||
@@ -385,7 +385,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
done(); // success
|
||||
} else {
|
||||
@@ -482,7 +482,7 @@ describe('postSkipSegments', () => {
|
||||
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
})
|
||||
@@ -507,7 +507,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
})
|
||||
@@ -525,7 +525,7 @@ describe('postSkipSegments', () => {
|
||||
videoID: "dQw4w9WgXcQ",
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
})
|
||||
@@ -550,7 +550,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
})
|
||||
@@ -574,7 +574,7 @@ describe('postSkipSegments', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
})
|
||||
@@ -592,7 +592,7 @@ describe('postSkipSegments', () => {
|
||||
videoID: "dQw4w9WgXcQ",
|
||||
}),
|
||||
})
|
||||
.then(res => {
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user