Debian Codegraph @

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

raw
1 import { strict as assert } from 'assert';
2 import testUtils, { GLOBAL } from '../test-utils';
3 import { transformArguments } from './REVRANGE';
4 import { TimeSeriesAggregationType } from '.';
5
6 describe('REVRANGE', () => {
7 describe('transformArguments', () => {
8 it('without options', () => {
9 assert.deepEqual(
10 transformArguments('key', '-', '+'),
11 ['TS.REVRANGE', 'key', '-', '+']
12 );
13 });
14
15 it('with FILTER_BY_TS', () => {
16 assert.deepEqual(
17 transformArguments('key', '-', '+', {
18 FILTER_BY_TS: [0]
19 }),
20 ['TS.REVRANGE', 'key', '-', '+', 'FILTER_BY_TS', '0']
21 );
22 });
23
24 it('with FILTER_BY_VALUE', () => {
25 assert.deepEqual(
26 transformArguments('key', '-', '+', {
27 FILTER_BY_VALUE: {
28 min: 1,
29 max: 2
30 }
31 }),
32 ['TS.REVRANGE', 'key', '-', '+', 'FILTER_BY_VALUE', '1', '2']
33 );
34 });
35
36 it('with COUNT', () => {
37 assert.deepEqual(
38 transformArguments('key', '-', '+', {
39 COUNT: 1
40 }),
41 ['TS.REVRANGE', 'key', '-', '+', 'COUNT', '1']
42 );
43 });
44
45 it('with ALIGN', () => {
46 assert.deepEqual(
47 transformArguments('key', '-', '+', {
48 ALIGN: '-'
49 }),
50 ['TS.REVRANGE', 'key', '-', '+', 'ALIGN', '-']
51 );
52 });
53
54 it('with AGGREGATION', () => {
55 assert.deepEqual(
56 transformArguments('key', '-', '+', {
57 AGGREGATION: {
58 type: TimeSeriesAggregationType.AVERAGE,
59 timeBucket: 1
60 }
61 }),
62 ['TS.REVRANGE', 'key', '-', '+', 'AGGREGATION', 'AVG', '1']
63 );
64 });
65
66 it('with FILTER_BY_TS, FILTER_BY_VALUE, COUNT, ALIGN, AGGREGATION', () => {
67 assert.deepEqual(
68 transformArguments('key', '-', '+', {
69 FILTER_BY_TS: [0],
70 FILTER_BY_VALUE: {
71 min: 1,
72 max: 2
73 },
74 COUNT: 1,
75 ALIGN: '-',
76 AGGREGATION: {
77 type: TimeSeriesAggregationType.AVERAGE,
78 timeBucket: 1
79 }
80 }),
81 [
82 'TS.REVRANGE', 'key', '-', '+', 'FILTER_BY_TS', '0', 'FILTER_BY_VALUE',
83 '1', '2', 'COUNT', '1', 'ALIGN', '-', 'AGGREGATION', 'AVG', '1'
84 ]
85 );
86 });
87 });
88
89 testUtils.testWithClient('client.ts.revRange', async client => {
90 await Promise.all([
91 client.ts.add('key', 0, 1),
92 client.ts.add('key', 1, 2)
93 ]);
94
95 assert.deepEqual(
96 await client.ts.revRange('key', '-', '+'),
97 [{
98 timestamp: 1,
99 value: 2
100 }, {
101 timestamp: 0,
102 value: 1
103 }]
104 );
105 }, GLOBAL.SERVERS.OPEN);
106 });