diff --git a/ci.json b/ci.json index 1637b41..c18b0d5 100644 --- a/ci.json +++ b/ci.json @@ -56,7 +56,6 @@ ] } ], - "maxNumberOfActiveWarnings": 3, "hoursAfterWarningExpires": 24, "rateLimit": { "vote": { diff --git a/test.json b/test.json index fef8052..aac0a2b 100644 --- a/test.json +++ b/test.json @@ -44,7 +44,6 @@ ] } ], - "maxNumberOfActiveWarnings": 3, "hoursAfterWarningExpires": 24, "rateLimit": { "vote": { diff --git a/test/cases/postSkipSegmentsWarnings.ts b/test/cases/postSkipSegmentsWarnings.ts index 1a1544b..9b1cd65 100644 --- a/test/cases/postSkipSegmentsWarnings.ts +++ b/test/cases/postSkipSegmentsWarnings.ts @@ -6,12 +6,14 @@ import { client } from "../utils/httpClient"; describe("postSkipSegments Warnings", () => { // Constant and helpers - const warnUser01 = "warn-user01-qwertyuiopasdfghjklzxcvbnm"; + const warnUser01 = "warn-user01"; const warnUser01Hash = getHash(warnUser01); - const warnUser02 = "warn-user02-qwertyuiopasdfghjklzxcvbnm"; + const warnUser02 = "warn-user02"; const warnUser02Hash = getHash(warnUser02); - const warnUser03 = "warn-user03-qwertyuiopasdfghjklzxcvbnm"; + const warnUser03 = "warn-user03"; const warnUser03Hash = getHash(warnUser03); + const warnUser04 = "warn-user04"; + const warnUser04Hash = getHash(warnUser04); const warnVideoID = "postSkipSegments-warn-video"; @@ -32,26 +34,20 @@ describe("postSkipSegments Warnings", () => { const reason03 = "Reason03"; const MILLISECONDS_IN_HOUR = 3600000; - const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires; + const WARNING_EXPIRATION_TIME = config.hoursAfterWarningExpires * MILLISECONDS_IN_HOUR; const insertWarningQuery = 'INSERT INTO warnings ("userID", "issuerUserID", "enabled", "reason", "issueTime") VALUES(?, ?, ?, ?, ?)'; - // User 1 - 4 active warnings + // User 1 | 1 active | custom reason db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, now]); - db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 1000)]); - db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 2000)]); - db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 3601000)]); - // User 2 - 3 active warnings - db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, now]); - db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, (now - (warningExpireTime + 1000))]); - db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, (now - (warningExpireTime + 2000))]); - // User 3 - 2 active warnings, 2 expired warnings - db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason03, now]); - db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason03, (now - 1000)]); - db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, (now - 2000)]); - db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, (now - 3601000)]); + // User 2 | 1 inactive | default reason + db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 0, reason02, now]); + // User 3 | 1 expired, active | custom reason + db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, (now - WARNING_EXPIRATION_TIME - 1000)]); + // User 4 | 1 active | default reason + db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason02, now]); }); - it("Should be rejected with custom message if user has too many active warnings", (done) => { + it("Should be rejected with custom message if user has active warnings", (done) => { postSkipSegmentJSON({ userID: warnUser01, videoID: warnVideoID, @@ -75,7 +71,7 @@ describe("postSkipSegments Warnings", () => { .catch(err => done(err)); }); - it("Should be accepted if user has some active warnings", (done) => { + it("Should be accepted if user has inactive warning", (done) => { postSkipSegmentJSON({ userID: warnUser02, videoID: warnVideoID, @@ -91,7 +87,7 @@ describe("postSkipSegments Warnings", () => { .catch(err => done(err)); }); - it("Should be accepted if user has some warnings removed", (done) => { + it("Should be accepted if user has expired warning", (done) => { postSkipSegmentJSON({ userID: warnUser03, videoID: warnVideoID, @@ -107,9 +103,9 @@ describe("postSkipSegments Warnings", () => { .catch(err => done(err)); }); - it("Should be rejected with default message if user has to many active warnings", (done) => { + it("Should be rejected with default message if user has active warning", (done) => { postSkipSegmentJSON({ - userID: warnUser01, + userID: warnUser04, videoID: warnVideoID, segments: [{ segment: [0, 10], @@ -119,7 +115,11 @@ describe("postSkipSegments Warnings", () => { .then(res => { assert.strictEqual(res.status, 403); const errorMessage = res.data; - assert.notStrictEqual(errorMessage, ""); + const expected = "Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes" + + " that are not malicious, and we just want to clarify the rules. " + + "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? " + + `Your userID is ${warnUser04Hash}.`; + assert.strictEqual(errorMessage, expected); done(); }) .catch(err => done(err));