From 8ebb73524a3f12d72cf6ff564be949aee5dae83b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 10 May 2026 11:43:22 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20tests=20for=20primitive=20?= =?UTF-8?q?values=20fast=20path=20in=20Redis=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented missing test coverage for the fast path handling of simple values in the Redis backend. Added test cases for both `get` and `set` methods to verify correct serialization and parsing of `null`, `undefined`, `true`, `false`, and numeric values. Co-authored-by: suranig <24814104+suranig@users.noreply.github.com> --- test/backends/redis.test.ts | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/backends/redis.test.ts b/test/backends/redis.test.ts index 668dbe6..bd48241 100644 --- a/test/backends/redis.test.ts +++ b/test/backends/redis.test.ts @@ -60,6 +60,36 @@ describe('RedisCacheBackend', () => { expect(result).toBeUndefined(); }); + it('should handle string "null" as null', async () => { + mockRedisClient.get.mockResolvedValue('null'); + const result = await backend.get('test-key'); + expect(result).toBeNull(); + }); + + it('should handle string "undefined" as undefined', async () => { + mockRedisClient.get.mockResolvedValue('undefined'); + const result = await backend.get('test-key'); + expect(result).toBeUndefined(); + }); + + it('should handle string "true" as boolean true', async () => { + mockRedisClient.get.mockResolvedValue('true'); + const result = await backend.get('test-key'); + expect(result).toBe(true); + }); + + it('should handle string "false" as boolean false', async () => { + mockRedisClient.get.mockResolvedValue('false'); + const result = await backend.get('test-key'); + expect(result).toBe(false); + }); + + it('should handle numeric strings as numbers', async () => { + mockRedisClient.get.mockResolvedValue('123.45'); + const result = await backend.get('test-key'); + expect(result).toBe(123.45); + }); + it('should throw CacheSerializationError for invalid JSON', async () => { mockRedisClient.get.mockResolvedValue('invalid-json'); @@ -124,6 +154,36 @@ describe('RedisCacheBackend', () => { ); }); + it('should set null as "null"', async () => { + mockRedisClient.set.mockResolvedValue('OK'); + await backend.set('test-key', null as any); + expect(mockRedisClient.set).toHaveBeenCalledWith('test-key', 'null'); + }); + + it('should set undefined as "undefined"', async () => { + mockRedisClient.set.mockResolvedValue('OK'); + await backend.set('test-key', undefined as any); + expect(mockRedisClient.set).toHaveBeenCalledWith('test-key', 'undefined'); + }); + + it('should set boolean true as "true"', async () => { + mockRedisClient.set.mockResolvedValue('OK'); + await backend.set('test-key', true as any); + expect(mockRedisClient.set).toHaveBeenCalledWith('test-key', 'true'); + }); + + it('should set boolean false as "false"', async () => { + mockRedisClient.set.mockResolvedValue('OK'); + await backend.set('test-key', false as any); + expect(mockRedisClient.set).toHaveBeenCalledWith('test-key', 'false'); + }); + + it('should set number as string', async () => { + mockRedisClient.set.mockResolvedValue('OK'); + await backend.set('test-key', 123.45 as any); + expect(mockRedisClient.set).toHaveBeenCalledWith('test-key', '123.45'); + }); + it('should throw CacheSerializationError for unstringifiable values', async () => { const circularValue = {}; (circularValue as Record).self = circularValue;