You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
RedisJSON
This commit is contained in:
@ -1,57 +1,66 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ARRPOP';
|
||||
import ARRPOP from './ARRPOP';
|
||||
|
||||
describe('ARRPOP', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('key', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key'),
|
||||
['JSON.ARRPOP', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
it('key, path', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$'),
|
||||
['JSON.ARRPOP', 'key', '$']
|
||||
);
|
||||
});
|
||||
|
||||
it('key, path, index', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', '$', 0),
|
||||
['JSON.ARRPOP', 'key', '$', '0']
|
||||
);
|
||||
});
|
||||
describe('JSON.ARRPOP', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
ARRPOP.transformArguments('key'),
|
||||
['JSON.ARRPOP', 'key']
|
||||
);
|
||||
});
|
||||
|
||||
describe('client.json.arrPop', () => {
|
||||
testUtils.testWithClient('null', async client => {
|
||||
await client.json.set('key', '.', []);
|
||||
|
||||
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);
|
||||
it('with path', () => {
|
||||
assert.deepEqual(
|
||||
ARRPOP.transformArguments('key', {
|
||||
path: '$'
|
||||
}),
|
||||
['JSON.ARRPOP', 'key', '$']
|
||||
);
|
||||
});
|
||||
|
||||
it('with path and index', () => {
|
||||
assert.deepEqual(
|
||||
ARRPOP.transformArguments('key', {
|
||||
path: '$',
|
||||
index: 0
|
||||
}),
|
||||
['JSON.ARRPOP', 'key', '$', '0']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('client.json.arrPop', () => {
|
||||
testUtils.testWithClient('without path and value', async client => {
|
||||
const [, reply] = await Promise.all([
|
||||
client.json.set('key', '$', []),
|
||||
client.json.arrPop('key')
|
||||
]);
|
||||
|
||||
assert.equal(reply, null);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithClient('. path with value', async client => {
|
||||
const [, reply] = await Promise.all([
|
||||
client.json.set('key', '.', ['value']),
|
||||
client.json.arrPop('key', {
|
||||
path: '.'
|
||||
})
|
||||
]);
|
||||
|
||||
assert.equal(reply, 'value');
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithClient('$ path with value', async client => {
|
||||
const [, reply] = await Promise.all([
|
||||
client.json.set('key', '$', ['value']),
|
||||
client.json.arrPop('key', {
|
||||
path: '$'
|
||||
})
|
||||
]);
|
||||
|
||||
assert.deepEqual(reply, ['value']);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user