You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
V5 bringing RESP3, Sentinel and TypeMapping to node-redis
RESP3 Support - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion. Sentinel TypeMapping Correctly types Multi commands Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
@@ -1,80 +1,79 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { SchemaFieldTypes } from '.';
|
||||
import { transformArguments } from './SPELLCHECK';
|
||||
import SPELLCHECK from './SPELLCHECK';
|
||||
|
||||
describe('SPELLCHECK', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('index', 'query'),
|
||||
['FT.SPELLCHECK', 'index', 'query']
|
||||
);
|
||||
});
|
||||
|
||||
it('with DISTANCE', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('index', 'query', { DISTANCE: 2 }),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'DISTANCE', '2']
|
||||
);
|
||||
});
|
||||
|
||||
describe('with TERMS', () => {
|
||||
it('single', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('index', 'query', {
|
||||
TERMS: {
|
||||
mode: 'INCLUDE',
|
||||
dictionary: 'dictionary'
|
||||
}
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'dictionary']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('index', 'query', {
|
||||
TERMS: [{
|
||||
mode: 'INCLUDE',
|
||||
dictionary: 'include'
|
||||
}, {
|
||||
mode: 'EXCLUDE',
|
||||
dictionary: 'exclude'
|
||||
}]
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'include', 'TERMS', 'EXCLUDE', 'exclude']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('with DIALECT', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('index', 'query', {
|
||||
DIALECT: 1
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'DIALECT', '1']
|
||||
);
|
||||
});
|
||||
describe('FT.SPELLCHECK', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
SPELLCHECK.transformArguments('index', 'query'),
|
||||
['FT.SPELLCHECK', 'index', 'query']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.ft.spellCheck', async client => {
|
||||
await Promise.all([
|
||||
client.ft.create('index', {
|
||||
field: SchemaFieldTypes.TEXT
|
||||
}),
|
||||
client.hSet('key', 'field', 'query')
|
||||
]);
|
||||
it('with DISTANCE', () => {
|
||||
assert.deepEqual(
|
||||
SPELLCHECK.transformArguments('index', 'query', {
|
||||
DISTANCE: 2
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'DISTANCE', '2']
|
||||
);
|
||||
});
|
||||
|
||||
describe('with TERMS', () => {
|
||||
it('single', () => {
|
||||
assert.deepEqual(
|
||||
await client.ft.spellCheck('index', 'quer'),
|
||||
[{
|
||||
term: 'quer',
|
||||
suggestions: [{
|
||||
score: 1,
|
||||
suggestion: 'query'
|
||||
}]
|
||||
}]
|
||||
SPELLCHECK.transformArguments('index', 'query', {
|
||||
TERMS: {
|
||||
mode: 'INCLUDE',
|
||||
dictionary: 'dictionary'
|
||||
}
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'dictionary']
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
||||
it('multiple', () => {
|
||||
assert.deepEqual(
|
||||
SPELLCHECK.transformArguments('index', 'query', {
|
||||
TERMS: [{
|
||||
mode: 'INCLUDE',
|
||||
dictionary: 'include'
|
||||
}, {
|
||||
mode: 'EXCLUDE',
|
||||
dictionary: 'exclude'
|
||||
}]
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'include', 'TERMS', 'EXCLUDE', 'exclude']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('with DIALECT', () => {
|
||||
assert.deepEqual(
|
||||
SPELLCHECK.transformArguments('index', 'query', {
|
||||
DIALECT: 1
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'DIALECT', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.ft.spellCheck', async client => {
|
||||
const [,, reply] = await Promise.all([
|
||||
client.ft.create('index', {
|
||||
field: 'TEXT'
|
||||
}),
|
||||
client.hSet('key', 'field', 'query'),
|
||||
client.ft.spellCheck('index', 'quer')
|
||||
]);
|
||||
|
||||
assert.deepEqual(reply, [{
|
||||
term: 'quer',
|
||||
suggestions: [{
|
||||
score: 1,
|
||||
suggestion: 'query'
|
||||
}]
|
||||
}]);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
Reference in New Issue
Block a user