sqlparser-devexpress 2.5.9 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/converter.js +32 -4
- package/src/core/parser.js +4 -1
- package/tests/fixtures/FilterCases.json +1579 -0
- package/tests/parser.test.js +27 -574
package/tests/parser.test.js
CHANGED
|
@@ -1,589 +1,42 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { convertToDevExpressFormat } from "../src/core/converter";
|
|
3
|
-
import { parse } from "../src/core/parser";
|
|
4
|
-
import { sanitizeQuery } from "../src/core/sanitizer";
|
|
5
3
|
import { convertAstToDevextreme, convertSQLToAst } from "../src";
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
expected: [
|
|
12
|
-
// [
|
|
13
|
-
"ID", "=", 42
|
|
14
|
-
// ],
|
|
15
|
-
// "or",
|
|
16
|
-
// [42, "=", null],
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
input: "GroupNo = {Employee.District} OR ISNULL(GroupNo,0) = 0 OR {Employee.District} = 0",
|
|
21
|
-
expected: [
|
|
22
|
-
// ["GroupNo", "=", 0],
|
|
23
|
-
// "or",
|
|
24
|
-
// ["GroupNo", "=", null],
|
|
25
|
-
// "or",
|
|
26
|
-
// [0, "=", 0],
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
input: "ContactID = {SaleInvoiceDocument.ContactID} AND AddressType IN (2, 4)",
|
|
31
|
-
expected: [
|
|
32
|
-
["ContactID", "=", 42],
|
|
33
|
-
"and",
|
|
34
|
-
[["AddressType", "=", 2], 'or', ["AddressType", "=", 4]],
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
input: "ID IN ({WorkOrderLine.ApplicableUoms}) AND (CompanyID = {WorkOrderDocument.CompanyID} OR {WorkOrderDocument.CompanyID} = 0)",
|
|
39
|
-
expected: [
|
|
40
|
-
[["ID", "=", "UOM1"], 'or', ["ID", "=", "UOM2"], 'or', ["ID", "=", "UOM3"]],
|
|
41
|
-
"and",
|
|
42
|
-
// [
|
|
43
|
-
["CompanyID", "=", 42],
|
|
44
|
-
// "or",
|
|
45
|
-
// [42, "=", 0],
|
|
46
|
-
// ],
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
input: "CompanyID = {AccountingRule.CompanyID}",
|
|
51
|
-
expected: [
|
|
52
|
-
"CompanyID", "=", 42,
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
input: "(Level > {Area.AreaType})",
|
|
57
|
-
expected: [
|
|
58
|
-
"Level", ">", 42
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
input: "(ID <> {Item.ID}) AND (ItemGroupType IN ({Item.AllowedItemGroupType}))",
|
|
63
|
-
expected: [
|
|
64
|
-
["ID", "<>", 42],
|
|
65
|
-
'and',
|
|
66
|
-
[["ItemGroupType", "=", "1"], 'or', ["ItemGroupType", "=", "2"]]
|
|
67
|
-
]
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
input: "((FromDate <= '{TransferOutwardDocument.DocDate}' AND ToDate >= '{TransferOutwardDocument.DocDate}') OR ToDate is NULL) AND (BranchID = {TransferOutwardDocument.RefBranchID} OR RefBranchID is NULL) AND (CompanyID = {TransferOutwardDocument.CompanyID} OR {TransferOutwardDocument.CompanyID} = 0 OR CompanyID is NULL)",
|
|
71
|
-
expected: [
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
["FromDate", "<=", "2022-01-01"],
|
|
76
|
-
'and',
|
|
77
|
-
["ToDate", ">=", "2022-01-01"]
|
|
78
|
-
],
|
|
79
|
-
'or',
|
|
80
|
-
["ToDate", "=", null, { "type": "IS" }, null]
|
|
81
|
-
],
|
|
82
|
-
"and",
|
|
83
|
-
[
|
|
84
|
-
["BranchID", "=", 42],
|
|
85
|
-
"or",
|
|
86
|
-
["RefBranchID", "=", null, { "type": "IS" }, null]
|
|
87
|
-
]
|
|
88
|
-
],
|
|
89
|
-
"and",
|
|
90
|
-
[
|
|
91
|
-
["CompanyID", "=", 7],
|
|
92
|
-
// "or",
|
|
93
|
-
// [7,"=",0],
|
|
94
|
-
"or",
|
|
95
|
-
["CompanyID", "=", null, { "type": "IS" }, null]
|
|
96
|
-
]
|
|
97
|
-
]
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
input: "(ID <> {Item.ID}) AND ( ItemGroupType = '''')",
|
|
101
|
-
expected: [
|
|
102
|
-
["ID", "<>", 42],
|
|
103
|
-
'and',
|
|
104
|
-
["ItemGroupType", "=", ""]
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
input: "((ISNULL({0}, 0) = 0 AND CompanyID = {1}) OR CompanyID IS NULL) OR BranchID = {0} | [LeadDocument.BranchID] | [LeadDocument.CompanyID]",
|
|
109
|
-
expected: [
|
|
110
|
-
// [
|
|
111
|
-
// [
|
|
112
|
-
// [42,"=",null],
|
|
113
|
-
// "and",
|
|
114
|
-
["CompanyID", "=", 7],
|
|
115
|
-
// ],
|
|
116
|
-
"or",
|
|
117
|
-
["CompanyID", "=", null, { "type": "IS" }, null],
|
|
118
|
-
// ],
|
|
119
|
-
'or',
|
|
120
|
-
["BranchID", "=", 42]
|
|
121
|
-
]
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
input: "FromDate Between '10-10-2021' AND '10-10-2022'",
|
|
125
|
-
expected: [
|
|
126
|
-
"FromDate", "between", ["10-10-2021", "10-10-2022"]
|
|
127
|
-
]
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
input: "BranchID is Null OR BranchID is not 12",
|
|
131
|
-
expected: [
|
|
132
|
-
["BranchID", "=", null, { "type": "IS" }, null],
|
|
133
|
-
"or",
|
|
134
|
-
["BranchID", "!=", 12, { "type": "IS NOT" }, 12]
|
|
135
|
-
]
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
input: "ISNULL(SourceID,0) = {ServiceOrderDocument.SourceID} OR ISNULL(SourceID,0) = 0",
|
|
139
|
-
expected: [
|
|
140
|
-
["SourceID", "=", 2, { "defaultValue": 0, "position": "column", "type": "ISNULL" }, 2],
|
|
141
|
-
"or",
|
|
142
|
-
[
|
|
143
|
-
["SourceID", "=", 0],
|
|
144
|
-
"or",
|
|
145
|
-
["SourceID", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL" }, null],
|
|
146
|
-
"or",
|
|
147
|
-
["SourceID", "=", false]
|
|
148
|
-
]
|
|
149
|
-
]
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
input: "(CompanyID = {LeadDocument.CompanyID} OR ISNULL(CompanyID,0) = 0) AND (ISNULL(IsSubdealer,0) = {LeadDocument.AllowSubDealer})",
|
|
153
|
-
expected: [
|
|
154
|
-
[
|
|
155
|
-
["CompanyID", "=", 7],
|
|
156
|
-
"or",
|
|
157
|
-
[
|
|
158
|
-
["CompanyID", "=", 0],
|
|
159
|
-
"or",
|
|
160
|
-
["CompanyID", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL" }, null],
|
|
161
|
-
"or",
|
|
162
|
-
["CompanyID", "=", false]
|
|
163
|
-
]
|
|
164
|
-
],
|
|
165
|
-
"and",
|
|
166
|
-
// [
|
|
167
|
-
// ["IsSubdealer", "=", 0],
|
|
168
|
-
// "or",
|
|
169
|
-
// ["IsSubdealer", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL" }, null],
|
|
170
|
-
// "or",
|
|
171
|
-
["IsSubdealer", "=", true, { "defaultValue": 0, "position": "column", "type": "ISNULL" }, true],
|
|
172
|
-
// ]
|
|
173
|
-
]
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
input: 'AddressType NOT IN (2, 4)',
|
|
177
|
-
expected: [
|
|
178
|
-
["AddressType", "!=", 2],
|
|
179
|
-
"and",
|
|
180
|
-
["AddressType", "!=", 4]
|
|
181
|
-
]
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
input: "AddressType IN ('2', ('4')) OR AddressType =({ServiceOrderDocument .SourceID})",
|
|
185
|
-
expected: [
|
|
186
|
-
["AddressType", "=", '2'],
|
|
187
|
-
"or",
|
|
188
|
-
["AddressType", "=", '4'],
|
|
189
|
-
"or",
|
|
190
|
-
["AddressType", "=", 2]
|
|
191
|
-
]
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
input: "(ISNULL(TicketID, 0) = ISNULL({SupportResolution.TicketID}, 0))",
|
|
195
|
-
expected: [
|
|
196
|
-
["TicketID", "=", 123, { "type": "ISNULL", "position": "both", "defaultValue": 0, "defaultValueRight": 0 }, 123],
|
|
197
|
-
"or",
|
|
198
|
-
["TicketID", "=", null]
|
|
199
|
-
]
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
input: "CompanyID = ISNULL({LeadDocument.CompanyID},0) OR (ISNULL(CompanyID,0) = 0))",
|
|
203
|
-
expected: [
|
|
204
|
-
["CompanyID", "=", 7, { "type": "ISNULL", "position": "value", "defaultValue": 0 }, 7],
|
|
205
|
-
"or",
|
|
206
|
-
[
|
|
207
|
-
["CompanyID", "=", 0],
|
|
208
|
-
"or",
|
|
209
|
-
["CompanyID", "=", null, { "type": "ISNULL", "position": "column", "defaultValue": 0 }, null],
|
|
210
|
-
"or",
|
|
211
|
-
["CompanyID", "=", false]
|
|
212
|
-
]
|
|
213
|
-
]
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
input: "CompanyName like '{LeadDocument.CompanyID}' AND BranchName not like '{LeadDocument.BranchID}'",
|
|
217
|
-
expected: [
|
|
218
|
-
["CompanyName", "contains", "7"],
|
|
219
|
-
"and",
|
|
220
|
-
["BranchName", "notcontains", "42"]
|
|
221
|
-
]
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
input: "(RS2ID in ({SaleOrderStatusStmtGlobalRpt.StateID}) Or (ISNULL({SaleOrderStatusStmtGlobalRpt.StateID},0) =0)) And (RS3ID in (0,{SaleOrderStatusStmtGlobalRpt.RegionID}) Or ISNULL({SaleOrderStatusStmtGlobalRpt.RegionID},0) =0 )",
|
|
225
|
-
expected: []
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
input: "ID IN ({WorkOrderLine.CompanyIDs}) AND 0 IN ({WorkOrderLine.CompanyIDs})",
|
|
229
|
-
expected: [
|
|
230
|
-
["ID", "=", "0"],
|
|
231
|
-
"or",
|
|
232
|
-
["ID", "=", "1"]
|
|
233
|
-
]
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
input: "CompanyID is null OR CompanyID is 7 OR CompanyID is not 8",
|
|
237
|
-
expected: [
|
|
238
|
-
["CompanyID", "=", null, { "type": "IS" }, null],
|
|
239
|
-
"or",
|
|
240
|
-
["CompanyID", "=", 7, { "type": "IS" }, 7],
|
|
241
|
-
"or",
|
|
242
|
-
["CompanyID", "!=", 8, { "type": "IS NOT" }, 8]
|
|
243
|
-
]
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
input: "null = 0",
|
|
247
|
-
expected: []
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
input: "null = null",
|
|
251
|
-
expected: []
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
input: "null = {SaleOrderStatusStmtGlobalRpt.StateID}",
|
|
255
|
-
expected: []
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
input: "null = {SaleOrderStatusStmtGlobalRpt.RegionID}",
|
|
259
|
-
expected: []
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
input: "null = {LeadDocument.CompanyID}",
|
|
263
|
-
expected: []
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
input: "{LeadDocument.BranchID} = null",
|
|
267
|
-
expected: []
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
input: "{LeadDocument.AllowSubDealer} != null",
|
|
271
|
-
expected: []
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
input: "ID = {SaleOrderStatusStmtGlobalRpt.RegionID}",
|
|
275
|
-
expected: []
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
input: "ID IN ({SaleOrderStatusStmtGlobalRpt.RegionID})",
|
|
279
|
-
expected: ["ID","=",null]
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
input: "10 < ID AND ApplicableUoms IN ({WorkOrderLine.ApplicableUoms})",
|
|
283
|
-
expected: [
|
|
284
|
-
["ID", ">", 10],
|
|
285
|
-
"and",
|
|
286
|
-
[
|
|
287
|
-
["ApplicableUoms", "=", "UOM1"],
|
|
288
|
-
"or",
|
|
289
|
-
["ApplicableUoms", "=", "UOM2"],
|
|
290
|
-
"or",
|
|
291
|
-
["ApplicableUoms", "=", "UOM3"]
|
|
292
|
-
]
|
|
293
|
-
],
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
input: "{ServiceOrderDocument.SourceID} = ID",
|
|
297
|
-
expected: [
|
|
298
|
-
"ID", "=", 2
|
|
299
|
-
]
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
input: "IsChecked = 1",
|
|
303
|
-
expected: [
|
|
304
|
-
["IsChecked", "=", 1],
|
|
305
|
-
"or",
|
|
306
|
-
["IsChecked", "=", true]
|
|
307
|
-
]
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
input: "ISNULL(CompanyID,0) = ISNULL({TransferOutwardDocument.CompanyID},0) OR (ISNULL(CompanyID,0) = 0)",
|
|
311
|
-
expected: [
|
|
312
|
-
["CompanyID", "=", 7, { "type": "ISNULL", "position": "both", "defaultValue": 0, "defaultValueRight": 0 }, 7],
|
|
313
|
-
"or",
|
|
314
|
-
["CompanyID", "=", null],
|
|
315
|
-
"or",
|
|
316
|
-
["CompanyID", "=", 0],
|
|
317
|
-
"or",
|
|
318
|
-
["CompanyID", "=", null, { "type": "ISNULL", "position": "column", "defaultValue": 0 }, null],
|
|
319
|
-
"or",
|
|
320
|
-
["CompanyID", "=", false]
|
|
321
|
-
]
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
input: "ISNULL(CompanyID,0) = ISNULL({TransferOutwardDocument.CompanyID},0) OR (ISNULL(CompanyID,1) = 0)",
|
|
325
|
-
expected: [
|
|
326
|
-
["CompanyID", "=", 7, { "type": "ISNULL", "position": "both", "defaultValue": 0, "defaultValueRight": 0 }, 7],
|
|
327
|
-
"or",
|
|
328
|
-
["CompanyID", "=", null],
|
|
329
|
-
"or",
|
|
330
|
-
["CompanyID", "=", 0, { "type": "ISNULL", "position": "column", "defaultValue": 1 }, 0],
|
|
331
|
-
"or",
|
|
332
|
-
["CompanyID", "=", false]
|
|
333
|
-
]
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
input: "ISNULL(CompanyID,0) = {LeadDocument.CompanyID}",
|
|
337
|
-
expected: [
|
|
338
|
-
"CompanyID", "=", 7, { "type": "ISNULL", "position": "column", "defaultValue": 0 }, 7
|
|
339
|
-
]
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
input: "ISNULL(CompanyID,0) = ISNULL({LeadDocument.CompanyID},0)",
|
|
343
|
-
expected: [
|
|
344
|
-
["CompanyID", "=", 7, { "type": "ISNULL", "position": "both", "defaultValue": 0, "defaultValueRight": 0 }, 7],
|
|
345
|
-
"or",
|
|
346
|
-
["CompanyID", "=", null]
|
|
347
|
-
]
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
input: "ISNULL(CompanyID,1) = ISNULL({LeadDocument.CompanyID},2)",
|
|
351
|
-
expected: [
|
|
352
|
-
"CompanyID", "=", 7, { "type": "ISNULL", "position": "both", "defaultValue": 1, "defaultValueRight": 2 }, 7
|
|
353
|
-
]
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
input: "CompanyID = ISNULL({LeadDocument.CompanyID},0)",
|
|
357
|
-
expected: [
|
|
358
|
-
"CompanyID", "=", 7, { "type": "ISNULL", "position": "value", "defaultValue": 0 }, 7
|
|
359
|
-
]
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
input: "AllowSubDealer = ISNULL({LeadDocument.AllowSubDealer},0)",
|
|
363
|
-
expected: [
|
|
364
|
-
"AllowSubDealer", "=", true, { "type": "ISNULL", "position": "value", "defaultValue": 0 }, true
|
|
365
|
-
]
|
|
366
|
-
},
|
|
367
|
-
{
|
|
368
|
-
input: "AllowSubDealer = ISNULL({LeadDocument.AllowSubDealer},1)",
|
|
369
|
-
expected: [
|
|
370
|
-
"AllowSubDealer", "=", true, { "type": "ISNULL", "position": "value", "defaultValue": 1 }, true
|
|
371
|
-
]
|
|
372
|
-
},
|
|
373
|
-
{
|
|
374
|
-
input: "ISNULL(AllowSubDealer,0) = ISNULL({LeadDocument.AllowSubDealer},1)",
|
|
375
|
-
expected: [
|
|
376
|
-
"AllowSubDealer", "=", true, { "type": "ISNULL", "position": "both", "defaultValue": 0, "defaultValueRight": 1 }, true
|
|
377
|
-
]
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
input: "ISNULL(AllowSubDealer,0) = {LeadDocument.AllowSubDealer}",
|
|
381
|
-
expected: [
|
|
382
|
-
"AllowSubDealer", "=", true, { "type": "ISNULL", "position": "column", "defaultValue": 0 }, true
|
|
383
|
-
]
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
input: "(CompanyID = {SingleStepTransferDocument.CompanyID} OR {SingleStepTransferDocument.CompanyID} = 0 OR ISNULL(CompanyID,0) = 0) AND ((ISNULL(IsSubdealer,0)) IN ({SingleStepTransferDocument.AllowedSubdealer}))",
|
|
387
|
-
expected: [
|
|
388
|
-
[
|
|
389
|
-
[ "CompanyID", "=", 2, ],
|
|
390
|
-
"or",
|
|
391
|
-
[
|
|
392
|
-
[ "CompanyID", "=", 0, ],
|
|
393
|
-
"or",
|
|
394
|
-
[ "CompanyID", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL", }, null, ],
|
|
395
|
-
"or",
|
|
396
|
-
[ "CompanyID", "=", false, ],
|
|
397
|
-
],
|
|
398
|
-
],
|
|
399
|
-
"and",
|
|
400
|
-
[
|
|
401
|
-
[ "IsSubdealer", "=", false, ],
|
|
402
|
-
"or",
|
|
403
|
-
[ "IsSubdealer", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL", }, null, ]
|
|
404
|
-
]
|
|
405
|
-
]
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
input: "ISNULL(AllowSubDealer,1) = {LeadDocument.AllowSubDealer}",
|
|
409
|
-
expected: [
|
|
410
|
-
["AllowSubDealer", "=", true],
|
|
411
|
-
'or',
|
|
412
|
-
["AllowSubDealer", "=", null, { "type": "ISNULL", "position": "column", "defaultValue": 1 }, null]
|
|
413
|
-
],
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
input: "(CompanyID = {LeadDocument.CompanyID} OR CompanyID IS NULL) AND ItemGroupType IN ({Item.AllowedItemGroupTypeOne}) AND ({PurchaseOrderDocument.IsMultiBrand} = 0 OR ({PurchaseOrderDocument.IsMultiBrand} = 1 AND Make IN ({PurchaseOrderDocument.AllowedApplicableMake})))",
|
|
417
|
-
expected: [
|
|
418
|
-
[
|
|
419
|
-
["CompanyID", "=", 7],
|
|
420
|
-
"or",
|
|
421
|
-
["CompanyID", "=", null, { "type": "IS" }, null]
|
|
422
|
-
],
|
|
423
|
-
"and",
|
|
424
|
-
["ItemGroupType", "=", "1"]
|
|
425
|
-
]
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
input: "AccountID = {AccountingRule.CompanyId}",
|
|
429
|
-
expected: [
|
|
430
|
-
"AccountID", "=", 42
|
|
431
|
-
]
|
|
432
|
-
},
|
|
433
|
-
{
|
|
434
|
-
input: "ID IN ({SampleDoc.AuthFilterID})",
|
|
435
|
-
expected: []
|
|
436
|
-
},
|
|
437
|
-
{
|
|
438
|
-
input: "ItemGroupType IN ({ItemPrice.AllowedItemGroupType}) AND ((ISNULL(IsNonStock,0))={ItemPrice.AllowedNonStock}) AND (CompanyID = {ItemPrice.CompanyID} OR {ItemPrice.CompanyID} = 0 OR ISNULL(CompanyID,0) = 0)",
|
|
439
|
-
expected: [
|
|
440
|
-
[
|
|
441
|
-
[
|
|
442
|
-
["ItemGroupType", "=", "1"],
|
|
443
|
-
"or",
|
|
444
|
-
["ItemGroupType", "=", "2"]
|
|
445
|
-
],
|
|
446
|
-
"and",
|
|
447
|
-
[
|
|
448
|
-
["IsNonStock", "=", 1, { "defaultValue": 0, "position": "column", "type": "ISNULL" }, 1],
|
|
449
|
-
"or",
|
|
450
|
-
["IsNonStock", "=", true]
|
|
451
|
-
]
|
|
452
|
-
],
|
|
453
|
-
"and",
|
|
454
|
-
[
|
|
455
|
-
["CompanyID", "=", 7],
|
|
456
|
-
"or",
|
|
457
|
-
[
|
|
458
|
-
["CompanyID", "=", 0],
|
|
459
|
-
"or",
|
|
460
|
-
["CompanyID", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL" }, null],
|
|
461
|
-
"or",
|
|
462
|
-
["CompanyID", "=", false]
|
|
463
|
-
]
|
|
464
|
-
]
|
|
465
|
-
],
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
input: "BranchID = {AdjustmentDocument.BranchID} AND CompanyID = {AdjustmentDocument.CompanyID} AND IsFromInvoice = {AdjustmentDocument.IsFromInvoice} AND (SupplierInvoiceNO IN ('{AdjustmentDocument.SupplierInvoiceNos}') OR ISNULL('{AdjustmentDocument.SupplierInvoiceNos}','''') = '''')",
|
|
469
|
-
expected: [
|
|
470
|
-
[
|
|
471
|
-
["BranchID", "=", 42],
|
|
472
|
-
"and",
|
|
473
|
-
["CompanyID", "=", 7],
|
|
474
|
-
"and",
|
|
475
|
-
["IsFromInvoice", "=", true],
|
|
476
|
-
],
|
|
477
|
-
"and",
|
|
478
|
-
["SupplierInvoiceNO", "=", "INV1"]
|
|
5
|
+
// Shared with the C# DevexpressFilterParser tests (SQLParserTests), which render each 'filter' back to SQL.
|
|
6
|
+
const { groups, variables, converterOptions } = JSON.parse(
|
|
7
|
+
readFileSync(new URL("./fixtures/FilterCases.json", import.meta.url), "utf8")
|
|
8
|
+
);
|
|
479
9
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
{
|
|
483
|
-
input: `DocType IN ({QuoteDocument.AllowedDocType})
|
|
484
|
-
AND CompanyID = {QuoteDocument.CompanyID}
|
|
485
|
-
AND
|
|
486
|
-
(
|
|
487
|
-
{QuoteDocument.IsVehicle} = 0
|
|
488
|
-
OR
|
|
489
|
-
(
|
|
490
|
-
{QuoteDocument.IsVehicle} = 1
|
|
491
|
-
AND ProspectID IS NOT NULL
|
|
492
|
-
)
|
|
493
|
-
)`,
|
|
494
|
-
expected: [
|
|
495
|
-
[
|
|
496
|
-
["DocType", "=", "10809"],
|
|
497
|
-
"or",
|
|
498
|
-
["DocType", "=", "40927"]
|
|
499
|
-
],
|
|
500
|
-
"and",
|
|
501
|
-
["CompanyID", "=", 2],
|
|
502
|
-
"and",
|
|
503
|
-
["ProspectID", "!=", null, { "type": "IS NOT" }, null]
|
|
504
|
-
]
|
|
505
|
-
}
|
|
506
|
-
];
|
|
10
|
+
// A text field is either a single string or an array of lines.
|
|
11
|
+
const joinLines = (text, separator) => Array.isArray(text) ? text.join(separator) : text;
|
|
507
12
|
|
|
508
|
-
|
|
509
|
-
|
|
13
|
+
describe("Parser SQL to dx Filter Builder", () => {
|
|
14
|
+
groups.forEach(({ name, cases }) => {
|
|
15
|
+
describe(name, () => {
|
|
16
|
+
cases.forEach(({ id, input, filter, skip }) => {
|
|
17
|
+
const sql = joinLines(input, "\n");
|
|
18
|
+
const test = skip?.js ? it.skip : it;
|
|
510
19
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
20
|
+
test(`Test Case ${id}: ${sql}`, () => {
|
|
21
|
+
const expected = filter ?? null;
|
|
514
22
|
|
|
515
|
-
|
|
516
|
-
astwithVariables = convertSQLToAst(input);
|
|
23
|
+
const astwithVariables = convertSQLToAst(sql);
|
|
517
24
|
|
|
25
|
+
if (astwithVariables == null) {
|
|
26
|
+
expect(null).toEqual(expected);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
518
29
|
|
|
519
|
-
|
|
520
|
-
expect(null).toEqual(expected);
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
30
|
+
const result = convertAstToDevextreme(astwithVariables.ast, variables, converterOptions);
|
|
523
31
|
|
|
524
|
-
|
|
525
|
-
|
|
32
|
+
if (result == null || result == true || result == false) {
|
|
33
|
+
expect([]).toEqual(expected);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
526
36
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
treatNumberAsNullableBit: true
|
|
37
|
+
expect(result).toEqual(expected);
|
|
38
|
+
});
|
|
530
39
|
});
|
|
531
|
-
|
|
532
|
-
if (result == null || result == true || result == false) {
|
|
533
|
-
expect([]).toEqual(expected);
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
expect(result).toEqual(expected);
|
|
538
40
|
});
|
|
539
41
|
});
|
|
540
42
|
});
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const sampleData = {
|
|
544
|
-
"SingleStepTransferDocument.CompanyID": 2,
|
|
545
|
-
"SingleStepTransferDocument.AllowedSubdealer": false,
|
|
546
|
-
"Example.ZeroValue": 0,
|
|
547
|
-
"CoreEntity0022.CompanyGroupID": 42,
|
|
548
|
-
"CoreEntity0022.BranchID": 7,
|
|
549
|
-
"Employee.District": 0,
|
|
550
|
-
"Employee.BranchID": 7,
|
|
551
|
-
"SaleInvoiceDocument.ContactID": 42,
|
|
552
|
-
"SaleInvoiceDocument.BranchID": 7,
|
|
553
|
-
"AccountingRule.CompanyID": 42,
|
|
554
|
-
"AccountingRule.BranchID": 7,
|
|
555
|
-
"Area.AreaType": 42,
|
|
556
|
-
"Area.BranchID": 7,
|
|
557
|
-
"Item.ID": 42,
|
|
558
|
-
"Item.BranchID": 7,
|
|
559
|
-
"Item.AllowedItemGroupType": "1,2",
|
|
560
|
-
"Item.AllowedItemGroupTypeOne": "1",
|
|
561
|
-
"WorkOrderLine.ApplicableUoms": ["UOM1", "UOM2", "UOM3"],
|
|
562
|
-
"WorkOrderLine.CompanyID": 2,
|
|
563
|
-
"WorkOrderDocument.CompanyID": 42,
|
|
564
|
-
"WorkOrderDocument.BranchID": 7,
|
|
565
|
-
"TransferOutwardDocument.DocDate": "2022-01-01",
|
|
566
|
-
"TransferOutwardDocument.RefBranchID": 42,
|
|
567
|
-
"TransferOutwardDocument.CompanyID": 7,
|
|
568
|
-
"LeadDocument.BranchID": 42,
|
|
569
|
-
"LeadDocument.CompanyID": 7,
|
|
570
|
-
"ServiceOrderDocument.SourceID": 2,
|
|
571
|
-
"LeadDocument.AllowSubDealer": true,
|
|
572
|
-
"SupportResolution.TicketID": 123,
|
|
573
|
-
"SaleOrderStatusStmtGlobalRpt.StateID": null,
|
|
574
|
-
"SaleOrderStatusStmtGlobalRpt.RegionID": null,
|
|
575
|
-
"WorkOrderLine.CompanyIDs": ["0,1"],
|
|
576
|
-
"PurchaseOrderDocument.IsMultiBrand": false,
|
|
577
|
-
"PurchaseOrderDocument.AllowedApplicableMake": "0",
|
|
578
|
-
"SampleDoc.AuthFilterID": "ID",
|
|
579
|
-
"ItemPrice.AllowedItemGroupType": "1,2",
|
|
580
|
-
"ItemPrice.AllowedNonStock": 1,
|
|
581
|
-
"ItemPrice.CompanyID": 7,
|
|
582
|
-
"AdjustmentDocument.BranchID": 42,
|
|
583
|
-
"AdjustmentDocument.CompanyID": 7,
|
|
584
|
-
"AdjustmentDocument.IsFromInvoice": true,
|
|
585
|
-
"AdjustmentDocument.SupplierInvoiceNos": "INV1",
|
|
586
|
-
"QuoteDocument.AllowedDocType": "10809,40927",
|
|
587
|
-
"QuoteDocument.CompanyID": 2,
|
|
588
|
-
"QuoteDocument.IsVehicle": true
|
|
589
|
-
};
|