mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 13:07:02 +03:00
getStatus, token tests and mocks
This commit is contained in:
@@ -50,7 +50,17 @@ describe("generateToken test", function() {
|
|||||||
patreonLicense = extractLicenseKey(res.data);
|
patreonLicense = extractLicenseKey(res.data);
|
||||||
assert.ok(validatelicenseKeyRegex(patreonLicense));
|
assert.ok(validatelicenseKeyRegex(patreonLicense));
|
||||||
done();
|
done();
|
||||||
});
|
}).catch(err => done(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should create patreon token for invalid patron", function (done) {
|
||||||
|
mock.onGet(/identity/).reply(200, patreon.formerIdentityFail);
|
||||||
|
if (!config?.patreon) this.skip();
|
||||||
|
getGenerateToken("patreon", "patreon_code", "").then(res => {
|
||||||
|
patreonLicense = extractLicenseKey(res.data);
|
||||||
|
assert.ok(validatelicenseKeyRegex(patreonLicense));
|
||||||
|
done();
|
||||||
|
}).catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to create new local token", function (done) {
|
it("Should be able to create new local token", function (done) {
|
||||||
@@ -58,28 +68,28 @@ describe("generateToken test", function() {
|
|||||||
assert.ok(validatelicenseKeyRegex(licenseKey));
|
assert.ok(validatelicenseKeyRegex(licenseKey));
|
||||||
localLicense = licenseKey;
|
localLicense = licenseKey;
|
||||||
done();
|
done();
|
||||||
});
|
}).catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if missing code parameter", function (done) {
|
it("Should return 400 if missing code parameter", function (done) {
|
||||||
getGenerateToken("patreon", null, "").then(res => {
|
getGenerateToken("patreon", null, "").then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
});
|
}).catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 403 if missing adminuserID parameter", function (done) {
|
it("Should return 403 if missing adminuserID parameter", function (done) {
|
||||||
getGenerateToken("local", "fake-code", null).then(res => {
|
getGenerateToken("local", "fake-code", null).then(res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
});
|
}).catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 403 for invalid adminuserID parameter", function (done) {
|
it("Should return 403 for invalid adminuserID parameter", function (done) {
|
||||||
getGenerateToken("local", "fake-code", "fakeAdminID").then(res => {
|
getGenerateToken("local", "fake-code", "fakeAdminID").then(res => {
|
||||||
assert.strictEqual(res.status, 403);
|
assert.strictEqual(res.status, 403);
|
||||||
done();
|
done();
|
||||||
});
|
}).catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,7 +106,7 @@ describe("verifyToken static tests", function() {
|
|||||||
getVerifyToken(null).then(res => {
|
getVerifyToken(null).then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
});
|
}).catch(err => done(err));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import assert from "assert";
|
|||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { client } from "../utils/httpClient";
|
import { client } from "../utils/httpClient";
|
||||||
import { config } from "../../src/config";
|
import { config } from "../../src/config";
|
||||||
|
import sinon from "sinon";
|
||||||
let dbVersion: number;
|
let dbVersion: number;
|
||||||
|
|
||||||
describe("getStatus", () => {
|
describe("getStatus", () => {
|
||||||
@@ -122,4 +123,16 @@ describe("getStatus", () => {
|
|||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should return commit unkown if not present", (done) => {
|
||||||
|
sinon.stub((global as any), "HEADCOMMIT").value(undefined);
|
||||||
|
client.get(`${endpoint}/commit`)
|
||||||
|
.then(res => {
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
assert.strictEqual(res.data, "test"); // commit should be test
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user