This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeWhere.test.ts
77 lines (72 loc) · 1.74 KB
/
makeWhere.test.ts
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
import { makeWhere } from '../helpers/makeWhere'
import { Args, Models } from '../types'
const models = {
User: {
fields: {
id: { isList: false },
name: { isList: false },
labels: { isList: true },
languages: { isList: true },
tags1: { isList: true },
tags2: { isList: true },
tags3: { isList: true },
},
},
} as unknown as Models
test('make where statement', () => {
expect(
makeWhere({ where: { id: 1, name: { in: ['a', 'b', 'c'] } } }, 'User', {
models,
}),
).toEqual('id.eq.1,name.in.("a","b","c")')
})
test('make where statement with not operator', () => {
expect(
makeWhere({ where: { name: { not: null } } }, 'User', {
models,
}),
).toEqual('name.not.is.null')
})
test('make where statement with OR and NOT operator', () => {
expect(
makeWhere(
{
where: {
OR: [
{ name: { startsWith: 'a' } },
{ name: { endsWith: 'b' } },
{ name: { contains: 'c', mode: 'insensitive' } },
],
NOT: [{ id: { gt: 10 } }, { id: { lt: 100 } }],
} as Args['where'],
},
'User',
{
models,
},
),
).toEqual(
'or(name.like.a*,name.like.*b,name.ilike.*c*),not.and(id.gt.10,id.lt.100)',
)
})
test('make where statement with list field operator', () => {
expect(
makeWhere(
{
where: {
labels: { has: 'a' },
languages: { hasSome: ['a'] },
tags1: { hasEvery: ['a', 'b'] },
tags2: { isEmpty: true },
tags3: { equals: 'c' },
},
},
'User',
{
models,
},
),
).toEqual(
'labels.cs.{"a"},languages.ov.{"a"},tags1.cs.{"a","b"},tags2.eq.{},tags3.eq.{"c"}',
)
})