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

@@ -9,44 +9,32 @@ const randKey2 = genRandom(16);
const randKey3 = genRandom();
const randValue3 = genRandom();
const redisGetCheck = (key: string, expected: string | null, done: Mocha.Done): Promise<void> =>
redis.get(key)
.then(res => {
assert.strictEqual(res, expected);
done();
}).catch(err => done(err));
describe("redis test", function() {
before(async function() {
if (!config.redis?.enabled) this.skip();
await redis.set(randKey1, randValue1);
});
it("Should get stored value", (done) => {
redisGetCheck(randKey1, randValue1, done);
it("Should get stored value", async () => {
const res = await redis.get(randKey1);
assert.strictEqual(res, randValue1);
});
it("Should not be able to get not stored value", (done) => {
redis.get(randKey2)
.then(res => {
if (res) done("Value should not be found");
done();
}).catch(err => done(err));
it("Should not be able to get not stored value", async () => {
const res = await redis.get(randKey2);
assert.strictEqual(res, null, "Value should not be found");
});
it("Should be able to delete stored value", (done) => {
redis.del(randKey1)
.catch(err => done(err))
.then(() => redisGetCheck(randKey1, null, done));
it("Should be able to delete stored value", async () => {
await redis.del(randKey1);
const res = await redis.get(randKey1);
assert.strictEqual(res, null, "Deleted key should not be found");
});
it("Should be able to set expiring value", (done) => {
redis.setEx(randKey3, 8400, randValue3)
.catch(err => done(err))
.then(() => redisGetCheck(randKey3, randValue3, done));
it("Should be able to set expiring value", async () => {
await redis.setEx(randKey3, 8400, randValue3);
const res = await redis.get(randKey3);
assert.strictEqual(res, randValue3);
});
it("Should continue when undefined value is fetched", (done) => {
it("Should continue when undefined value is fetched", async () => {
const undefkey = `undefined.${genRandom()}`;
redis.get(undefkey)
.then(result => {
assert.ok(!result); // result should be falsy
done();
});
const res = await redis.get(undefkey);
assert.strictEqual(res, null);
});
});
});