Skip to content

Commit 8736d90

Browse files
authored
test: add querying by null tests (#319)
1 parent 07bdc5f commit 8736d90

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/find-first.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,24 @@ it('queries through array models', async () => {
138138
numberList.findFirst((q) => q.where((arr) => arr.includes(2))),
139139
).toEqual([1, 2, 3])
140140
})
141+
142+
it('queries by nullable properties', async () => {
143+
const users = new Collection({
144+
schema: z.object({
145+
id: z.number(),
146+
organizationId: z.number().nullable(),
147+
}),
148+
})
149+
150+
await users.create({ id: 1, organizationId: null })
151+
await users.create({ id: 2, organizationId: 5 })
152+
await users.create({ id: 3, organizationId: null })
153+
154+
expect(users.findFirst((q) => q.where({ organizationId: null }))).toEqual({
155+
id: 1,
156+
organizationId: null,
157+
})
158+
expect(
159+
users.findFirst((q) => q.where({ organizationId: (id) => id !== null })),
160+
).toEqual({ id: 2, organizationId: 5 })
161+
})

tests/find-many.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,24 @@ it('returns all entries matching the query (OR)', async () => {
8686
{ id: 3, name: 'John' },
8787
])
8888
})
89+
90+
it('queries by nullable properties', async () => {
91+
const users = new Collection({
92+
schema: z.object({
93+
id: z.number(),
94+
organizationId: z.number().nullable(),
95+
}),
96+
})
97+
98+
await users.create({ id: 1, organizationId: null })
99+
await users.create({ id: 2, organizationId: 5 })
100+
await users.create({ id: 3, organizationId: null })
101+
102+
expect(users.findMany((q) => q.where({ organizationId: null }))).toEqual([
103+
{ id: 1, organizationId: null },
104+
{ id: 3, organizationId: null },
105+
])
106+
expect(
107+
users.findMany((q) => q.where({ organizationId: (id) => id !== null })),
108+
).toEqual([{ id: 2, organizationId: 5 }])
109+
})

0 commit comments

Comments
 (0)