Skip to content

Commit d2635ed

Browse files
committed
fix some tests
1 parent 6483865 commit d2635ed

File tree

8 files changed

+37
-40
lines changed

8 files changed

+37
-40
lines changed

packages/client/lib/commands/VADD.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,15 @@ describe('VADD', () => {
5757
testUtils.testAll('vAdd', async client => {
5858
assert.equal(
5959
await client.vAdd('key', [1.0, 2.0, 3.0], 'element'),
60-
1
60+
true
61+
);
62+
63+
// same element should not be added again
64+
assert.equal(
65+
await client.vAdd('key', [1, 2 , 3], 'element'),
66+
false
6167
);
68+
6269
}, {
6370
client: GLOBAL.SERVERS.OPEN,
6471
cluster: GLOBAL.CLUSTERS.OPEN
@@ -71,6 +78,12 @@ describe('VADD', () => {
7178
true
7279
);
7380

81+
// same element should not be added again
82+
assert.equal(
83+
await client.vAdd('resp3-key', [1, 2 , 3], 'resp3-element'),
84+
false
85+
);
86+
7487
// Test with options to ensure complex parameters work with RESP3
7588
assert.equal(
7689
await client.vAdd('resp3-key', [4.0, 5.0, 6.0], 'resp3-element2', {

packages/client/lib/commands/VADD.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommandParser } from '../client/parser';
22
import { RedisArgument, NumberReply, Command, BooleanReply } from '../RESP/types';
3-
import { transformDoubleArgument } from './generic-transformers';
3+
import { transformBooleanReply, transformDoubleArgument } from './generic-transformers';
44

55
export interface VAddOptions {
66
REDUCE?: number;
@@ -61,8 +61,5 @@ export default {
6161
parser.push('M', options.M.toString());
6262
}
6363
},
64-
transformReply: {
65-
2: undefined as unknown as () => NumberReply,
66-
3: undefined as unknown as () => BooleanReply
67-
}
64+
transformReply: transformBooleanReply
6865
} as const satisfies Command;

packages/client/lib/commands/VCARD.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('VCARD', () => {
1919
await client.vCard('key'),
2020
2
2121
);
22+
23+
assert.equal(await client.vCard('unknown'), 0);
2224
}, {
2325
client: GLOBAL.SERVERS.OPEN,
2426
cluster: GLOBAL.CLUSTERS.OPEN
@@ -44,6 +46,8 @@ describe('VCARD', () => {
4446
await client.vCard('resp3-key'),
4547
3
4648
);
49+
50+
assert.equal(await client.vCard('unknown'), 0);
4751
}, {
4852
...GLOBAL.SERVERS.OPEN,
4953
clientOptions: {

packages/client/lib/commands/VCARD.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { CommandParser } from '../client/parser';
22
import { RedisArgument, NumberReply, Command } from '../RESP/types';
33

44
export default {
5-
CACHEABLE: true,
65
IS_READ_ONLY: true,
76
/**
87
* Retrieve the number of elements in a vector set

packages/client/lib/commands/VDIM.spec.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,13 @@ describe('VDIM', () => {
2424
});
2525

2626
testUtils.testWithClient('vDim with RESP3', async client => {
27-
// Test with different vector dimensions
28-
await client.vAdd('resp3-2d', [1.0, 2.0], 'elem2d');
29-
assert.equal(
30-
await client.vDim('resp3-2d'),
31-
2
32-
);
33-
3427
await client.vAdd('resp3-5d', [1.0, 2.0, 3.0, 4.0, 5.0], 'elem5d');
35-
assert.equal(
36-
await client.vDim('resp3-5d'),
37-
5
38-
);
3928

40-
// Verify dimension consistency within the same vector set
41-
await client.vAdd('resp3-5d', [6.0, 7.0, 8.0, 9.0, 10.0], 'elem5d-2');
4229
assert.equal(
4330
await client.vDim('resp3-5d'),
4431
5
4532
);
33+
4634
}, {
4735
...GLOBAL.SERVERS.OPEN,
4836
clientOptions: {

packages/client/lib/commands/VEMB.spec.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,19 @@ describe('VEMB', () => {
1717
const result = await client.vEmb('key', 'element');
1818
assert.ok(Array.isArray(result));
1919
assert.equal(result.length, 3);
20+
assert.equal(typeof result[0], 'number');
2021
}, {
2122
client: GLOBAL.SERVERS.OPEN,
2223
cluster: GLOBAL.CLUSTERS.OPEN
2324
});
2425

2526
testUtils.testWithClient('vEmb with RESP3', async client => {
26-
// Test retrieving embeddings with RESP3
27-
const originalVector = [1.5, 2.5, 3.5, 4.5];
28-
await client.vAdd('resp3-key', originalVector, 'resp3-element');
27+
await client.vAdd('resp3-key', [1.5, 2.5, 3.5, 4.5], 'resp3-element');
2928

30-
const embedding = await client.vEmb('resp3-key', 'resp3-element');
31-
assert.ok(Array.isArray(embedding));
32-
assert.equal(embedding.length, 4);
33-
34-
// Verify that all values are numbers (RESP3 should preserve numeric types)
35-
embedding.forEach(value => {
36-
assert.equal(typeof value, 'number');
37-
});
38-
39-
// Test with quantized vector to ensure RESP3 handles different precision
40-
await client.vAdd('resp3-key', [10.0, 20.0, 30.0, 40.0], 'quantized-elem', { QUANT: 'Q8' });
41-
const quantizedEmbedding = await client.vEmb('resp3-key', 'quantized-elem');
42-
assert.ok(Array.isArray(quantizedEmbedding));
43-
assert.equal(quantizedEmbedding.length, 4);
29+
const result = await client.vEmb('resp3-key', 'resp3-element');
30+
assert.ok(Array.isArray(result));
31+
assert.equal(result.length, 4);
32+
assert.equal(typeof result[0], 'number');
4433
}, {
4534
...GLOBAL.SERVERS.OPEN,
4635
clientOptions: {

packages/client/lib/commands/VEMB.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CommandParser } from '../client/parser';
2-
import { RedisArgument, ArrayReply, DoubleReply, Command } from '../RESP/types';
2+
import { RedisArgument, Command } from '../RESP/types';
3+
import { transformDoubleArrayReply } from './generic-transformers';
34

45
export default {
56
CACHEABLE: true,
@@ -17,5 +18,5 @@ export default {
1718
parser.pushKey(key);
1819
parser.push(element);
1920
},
20-
transformReply: undefined as unknown as () => ArrayReply<DoubleReply>
21+
transformReply: transformDoubleArrayReply
2122
} as const satisfies Command;

packages/client/lib/commands/VGETATTR.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,26 @@ describe('VGETATTR', () => {
1313

1414
testUtils.testAll('vGetAttr', async client => {
1515
await client.vAdd('key', [1.0, 2.0, 3.0], 'element');
16+
17+
const nullResult = await client.vGetAttr('key', 'element');
18+
assert.equal(nullResult, null);
19+
1620
await client.vSetAttr('key', 'element', { name: 'test' });
1721

1822
const result = await client.vGetAttr('key', 'element');
1923
assert.ok(result !== null);
24+
2025
}, {
2126
client: GLOBAL.SERVERS.OPEN,
2227
cluster: GLOBAL.CLUSTERS.OPEN
2328
});
2429

2530
testUtils.testWithClient('vGetAttr with RESP3', async client => {
26-
// Test getting attributes with RESP3
2731
await client.vAdd('resp3-key', [1.0, 2.0], 'resp3-element');
2832

2933
// Test null case (no attributes set)
3034
const nullResult = await client.vGetAttr('resp3-key', 'resp3-element');
35+
3136
assert.equal(nullResult, null);
3237

3338
// Set complex attributes and retrieve them
@@ -41,6 +46,7 @@ describe('VGETATTR', () => {
4146
await client.vSetAttr('resp3-key', 'resp3-element', complexAttrs);
4247

4348
const result = await client.vGetAttr('resp3-key', 'resp3-element');
49+
4450
assert.ok(result !== null);
4551

4652
// Parse the JSON result and verify structure

0 commit comments

Comments
 (0)