mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 04:27:09 +03:00
test fixes
test fixes - fix timeout in redis (by @ajayyy) - allow "errors" in tempVIP test - remove duplicate warning in postSkipSegments - remove duplicate VIP in tempVIP - run tests against different user once tempVIP removed - fix typo in getHashCache fetching syntax and wording - use standard syntax in redisTest - fix spacing in getLockReason - typo in npm script name test cases - add getHashCache test case - add more tests to redisTest configuration - update config to use redis timeout - update docker-compose to use newest pinned version Co-Authored-By: Ajay Ramachandran <dev@ajay.app>
This commit is contained in:
31
test/cases/getHashCache.ts
Normal file
31
test/cases/getHashCache.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { config } from "../../src/config";
|
||||
import { getHashCache } from "../../src/utils/getHashCache";
|
||||
import { shaHashKey } from "../../src/utils/redisKeys";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import redis from "../../src/utils/redis";
|
||||
import crypto from "crypto";
|
||||
import assert from "assert";
|
||||
import { setTimeout } from "timers/promises";
|
||||
|
||||
const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");
|
||||
|
||||
const rand1Hash = genRandom(24);
|
||||
const rand1Hash_Key = getHash(rand1Hash, 1);
|
||||
const rand1Hash_Result = getHash(rand1Hash);
|
||||
|
||||
describe("getHashCache test", function() {
|
||||
before(function() {
|
||||
if (!config.redis?.enabled) this.skip();
|
||||
});
|
||||
it("Should set hashKey and be able to retreive", (done) => {
|
||||
const redisKey = shaHashKey(rand1Hash_Key);
|
||||
getHashCache(rand1Hash)
|
||||
.then(() => setTimeout(50)) // add timeout for redis to complete async
|
||||
.then(() => redis.get(redisKey))
|
||||
.then(result => {
|
||||
assert.strictEqual(result, rand1Hash_Result);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err === undefined ? "no set value" : err));
|
||||
}).timeout(5000);
|
||||
});
|
||||
Reference in New Issue
Block a user