diff --git a/packages/json/lib/commands/ARRPOP.spec.ts b/packages/json/lib/commands/ARRPOP.spec.ts index a80b8c3cbc..7c2ec365eb 100644 --- a/packages/json/lib/commands/ARRPOP.spec.ts +++ b/packages/json/lib/commands/ARRPOP.spec.ts @@ -26,12 +26,32 @@ describe('ARRPOP', () => { }); }); - testUtils.testWithClient('client.json.arrPop', async client => { - await client.json.set('key', '$', []); + describe('client.json.arrPop', () => { + testUtils.testWithClient('null', async client => { + await client.json.set('key', '.', []); - assert.deepEqual( - await client.json.arrPop('key', '$'), - [null] - ); - }, GLOBAL.SERVERS.OPEN); + assert.equal( + await client.json.arrPop('key', '.'), + null + ); + }, GLOBAL.SERVERS.OPEN); + + testUtils.testWithClient('with value', async client => { + await client.json.set('key', '.', ['value']); + + assert.equal( + await client.json.arrPop('key', '.'), + 'value' + ); + }, GLOBAL.SERVERS.OPEN); + + testUtils.testWithClient('array', async client => { + await client.json.set('key', '$', ['value']); + + assert.deepEqual( + await client.json.arrPop('key', '$'), + ['value'] + ); + }, GLOBAL.SERVERS.OPEN); + }); }); diff --git a/packages/json/lib/commands/ARRPOP.ts b/packages/json/lib/commands/ARRPOP.ts index 932b3294d8..18830c0d31 100644 --- a/packages/json/lib/commands/ARRPOP.ts +++ b/packages/json/lib/commands/ARRPOP.ts @@ -1,3 +1,5 @@ +import { RedisJSON, transformRedisJsonNullReply } from '.'; + export const FIRST_KEY_INDEX = 1; export function transformArguments(key: string, path?: string, index?: number): Array { @@ -14,4 +16,12 @@ export function transformArguments(key: string, path?: string, index?: number): return args; } -export { transformRedisJsonNullArrayNullReply as transformReply } from '.'; +export function transformReply(reply: null | string | Array): null | RedisJSON | Array { + if (reply === null) return null; + + if (Array.isArray(reply)) { + return reply.map(transformRedisJsonNullReply); + } + + return transformRedisJsonNullReply(reply); +} diff --git a/packages/json/lib/commands/index.ts b/packages/json/lib/commands/index.ts index f898fde584..efcf156b84 100644 --- a/packages/json/lib/commands/index.ts +++ b/packages/json/lib/commands/index.ts @@ -79,22 +79,12 @@ export function transformRedisJsonReply(json: string): RedisJSON { return JSON.parse(json); } -export function transformRedisJsonArrayReply(jsons: Array): Array { - return jsons.map(transformRedisJsonReply) -} - export function transformRedisJsonNullReply(json: string | null): RedisJSON | null { if (json === null) return null; return transformRedisJsonReply(json); } -export function transformRedisJsonNullArrayNullReply(jsons: Array | null): Array | null { - if (jsons === null) return null; - - return jsons.map(transformRedisJsonNullReply); -} - export function transformNumbersReply(reply: string): number | Array { return JSON.parse(reply); }