Skip to content

Commit 65f2f41

Browse files
committed
chore(tests): fix embeded functions join test
1 parent c77a743 commit 65f2f41

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

test/embeded_functions_join.test.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ describe('embeded functions select', () => {
6868
id: z.number(),
6969
message: z.string().nullable(),
7070
username: z.string(),
71-
blurb_message: z.string().nullable(),
7271
})
7372
),
7473
})
@@ -198,7 +197,6 @@ describe('embeded functions select', () => {
198197
z.object({
199198
channel_id: z.number(),
200199
data: z.unknown().nullable(),
201-
blurb_message: z.string().nullable(),
202200
id: z.number(),
203201
message: z.string().nullable(),
204202
username: z.string(),
@@ -367,6 +365,9 @@ describe('embeded functions select', () => {
367365
}
368366
`)
369367
let result: Exclude<typeof res.data, null>
368+
// The override marks this as not nullable, but the data can be null at runtime.
369+
// So the correct runtime schema is nullable, but the type is not.
370+
// We check that the type is as expected (not nullable), but parsing will fail.
370371
const ExpectedSchema = z.array(
371372
z.object({
372373
username: z.string(),
@@ -378,7 +379,21 @@ describe('embeded functions select', () => {
378379
)
379380
let expected: z.infer<typeof ExpectedSchema>
380381
expectType<TypeEqual<typeof result, typeof expected>>(true)
381-
ExpectedSchema.parse(res.data)
382+
// Parsing with the non-nullable schema should throw, because there are nulls in the data.
383+
expect(() => ExpectedSchema.parse(res.data)).toThrowError()
384+
// However, parsing with a nullable schema should succeed.
385+
const ExpectedNullable = z.array(
386+
z.object({
387+
username: z.string(),
388+
user_called_profile_not_null: z
389+
.object({
390+
id: z.number(),
391+
username: z.string().nullable(),
392+
})
393+
.nullable(),
394+
})
395+
)
396+
ExpectedNullable.parse(res.data)
382397
})
383398

384399
test('embeded_setof_row_one_function_with_fields_selection - function returning a single row embeded table with fields selection', async () => {
@@ -572,7 +587,6 @@ describe('embeded functions select', () => {
572587
id: z.number(),
573588
message: z.string().nullable(),
574589
username: z.string(),
575-
blurb_message: z.string().nullable(),
576590
})
577591
),
578592
})
@@ -645,7 +659,6 @@ describe('embeded functions select', () => {
645659
id: z.number(),
646660
message: z.string().nullable(),
647661
username: z.string(),
648-
blurb_message: z.string().nullable(),
649662
})
650663
),
651664
})
@@ -888,10 +901,8 @@ describe('embeded functions select', () => {
888901
}
889902
`)
890903
let result: Exclude<typeof res.data, null>
891-
const ExpectedSchema = z.array(z.never())
892-
let expected: z.infer<typeof ExpectedSchema>
904+
let expected: never[]
893905
expectType<TypeEqual<typeof result, typeof expected>>(true)
894-
ExpectedSchema.parse(res.data)
895906
})
896907

897908
test('embeded_function_returning_single_row - can embed single row returns function with row single param', async () => {

0 commit comments

Comments
 (0)