UNPKG

@langchain/community

Version:
18 lines (17 loc) 654 B
import { test, expect, jest } from "@jest/globals"; import { insecureHash } from "@langchain/core/utils/hash"; import { UpstashRedisCache } from "../upstash_redis.js"; const sha1 = (str) => insecureHash(str); test("UpstashRedisCache", async () => { const redis = { get: jest.fn(async (key) => { if (key === sha1("foo_bar_0")) { return { text: "baz" }; } return null; }), }; // eslint-disable-next-line @typescript-eslint/no-explicit-any const cache = new UpstashRedisCache({ client: redis }); expect(await cache.lookup("foo", "bar")).toEqual([{ text: "baz" }]); });