Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/backends/redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@
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');

Expand Down Expand Up @@ -124,6 +154,36 @@
);
});

it('should set null as "null"', async () => {
mockRedisClient.set.mockResolvedValue('OK');
await backend.set('test-key', null as any);

Check failure on line 159 in test/backends/redis.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
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);

Check failure on line 165 in test/backends/redis.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
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);

Check failure on line 171 in test/backends/redis.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
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);

Check failure on line 177 in test/backends/redis.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
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);

Check failure on line 183 in test/backends/redis.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
expect(mockRedisClient.set).toHaveBeenCalledWith('test-key', '123.45');
});

it('should throw CacheSerializationError for unstringifiable values', async () => {
const circularValue = {};
(circularValue as Record<string, unknown>).self = circularValue;
Expand Down
Loading