Skip to content

Commit decf552

Browse files
committed
refactor: use ts-expect-error directive everywhere
It allows to see the errors directly into the editor rather than only at tsd runtime. Also reduce the noise when openning the files into the editor
1 parent c17a542 commit decf552

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

test/index.test-d.ts

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
11
import { TypeEqual } from 'ts-expect'
2-
import { expectError, expectType } from 'tsd'
2+
import { expectType } from 'tsd'
33
import { PostgrestClient, PostgrestError } from '../src/index'
44
import { Prettify } from '../src/types'
55
import { Json } from '../src/select-query-parser/types'
66
import { Database } from './types.override'
7+
import { Database as DatabaseWithOptions } from './types.override-with-options-postgrest13'
78

89
const REST_URL = 'http://localhost:3000'
910
const postgrest = new PostgrestClient<Database>(REST_URL)
11+
const postgrestWithOptions = new PostgrestClient<DatabaseWithOptions>(REST_URL)
1012

1113
// table invalid type
1214
{
13-
expectError(postgrest.from(42))
14-
expectError(postgrest.from('nonexistent_table'))
15+
// @ts-expect-error should be error
16+
postgrest.from(42)
17+
// @ts-expect-error should be error
18+
postgrest.from('nonexistent_table')
1519
}
1620

1721
// `null` can't be used with `.eq()`
1822
{
1923
postgrest.from('users').select().eq('username', 'foo')
20-
expectError(postgrest.from('users').select().eq('username', null))
24+
// @ts-expect-error should be error
25+
postgrest.from('users').select().eq('username', null)
2126

2227
const nullableVar = 'foo' as string | null
23-
expectError(postgrest.from('users').select().eq('username', nullableVar))
28+
// @ts-expect-error should be error
29+
postgrest.from('users').select().eq('username', nullableVar)
2430
}
2531

2632
// `.eq()`, '.neq()' and `.in()` validate provided filter value when column is an enum.
2733
// Behaves the same for simple columns, as well as relationship filters.
2834
{
29-
expectError(postgrest.from('users').select().eq('status', 'invalid'))
30-
expectError(postgrest.from('users').select().neq('status', 'invalid'))
31-
expectError(postgrest.from('users').select().in('status', ['invalid']))
35+
// @ts-expect-error should be error
36+
postgrest.from('users').select().eq('status', 'invalid')
37+
// @ts-expect-error should be error
38+
postgrest.from('users').select().neq('status', 'invalid')
39+
// @ts-expect-error should be error
40+
postgrest.from('users').select().in('status', ['invalid'])
41+
42+
// @ts-expect-error should be error
43+
postgrest.from('best_friends').select('users!first_user(status)').eq('users.status', 'invalid')
44+
// @ts-expect-error should be error
45+
postgrest.from('best_friends').select('users!first_user(status)').neq('users.status', 'invalid')
46+
postgrest
47+
.from('best_friends')
48+
.select('users!first_user(status)')
49+
// @ts-expect-error should be error
50+
.in('users.status', ['invalid'])
3251

33-
expectError(
34-
postgrest.from('best_friends').select('users!first_user(status)').eq('users.status', 'invalid')
35-
)
36-
expectError(
37-
postgrest.from('best_friends').select('users!first_user(status)').neq('users.status', 'invalid')
38-
)
39-
expectError(
40-
postgrest
41-
.from('best_friends')
42-
.select('users!first_user(status)')
43-
.in('users.status', ['invalid'])
44-
)
4552
// Validate deeply nested embedded tables
46-
expectError(
47-
postgrest.from('users').select('messages(channels(*))').eq('messages.channels.id', 'invalid')
48-
)
49-
expectError(
50-
postgrest.from('users').select('messages(channels(*))').neq('messages.channels.id', 'invalid')
51-
)
52-
expectError(
53-
postgrest.from('users').select('messages(channels(*))').in('messages.channels.id', ['invalid'])
54-
)
53+
// @ts-expect-error should be error
54+
postgrest.from('users').select('messages(channels(*))').eq('messages.channels.id', 'invalid')
55+
// @ts-expect-error should be error
56+
postgrest.from('users').select('messages(channels(*))').neq('messages.channels.id', 'invalid')
57+
// @ts-expect-error should be error
58+
postgrest.from('users').select('messages(channels(*))').in('messages.channels.id', ['invalid'])
5559

5660
{
5761
const result = await postgrest.from('users').select('status').eq('status', 'ONLINE')
@@ -145,12 +149,14 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
145149

146150
// cannot update non-updatable views
147151
{
148-
expectError(postgrest.from('updatable_view').update({ non_updatable_column: 0 }))
152+
// @ts-expect-error should be error
153+
postgrest.from('updatable_view').update({ non_updatable_column: 0 })
149154
}
150155

151156
// cannot update non-updatable columns
152157
{
153-
expectError(postgrest.from('updatable_view').update({ non_updatable_column: 0 }))
158+
// @ts-expect-error should be error
159+
postgrest.from('updatable_view').update({ non_updatable_column: 0 })
154160
}
155161

156162
// spread resource with single column in select query
@@ -286,6 +292,14 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
286292
}[]
287293
>(result.data)
288294
}
295+
296+
// Check that client options __InternalSupabase isn't considered like the other schemas
297+
{
298+
await postgrestWithOptions
299+
// @ts-expect-error supabase internal shouldn't be available as one of the selectable schema
300+
.schema('__InternalSupabase')
301+
}
302+
289303
// Json string Accessor with custom types overrides
290304
{
291305
const result = await postgrest

0 commit comments

Comments
 (0)