|
1
|
import { flattenObjectKeys } from "../flatten-object-keys" |
|
2
|
|
|
3
|
describe("flattenWhereClauses", () => { |
|
4
|
it("should flatten where clauses", () => { |
|
5
|
const where = { |
|
6
|
a: 1, |
|
7
|
b: { |
|
8
|
c: 2, |
|
9
|
d: 3, |
|
10
|
z: { |
|
11
|
$ilike: "%test%", |
|
12
|
}, |
|
13
|
y: null, |
|
14
|
}, |
|
15
|
e: 4, |
|
16
|
} |
|
17
|
|
|
18
|
const result = flattenObjectKeys(where) |
|
19
|
|
|
20
|
expect(result).toEqual({ |
|
21
|
a: 1, |
|
22
|
"b.c": 2, |
|
23
|
"b.d": 3, |
|
24
|
"b.z": { $ilike: "%test%" }, |
|
25
|
"b.y": null, |
|
26
|
e: 4, |
|
27
|
}) |
|
28
|
}) |
|
29
|
|
|
30
|
it("should preserve non-plain object values", () => { |
|
31
|
const date = new Date("2024-01-01T00:00:00.000Z") |
|
32
|
const where = { |
|
33
|
created_at: date, |
|
34
|
nested: { |
|
35
|
updated_at: date, |
|
36
|
}, |
|
37
|
} |
|
38
|
|
|
39
|
const result = flattenObjectKeys(where) |
|
40
|
|
|
41
|
expect(result).toEqual({ |
|
42
|
created_at: date, |
|
43
|
"nested.updated_at": date, |
|
44
|
}) |
|
45
|
}) |
|
46
|
}) |