Skip to content

Commit 61cec9d

Browse files
committed
increase test coverage
1 parent 4097258 commit 61cec9d

File tree

9 files changed

+97
-38
lines changed

9 files changed

+97
-38
lines changed

lib/cluster/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Cluster', () => {
3131
itWithCluster(TestRedisClusters.OPEN, 'multi', async cluster => {
3232
const key = 'key';
3333
assert.deepEqual(
34-
await cluster.multi(key)
34+
await cluster.multi()
3535
.set(key, 'value')
3636
.get(key)
3737
.exec(),

lib/commands/GEODIST.spec.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,33 @@ describe('GEODIST', () => {
1919
});
2020
});
2121

22-
itWithClient(TestRedisServers.OPEN, 'client.geoDist', async client => {
23-
assert.equal(
24-
await client.geoDist('key', '1', '2'),
25-
null
26-
);
22+
describe('client.geoDist', () => {
23+
itWithClient(TestRedisServers.OPEN, 'null', async client => {
24+
assert.equal(
25+
await client.geoDist('key', '1', '2'),
26+
null
27+
);
28+
});
29+
30+
itWithClient(TestRedisServers.OPEN, 'with value', async client => {
31+
const [, dist] = await Promise.all([
32+
client.geoAdd('key', [{
33+
member: '1',
34+
longitude: 1,
35+
latitude: 1
36+
}, {
37+
member: '2',
38+
longitude: 2,
39+
latitude: 2
40+
}]),
41+
client.geoDist('key', '1', '2')
42+
]);
43+
44+
assert.equal(
45+
dist,
46+
157270.0561
47+
);
48+
});
2749
});
2850

2951
itWithCluster(TestRedisClusters.OPEN, 'cluster.geoDist', async cluster => {

lib/commands/HELLO.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function transformArguments(options?: HelloOptions): Array<string> {
1212
if (options) {
1313
args.push(options.protover.toString());
1414

15-
if (options?.auth) {
15+
if (options.auth) {
1616
args.push('AUTH', options.auth.username, options.auth.password);
1717
}
1818

lib/commands/HSET.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ describe('HSET', () => {
2626
});
2727

2828
it('Object', () => {
29-
it('Array', () => {
30-
assert.deepEqual(
31-
transformArguments('key', { field: 'value' }),
32-
['HSET', 'key', 'field', 'value']
33-
);
34-
});
29+
assert.deepEqual(
30+
transformArguments('key', { field: 'value' }),
31+
['HSET', 'key', 'field', 'value']
32+
);
3533
});
3634
});
3735

lib/commands/XREAD.spec.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import { strict as assert } from 'assert';
22
import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters } from '../test-utils';
3-
import { transformArguments } from './XREAD';
3+
import { FIRST_KEY_INDEX, transformArguments } from './XREAD';
44

55
describe('XREAD', () => {
6+
describe('FIRST_KEY_INDEX', () => {
7+
it('single stream', () => {
8+
assert.equal(
9+
FIRST_KEY_INDEX({ key: 'key', id: '' }),
10+
'key'
11+
);
12+
});
13+
14+
it('multiple streams', () => {
15+
assert.equal(
16+
FIRST_KEY_INDEX([{ key: '1', id: '' }, { key: '2', id: '' }]),
17+
'1'
18+
);
19+
});
20+
});
21+
622
describe('transformArguments', () => {
723
it('single stream', () => {
824
assert.deepEqual(
@@ -13,13 +29,13 @@ describe('XREAD', () => {
1329
['XREAD', 'STREAMS', 'key', '0']
1430
);
1531
});
16-
32+
1733
it('multiple streams', () => {
1834
assert.deepEqual(
1935
transformArguments([{
2036
key: '1',
2137
id: '0'
22-
}, {
38+
}, {
2339
key: '2',
2440
id: '0'
2541
}]),

lib/commands/XREADGROUP.spec.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import { strict as assert } from 'assert';
22
import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters } from '../test-utils';
3-
import { transformArguments } from './XREADGROUP';
3+
import { FIRST_KEY_INDEX, transformArguments } from './XREADGROUP';
44

55
describe('XREADGROUP', () => {
6+
describe('FIRST_KEY_INDEX', () => {
7+
it('single stream', () => {
8+
assert.equal(
9+
FIRST_KEY_INDEX('', '', { key: 'key', id: '' }),
10+
'key'
11+
);
12+
});
13+
14+
it('multiple streams', () => {
15+
assert.equal(
16+
FIRST_KEY_INDEX('', '', [{ key: '1', id: '' }, { key: '2', id: '' }]),
17+
'1'
18+
);
19+
});
20+
});
21+
622
describe('transformArguments', () => {
723
it('single stream', () => {
824
assert.deepEqual(
@@ -78,13 +94,27 @@ describe('XREADGROUP', () => {
7894
});
7995
});
8096

81-
describe('client.xReadGroup', () => {
82-
itWithClient(TestRedisServers.OPEN, 'null', async client => {
97+
itWithClient(TestRedisServers.OPEN, 'null', async client => {
98+
const [, readGroupReply] = await Promise.all([
99+
client.xGroupCreate('key', 'group', '$', {
100+
MKSTREAM: true
101+
}),
102+
client.xReadGroup('group', 'consumer', {
103+
key: 'key',
104+
id: '>'
105+
})
106+
]);
107+
108+
assert.equal(readGroupReply, null);
109+
});
110+
111+
describe('cluster.xReadGroup', () => {
112+
itWithCluster(TestRedisClusters.OPEN, 'null', async cluster => {
83113
const [, readGroupReply] = await Promise.all([
84-
client.xGroupCreate('key', 'group', '$', {
114+
cluster.xGroupCreate('key', 'group', '$', {
85115
MKSTREAM: true
86116
}),
87-
client.xReadGroup('group', 'consumer', {
117+
cluster.xReadGroup('group', 'consumer', {
88118
key: 'key',
89119
id: '>'
90120
})
@@ -93,7 +123,7 @@ describe('XREADGROUP', () => {
93123
assert.equal(readGroupReply, null);
94124
});
95125

96-
itWithClient(TestRedisServers.OPEN, 'with a message', async client => {
126+
itWithCluster(TestRedisClusters.OPEN, 'with a message', async client => {
97127
const [, id, readGroupReply] = await Promise.all([
98128
client.xGroupCreate('key', 'group', '$', {
99129
MKSTREAM: true
@@ -120,18 +150,4 @@ describe('XREADGROUP', () => {
120150
}]);
121151
});
122152
});
123-
124-
itWithCluster(TestRedisClusters.OPEN, 'cluster.xReadGroup', async cluster => {
125-
const [, readGroupReply] = await Promise.all([
126-
cluster.xGroupCreate('key', 'group', '$', {
127-
MKSTREAM: true
128-
}),
129-
cluster.xReadGroup('group', 'consumer', {
130-
key: 'key',
131-
id: '>'
132-
})
133-
]);
134-
135-
assert.equal(readGroupReply, null);
136-
});
137153
});

lib/commands/ZINTER.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function transformArguments(keys: Array<string> | string, options?: ZInte
2121
}
2222

2323
if (options?.AGGREGATE) {
24-
args.push('AGGREGATE', options?.AGGREGATE);
24+
args.push('AGGREGATE', options.AGGREGATE);
2525
}
2626

2727
return args;

lib/commands/ZINTERSTORE.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function transformArguments(destination: string, keys: Array<string> | st
1919
}
2020

2121
if (options?.AGGREGATE) {
22-
args.push('AGGREGATE', options?.AGGREGATE);
22+
args.push('AGGREGATE', options.AGGREGATE);
2323
}
2424

2525
return args;

lib/commands/ZRANGE.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ describe('ZRANGE', () => {
1111
);
1212
});
1313

14+
it('using strings', () => {
15+
assert.deepEqual(
16+
transformArguments('src', '0', '1'),
17+
['ZRANGE', 'src', '0', '1']
18+
);
19+
});
20+
1421
it('with BYSCORE', () => {
1522
assert.deepEqual(
1623
transformArguments('src', 0, 1, {

0 commit comments

Comments
 (0)