2021-12-19 08:03:50 +01:00
|
|
|
import { config } from "../../src/config";
|
|
|
|
import redis from "../../src/utils/redis";
|
|
|
|
import crypto from "crypto";
|
|
|
|
import assert from "assert";
|
|
|
|
|
2021-12-20 01:37:22 +01:00
|
|
|
const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");
|
|
|
|
|
|
|
|
const randKey1 = genRandom();
|
|
|
|
const randValue1 = genRandom();
|
|
|
|
const randKey2 = genRandom(16);
|
2021-12-19 08:03:50 +01:00
|
|
|
|
|
|
|
describe("redis test", function() {
|
|
|
|
before(async function() {
|
|
|
|
if (!config.redis) this.skip();
|
2021-12-20 01:37:22 +01:00
|
|
|
await redis.setAsync(randKey1, randValue1);
|
2021-12-19 08:03:50 +01:00
|
|
|
});
|
|
|
|
it("Should get stored value", (done) => {
|
2021-12-20 01:37:22 +01:00
|
|
|
redis.getAsync(randKey1)
|
2021-12-19 08:03:50 +01:00
|
|
|
.then(res => {
|
|
|
|
if (res.err) assert.fail(res.err);
|
2021-12-20 01:37:22 +01:00
|
|
|
assert.strictEqual(res.reply, randValue1);
|
2021-12-19 08:03:50 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2021-12-20 01:37:22 +01:00
|
|
|
it("Should not be able to get not stored value", (done) => {
|
|
|
|
redis.getAsync(randKey2)
|
|
|
|
.then(res => {
|
2021-12-21 05:04:41 +01:00
|
|
|
if (res.reply || res.err ) assert.fail("Value should not be found");
|
2021-12-20 01:37:22 +01:00
|
|
|
done();
|
|
|
|
});
|
2021-12-21 05:04:41 +01:00
|
|
|
});
|
2021-12-19 08:03:50 +01:00
|
|
|
});
|