|
| 1 | +import { db } from "../../src/databases/databases"; |
| 2 | +import { getHash } from "../../src/utils/getHash"; |
| 3 | +import assert from "assert"; |
| 4 | +import { client } from "../utils/httpClient"; |
| 5 | + |
| 6 | +describe("getUserInfo Free Chapters", () => { |
| 7 | + const endpoint = "/api/userInfo"; |
| 8 | + |
| 9 | + const noQualifyUserID = "getUserInfo-Free-noQualify"; |
| 10 | + const vipQualifyUserID = "getUserInfo-Free-VIP"; |
| 11 | + const repQualifyUserID = "getUserInfo-Free-RepQualify"; |
| 12 | + const oldQualifyUserID = "getUserInfo-Free-OldQualify"; |
| 13 | + const postOldQualify = 1600000000000; |
| 14 | + |
| 15 | + before(async () => { |
| 16 | + const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "reputation", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; |
| 17 | + await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-0", getHash(repQualifyUserID), postOldQualify, 0, "sponsor", "skip", 20, 0]); |
| 18 | + await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-1", getHash(oldQualifyUserID), 0, 0, "sponsor", "skip", 0, 0]); // submit at epoch |
| 19 | + await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-2", getHash(noQualifyUserID), postOldQualify, 0, "sponsor", "skip", 0, 0]); |
| 20 | + |
| 21 | + await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash(vipQualifyUserID)]); |
| 22 | + }); |
| 23 | + |
| 24 | + const getUserInfo = (userID: string) => client.get(endpoint, { params: { userID, value: "freeChaptersAccess" } }); |
| 25 | + |
| 26 | + it("Should not get free access (noQuality)", (done) => { |
| 27 | + getUserInfo(noQualifyUserID) |
| 28 | + .then(res => { |
| 29 | + assert.strictEqual(res.status, 200); |
| 30 | + assert.strictEqual(res.data.freeChaptersAccess, false); |
| 31 | + done(); |
| 32 | + }) |
| 33 | + .catch(err => done(err)); |
| 34 | + }); |
| 35 | + |
| 36 | + it("Should get free access (VIP)", (done) => { |
| 37 | + getUserInfo(vipQualifyUserID) |
| 38 | + .then(res => { |
| 39 | + assert.strictEqual(res.status, 200); |
| 40 | + assert.strictEqual(res.data.freeChaptersAccess, true); |
| 41 | + done(); |
| 42 | + }) |
| 43 | + .catch(err => done(err)); |
| 44 | + }); |
| 45 | + |
| 46 | + it("Should get free access (rep)", (done) => { |
| 47 | + getUserInfo(repQualifyUserID) |
| 48 | + .then(res => { |
| 49 | + assert.strictEqual(res.status, 200); |
| 50 | + assert.strictEqual(res.data.freeChaptersAccess, true); |
| 51 | + done(); |
| 52 | + }) |
| 53 | + .catch(err => done(err)); |
| 54 | + }); |
| 55 | + |
| 56 | + it("Should get free access (old)", (done) => { |
| 57 | + getUserInfo(oldQualifyUserID) |
| 58 | + .then(res => { |
| 59 | + assert.strictEqual(res.status, 200); |
| 60 | + assert.strictEqual(res.data.freeChaptersAccess, true); |
| 61 | + done(); |
| 62 | + }) |
| 63 | + .catch(err => done(err)); |
| 64 | + }); |
| 65 | +}); |
0 commit comments