Files
SponsorBlockServer/test/cases/redisTest.ts
mini-bomba 899000309f 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
2025-09-11 01:14:40 +02:00

41 lines
1.5 KiB
TypeScript

import { config } from "../../src/config";
import redis from "../../src/utils/redis";
import assert from "assert";
import { genRandom } from "../utils/getRandom";
const randKey1 = genRandom();
const randValue1 = genRandom();
const randKey2 = genRandom(16);
const randKey3 = genRandom();
const randValue3 = genRandom();
describe("redis test", function() {
before(async function() {
if (!config.redis?.enabled) this.skip();
await redis.set(randKey1, randValue1);
});
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", async () => {
const res = await redis.get(randKey2);
assert.strictEqual(res, null, "Value should not be found");
});
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", 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", async () => {
const undefkey = `undefined.${genRandom()}`;
const res = await redis.get(undefkey);
assert.strictEqual(res, null);
});
});