Add complex object tests
This commit is contained in:
parent
f2330144de
commit
82ff748fd9
|
@ -18,14 +18,26 @@ describe("redis", () => {
|
||||||
|
|
||||||
expect(await redis.get(key)).toEqual(value)
|
expect(await redis.get(key)).toEqual(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("objects can be persisted", async () => {
|
||||||
|
const key = structures.uuid()
|
||||||
|
const value = { [generator.word()]: generator.word() }
|
||||||
|
|
||||||
|
await redis.store(key, value)
|
||||||
|
|
||||||
|
expect(await redis.get(key)).toEqual(value)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("bulkStore", () => {
|
describe("bulkStore", () => {
|
||||||
function createRandomObject(keyLength: number) {
|
function createRandomObject(
|
||||||
|
keyLength: number,
|
||||||
|
valueGenerator: () => any = () => generator.word()
|
||||||
|
) {
|
||||||
return generator
|
return generator
|
||||||
.unique(() => generator.word(), keyLength)
|
.unique(() => generator.word(), keyLength)
|
||||||
.reduce((acc, key) => {
|
.reduce((acc, key) => {
|
||||||
acc[key] = generator.word()
|
acc[key] = valueGenerator()
|
||||||
return acc
|
return acc
|
||||||
}, {} as Record<string, string>)
|
}, {} as Record<string, string>)
|
||||||
}
|
}
|
||||||
|
@ -42,6 +54,21 @@ describe("redis", () => {
|
||||||
expect(await redis.keys("*")).toHaveLength(10)
|
expect(await redis.keys("*")).toHaveLength(10)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("a complex object can be persisted", async () => {
|
||||||
|
const data = {
|
||||||
|
...createRandomObject(10, () => createRandomObject(5)),
|
||||||
|
...createRandomObject(5),
|
||||||
|
}
|
||||||
|
|
||||||
|
await redis.bulkStore(data)
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
expect(await redis.get(key)).toEqual(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(await redis.keys("*")).toHaveLength(10)
|
||||||
|
})
|
||||||
|
|
||||||
it("no TTL is set by default", async () => {
|
it("no TTL is set by default", async () => {
|
||||||
const data = createRandomObject(10)
|
const data = createRandomObject(10)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue