This repository was archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilters.test.js
More file actions
130 lines (117 loc) · 4.5 KB
/
Copy pathfilters.test.js
File metadata and controls
130 lines (117 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
const assert = require('assert');
const { Op } = require('sequelize');
const { filterToSequelizeWhereClause } = require('../../../app/lib/server/utilities');
module.exports = () => {
describe('Server utils', () => {
describe('Transforming filters to sequelize where-cluase ', () => {
it('should return empty object when provided with undefined or empty object', () => {
assert.deepStrictEqual(filterToSequelizeWhereClause(undefined), {});
assert.deepStrictEqual(filterToSequelizeWhereClause({}), {});
});
it('should handle syntax for default relational operator \'eq\'', () => {
const srcFilter = {
not: {
field3: 1,
},
};
const expectedFilter = {
[Op.not]: {
field3: 1,
},
};
assert.deepStrictEqual(expectedFilter, filterToSequelizeWhereClause(srcFilter));
});
it('should transform filter object - with pruning', () => {
const srcFilter = {
or: {
field1: {
gt: '10',
lt: '3',
_goperator: 'or',
},
filed2: {
like: 'LHC_%pass',
notLike: 'LHC_c%',
},
},
};
const expectedFilter = {
[Op.or]: {
field1: {
[Op.or]: {
[Op.gt]: '10',
[Op.lt]: '3',
},
},
filed2: {
[Op.like]: 'LHC_%pass',
[Op.notLike]: 'LHC_c%',
},
},
};
assert.deepStrictEqual(expectedFilter, filterToSequelizeWhereClause(srcFilter));
});
it('should transform filter object - without pruning', () => {
const srcFilter = {
field1: {
gt: '10',
lt: '3',
_goperator: 'or',
},
filed2: {
like: 'LHC_%pass',
notLike: 'LHC_c%',
},
};
const expectedFilter = {
[Op.and]: {
field1: {
[Op.or]: {
[Op.gt]: '10',
[Op.lt]: '3',
},
},
filed2: {
[Op.and]: {
[Op.like]: 'LHC_%pass',
[Op.notLike]: 'LHC_c%',
},
},
},
};
assert.deepStrictEqual(expectedFilter, filterToSequelizeWhereClause(srcFilter, false));
});
it('should transform filter object containing array values - with pruning', () => {
const srcFilter = {
field1: {
in: '1,2,4,5 ,1',
},
filed2: {
notBetween: '-123,1.1',
},
};
const expectedFilter = {
field1: {
[Op.in]: ['1', '2', '4', '5', '1'],
},
filed2: {
[Op.notBetween]: ['-123', '1.1'],
},
};
assert.deepStrictEqual(expectedFilter, filterToSequelizeWhereClause(srcFilter));
});
});
});
};