Skip to content

Commit e4d99a8

Browse files
committed
clean code
1 parent 3a17355 commit e4d99a8

31 files changed

+724
-948
lines changed

packages/time-series/lib/commands/ALTER.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('ALTER', () => {
4141
});
4242

4343
testUtils.testWithClient('client.ts.alter', async client => {
44-
await client.ts.create('key');
44+
await client.ts.create('key');
4545

4646
assert.equal(
4747
await client.ts.alter('key', { RETENTION: 1 }),

packages/time-series/lib/commands/CREATE.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ describe('CREATE', () => {
5151
it('with LABELS', () => {
5252
assert.deepEqual(
5353
transformArguments('key', {
54-
LABELS: { label: 'value', label2: 'newValue' }
54+
LABELS: { label: 'value' }
5555
}),
56-
['TS.CREATE', 'key', 'LABELS', 'label', 'value', 'label2', 'newValue']
56+
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
5757
);
5858
});
5959

packages/time-series/lib/commands/DECRBY.spec.ts

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('DECRBY', () => {
1010
['TS.DECRBY', 'key', '1']
1111
);
1212
});
13-
13+
1414
it('with TIMESTAMP', () => {
1515
assert.deepEqual(
1616
transformArguments('key', 1, {
@@ -19,16 +19,16 @@ describe('DECRBY', () => {
1919
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*']
2020
);
2121
});
22-
22+
2323
it('with RETENTION', () => {
2424
assert.deepEqual(
2525
transformArguments('key', 1, {
26-
RETENTION: 100
26+
RETENTION: 1
2727
}),
28-
['TS.DECRBY', 'key', '1', 'RETENTION', '100']
28+
['TS.DECRBY', 'key', '1', 'RETENTION', '1']
2929
);
3030
});
31-
31+
3232
it('with UNCOMPRESSED', () => {
3333
assert.deepEqual(
3434
transformArguments('key', 1, {
@@ -37,16 +37,7 @@ describe('DECRBY', () => {
3737
['TS.DECRBY', 'key', '1', 'UNCOMPRESSED']
3838
);
3939
});
40-
41-
it('without UNCOMPRESSED', () => {
42-
assert.deepEqual(
43-
transformArguments('key', 1, {
44-
UNCOMPRESSED: false
45-
}),
46-
['TS.DECRBY', 'key', '1']
47-
);
48-
});
49-
40+
5041
it('with CHUNK_SIZE', () => {
5142
assert.deepEqual(
5243
transformArguments('key', 1, {
@@ -55,7 +46,7 @@ describe('DECRBY', () => {
5546
['TS.DECRBY', 'key', '1', 'CHUNK_SIZE', '100']
5647
);
5748
});
58-
49+
5950
it('with LABELS', () => {
6051
assert.deepEqual(
6152
transformArguments('key', 1, {
@@ -64,40 +55,27 @@ describe('DECRBY', () => {
6455
['TS.DECRBY', 'key', '1', 'LABELS', 'label', 'value']
6556
);
6657
});
67-
58+
6859
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
6960
assert.deepEqual(
7061
transformArguments('key', 1, {
7162
TIMESTAMP: '*',
72-
RETENTION: 100,
63+
RETENTION: 1,
7364
UNCOMPRESSED: true,
74-
CHUNK_SIZE: 1000,
75-
LABELS: { label: 'value', label2: 'new_value' }
65+
CHUNK_SIZE: 2,
66+
LABELS: { label: 'value' }
7667
}),
77-
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '100', 'UNCOMPRESSED',
78-
'CHUNK_SIZE', '1000', 'LABELS', 'label', 'value', 'label2', 'new_value']
68+
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value']
7969
);
8070
});
8171
});
8272

8373
testUtils.testWithClient('client.ts.decrBy', async client => {
84-
await Promise.all([
85-
client.ts.create('key'),
86-
]);
87-
8874
assert.equal(
8975
await client.ts.decrBy('key', 1, {
90-
TIMESTAMP: 1638267369476
76+
TIMESTAMP: 0
9177
}),
92-
1638267369476
93-
);
94-
95-
assert.deepEqual(
96-
await client.ts.get('key'),
97-
{
98-
timestamp: 1638267369476,
99-
value: -1
100-
}
78+
0
10179
);
10280
}, GLOBAL.SERVERS.OPEN);
10381
});

packages/time-series/lib/commands/DEL.spec.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@ import { transformArguments } from './DEL';
55
describe('DEL', () => {
66
it('transformArguments', () => {
77
assert.deepEqual(
8-
transformArguments('key', 1, 10),
9-
['TS.DEL', 'key', '1', '10']
8+
transformArguments('key', '-', '+'),
9+
['TS.DEL', 'key', '-', '+']
1010
);
1111
});
1212

1313
testUtils.testWithClient('client.ts.del', async client => {
14-
await Promise.all([
15-
client.ts.create('key'),
16-
client.ts.add('key', 1, 2),
17-
client.ts.add('key', 2, 3)
18-
]);
14+
await client.ts.create('key');
1915

2016
assert.equal(
21-
await client.ts.del('key', 1, 100),
22-
2
23-
);
24-
25-
assert.equal(
26-
await client.ts.get('key'),
27-
null
17+
await client.ts.del('key', '-', '+'),
18+
0
2819
);
2920
}, GLOBAL.SERVERS.OPEN);
3021
});

packages/time-series/lib/commands/DELETERULE.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const FIRST_KEY_INDEX = 1;
22

3-
export function transformArguments(sourceKey: string, destinationKey: string,): Array<string> {
3+
export function transformArguments(sourceKey: string, destinationKey: string): Array<string> {
44
return [
55
'TS.DELETERULE',
66
sourceKey,

packages/time-series/lib/commands/GET.spec.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,26 @@ describe('GET', () => {
1010
);
1111
});
1212

13-
testUtils.testWithClient('client.ts.get', async client => {
14-
await Promise.all([
15-
client.ts.create('key'),
16-
client.ts.add('key', 1, 2)
17-
]);
13+
describe('client.ts.get', () => {
14+
testUtils.testWithClient('null', async client => {
15+
await client.ts.create('key');
1816

19-
assert.deepEqual(
20-
await client.ts.get('key'),
21-
{
22-
timestamp: 1,
23-
value: 2
24-
}
25-
);
26-
}, GLOBAL.SERVERS.OPEN);
17+
assert.equal(
18+
await client.ts.get('key'),
19+
null
20+
);
21+
}, GLOBAL.SERVERS.OPEN);
22+
23+
testUtils.testWithClient('with samples', async client => {
24+
await client.ts.add('key', 0, 1);
25+
26+
assert.deepEqual(
27+
await client.ts.get('key'),
28+
{
29+
timestamp: 0,
30+
value: 1
31+
}
32+
);
33+
}, GLOBAL.SERVERS.OPEN);
34+
});
2735
});

packages/time-series/lib/commands/INCRBY.spec.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ describe('INCRBY', () => {
2323
it('with RETENTION', () => {
2424
assert.deepEqual(
2525
transformArguments('key', 1, {
26-
RETENTION: 100
26+
RETENTION: 1
2727
}),
28-
['TS.INCRBY', 'key', '1', 'RETENTION', '100']
28+
['TS.INCRBY', 'key', '1', 'RETENTION', '1']
2929
);
3030
});
3131

@@ -50,9 +50,9 @@ describe('INCRBY', () => {
5050
it('with CHUNK_SIZE', () => {
5151
assert.deepEqual(
5252
transformArguments('key', 1, {
53-
CHUNK_SIZE: 100
53+
CHUNK_SIZE: 1
5454
}),
55-
['TS.INCRBY', 'key', '1', 'CHUNK_SIZE', '100']
55+
['TS.INCRBY', 'key', '1', 'CHUNK_SIZE', '1']
5656
);
5757
});
5858

@@ -69,35 +69,23 @@ describe('INCRBY', () => {
6969
assert.deepEqual(
7070
transformArguments('key', 1, {
7171
TIMESTAMP: '*',
72-
RETENTION: 100,
72+
RETENTION: 1,
7373
UNCOMPRESSED: true,
74-
CHUNK_SIZE: 1000,
75-
LABELS: { label: 'value', label2: 'new_value' }
74+
CHUNK_SIZE: 1,
75+
LABELS: { label: 'value' }
7676
}),
77-
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '100', 'UNCOMPRESSED',
78-
'CHUNK_SIZE', '1000', 'LABELS', 'label', 'value', 'label2', 'new_value']
77+
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED',
78+
'CHUNK_SIZE', '1', 'LABELS', 'label', 'value']
7979
);
8080
});
8181
});
8282

8383
testUtils.testWithClient('client.ts.incrBy', async client => {
84-
await Promise.all([
85-
client.ts.create('key'),
86-
]);
87-
8884
assert.equal(
8985
await client.ts.incrBy('key', 1, {
90-
TIMESTAMP: 1638267369476
86+
TIMESTAMP: 0
9187
}),
92-
1638267369476
93-
);
94-
95-
assert.deepEqual(
96-
await client.ts.get('key'),
97-
{
98-
timestamp: 1638267369476,
99-
value: 1
100-
}
88+
0
10189
);
10290
}, GLOBAL.SERVERS.OPEN);
10391
});

packages/time-series/lib/commands/MADD.spec.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,35 @@ import { transformArguments } from './MADD';
55
describe('MADD', () => {
66
it('transformArguments', () => {
77
assert.deepEqual(
8-
transformArguments([
9-
{
10-
key: 'key',
11-
timestamp: 0,
12-
value: 0
13-
},
14-
{
15-
key: 'key2',
16-
timestamp: 1,
17-
value: 1
18-
}]),
19-
['TS.MADD', 'key', '0', '0', 'key2', '1', '1']
8+
transformArguments([{
9+
key: '1',
10+
timestamp: 0,
11+
value: 0
12+
}, {
13+
key: '2',
14+
timestamp: 1,
15+
value: 1
16+
}]),
17+
['TS.MADD', '1', '0', '0', '2', '1', '1']
2018
);
2119
});
2220

2321
// Should we check empty array?
2422

25-
testUtils.testWithClient('client.ts.madd', async client => {
26-
await Promise.all([
27-
client.ts.create('key')
28-
]);
29-
23+
testUtils.testWithClient('client.ts.mAdd', async client => {
24+
await client.ts.create('key');
25+
3026
assert.deepEqual(
31-
await client.ts.mAdd([
32-
{
33-
key: 'key',
34-
timestamp: 1,
35-
value: 0
36-
},
37-
{
38-
key: 'key',
39-
timestamp: 2,
40-
value: 10
41-
}]),
42-
[1, 2]
27+
await client.ts.mAdd([{
28+
key: 'key',
29+
timestamp: 0,
30+
value: 0
31+
}, {
32+
key: 'key',
33+
timestamp: 1,
34+
value: 1
35+
}]),
36+
[0, 1]
4337
);
4438
}, GLOBAL.SERVERS.OPEN);
4539
});

packages/time-series/lib/commands/MGET.spec.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,25 @@ import { transformArguments } from './MGET';
55
describe('MGET', () => {
66
it('transformArguments', () => {
77
assert.deepEqual(
8-
transformArguments(['name=value', 'age!=']),
9-
['TS.MGET', 'FILTER', 'name=value', 'age!=']
8+
transformArguments('label=value'),
9+
['TS.MGET', 'FILTER', 'label=value']
1010
);
1111
});
12-
1312

14-
testUtils.testWithClient('client.ts.mget', async client => {
15-
await Promise.all([
16-
client.ts.create('key', {
17-
LABELS: {Test: 'This'}
18-
}),
19-
client.ts.add('key', 10, 15),
20-
]);
13+
testUtils.testWithClient('client.ts.mGet', async client => {
14+
await client.ts.add('key', 0, 0, {
15+
LABELS: { label: 'value' }
16+
});
2117

2218
assert.deepEqual(
23-
await client.ts.mGet(['Test=This']),
24-
[
25-
{
26-
key: 'key',
27-
sample: {
28-
timestamp: 10,
29-
value: 15
30-
}
19+
await client.ts.mGet('label=value'),
20+
[{
21+
key: 'key',
22+
sample: {
23+
timestamp: 0,
24+
value: 0
3125
}
32-
]
26+
}]
3327
);
3428
}, GLOBAL.SERVERS.OPEN);
3529
});

0 commit comments

Comments
 (0)