make eslint scream about promises, then fix all lints

also rewrite a bunch of test suites from using done callbacks to using
async functions - it's way too easy to forget about a .catch() clause
This commit is contained in:
mini-bomba
2025-09-11 01:14:40 +02:00
parent 5664ff4f58
commit 899000309f
16 changed files with 750 additions and 1220 deletions

View File

@@ -16,32 +16,24 @@ describe("tokenUtils test", function() {
mock.onGet(/identity/).reply(200, patreon.activeIdentity);
});
it("Should be able to create patreon token", function (done) {
if (!config?.patreon) this.skip();
tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => {
assert.ok(validateToken(licenseKey[0]));
done();
});
it("Should be able to create patreon token", async function () {
if (!config?.patreon) return this.skip();
const licenseKey = await tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code");
assert.ok(validateToken(licenseKey[0]));
});
it("Should be able to create local token", (done) => {
tokenUtils.createAndSaveToken(tokenUtils.TokenType.local).then((licenseKey) => {
assert.ok(validateToken(licenseKey[0]));
done();
});
it("Should be able to create local token", async () => {
const licenseKey = await tokenUtils.createAndSaveToken(tokenUtils.TokenType.local);
assert.ok(validateToken(licenseKey[0]));
});
it("Should be able to get patreon identity", function (done) {
if (!config?.patreon) this.skip();
tokenUtils.getPatreonIdentity("fake_access_token").then((result) => {
assert.deepEqual(result, patreon.activeIdentity);
done();
});
it("Should be able to get patreon identity", async function () {
if (!config?.patreon) return this.skip();
const result = await tokenUtils.getPatreonIdentity("fake_access_token");
assert.deepEqual(result, patreon.activeIdentity);
});
it("Should be able to refresh token", function (done) {
if (!config?.patreon) this.skip();
tokenUtils.refreshToken(tokenUtils.TokenType.patreon, "fake-licence-Key", "fake_refresh_token").then((result) => {
assert.strictEqual(result, true);
done();
});
it("Should be able to refresh token", async function () {
if (!config?.patreon) return this.skip();
const result = await tokenUtils.refreshToken(tokenUtils.TokenType.patreon, "fake-licence-Key", "fake_refresh_token");
assert.strictEqual(result, true);
});
after(function () {
@@ -56,20 +48,16 @@ describe("tokenUtils failing tests", function() {
mock.onGet(/identity/).reply(204, patreon.activeIdentity);
});
it("Should fail if patreon is not correctly stubbed", function (done) {
tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => {
assert.strictEqual(licenseKey, null);
done();
});
it("Should fail if patreon is not correctly stubbed", async () => {
const licenseKey = await tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code");
assert.strictEqual(licenseKey, null);
});
it("Should fail if token type is invalid", (done) => {
tokenUtils.createAndSaveToken("invalidTokenType" as tokenUtils.TokenType).then((licenseKey) => {
assert.strictEqual(licenseKey, null);
done();
});
it("Should fail if token type is invalid", async () => {
const licenseKey = await tokenUtils.createAndSaveToken("invalidTokenType" as tokenUtils.TokenType);
assert.strictEqual(licenseKey, null);
});
after(function () {
mock.restore();
});
});
});