1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

fix GEO* commands

This commit is contained in:
Leibale
2023-05-08 11:04:22 +03:00
parent d2e244a77d
commit 6a0b4db4f7
37 changed files with 1115 additions and 990 deletions

View File

@@ -1,57 +1,54 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './GEODIST';
import GEODIST from './GEODIST';
describe('GEODIST', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('key', '1', '2'),
['GEODIST', 'key', '1', '2']
);
});
it('with unit', () => {
assert.deepEqual(
transformArguments('key', '1', '2', 'm'),
['GEODIST', 'key', '1', '2', 'm']
);
});
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
GEODIST.transformArguments('key', '1', '2'),
['GEODIST', 'key', '1', '2']
);
});
describe('client.geoDist', () => {
testUtils.testWithClient('null', async client => {
assert.equal(
await client.geoDist('key', '1', '2'),
null
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('with value', async client => {
const [, dist] = await Promise.all([
client.geoAdd('key', [{
member: '1',
longitude: 1,
latitude: 1
}, {
member: '2',
longitude: 2,
latitude: 2
}]),
client.geoDist('key', '1', '2')
]);
assert.equal(
dist,
157270.0561
);
}, GLOBAL.SERVERS.OPEN);
it('with unit', () => {
assert.deepEqual(
GEODIST.transformArguments('key', '1', '2', 'm'),
['GEODIST', 'key', '1', '2', 'm']
);
});
});
testUtils.testWithCluster('cluster.geoDist', async cluster => {
assert.equal(
await cluster.geoDist('key', '1', '2'),
null
);
}, GLOBAL.CLUSTERS.OPEN);
testUtils.testAll('geoDist null', async client => {
assert.equal(
await client.geoDist('key', '1', '2'),
null
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
testUtils.testAll('geoDist with member', async client => {
const [, dist] = await Promise.all([
client.geoAdd('key', [{
member: '1',
longitude: 1,
latitude: 1
}, {
member: '2',
longitude: 2,
latitude: 2
}]),
client.geoDist('key', '1', '2')
]);
assert.equal(
dist,
157270.0561
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});