@@ -10,19 +10,43 @@ import XCTest
10
10
import FoundationNetworking
11
11
#endif
12
12
13
+ struct User : Encodable {
14
+ var email : String
15
+ var username : String ?
16
+ }
17
+
13
18
@MainActor
14
19
final class BuildURLRequestTests : XCTestCase {
15
20
let url = URL ( string: " https://example.supabase.co " ) !
16
21
17
22
struct TestCase : Sendable {
18
23
let name : String
19
- var record = false
24
+ let record : Bool
25
+ let file : StaticString
26
+ let line : UInt
20
27
let build : @Sendable ( PostgrestClient) async throws -> PostgrestBuilder
28
+
29
+ init (
30
+ name: String ,
31
+ record: Bool = false ,
32
+ file: StaticString = #file,
33
+ line: UInt = #line,
34
+ build: @escaping @Sendable ( PostgrestClient) async throws -> PostgrestBuilder
35
+ ) {
36
+ self . name = name
37
+ self . record = record
38
+ self . file = file
39
+ self . line = line
40
+ self . build = build
41
+ }
21
42
}
22
43
23
44
func testBuildRequest( ) async throws {
24
45
let runningTestCase = ActorIsolated ( TestCase ? . none)
25
46
47
+ let encoder = PostgrestClient . Configuration. jsonEncoder
48
+ encoder. outputFormatting = . sortedKeys
49
+
26
50
let client = PostgrestClient (
27
51
url: url,
28
52
schema: nil ,
@@ -39,12 +63,15 @@ final class BuildURLRequestTests: XCTestCase {
39
63
as: . curl,
40
64
named: runningTestCase. name,
41
65
record: runningTestCase. record,
42
- testName: " testBuildRequest() "
66
+ file: runningTestCase. file,
67
+ testName: " testBuildRequest() " ,
68
+ line: runningTestCase. line
43
69
)
44
70
}
45
71
46
72
return ( Data ( ) , URLResponse ( ) )
47
- }
73
+ } ,
74
+ encoder: encoder
48
75
)
49
76
50
77
let testCases : [ TestCase ] = [
@@ -55,7 +82,16 @@ final class BuildURLRequestTests: XCTestCase {
55
82
} ,
56
83
TestCase ( name: " insert new user " ) { client in
57
84
try await client. from ( " users " )
58
- . insert ( [ " email " : " [email protected] " ] )
85
+ . insert ( User ( email
: " [email protected] " ) )
86
+ } ,
87
+ TestCase ( name: " bulk insert users " ) { client in
88
+ try await client. from ( " users " )
89
+ . insert (
90
+ [
91
+
92
+ User ( email
: " [email protected] " , username
: " johndoe2 " ) ,
93
+ ]
94
+ )
59
95
} ,
60
96
TestCase ( name: " call rpc " ) { client in
61
97
try await client. rpc ( " test_fcn " , params: [ " KEY " : " VALUE " ] )
@@ -89,11 +125,20 @@ final class BuildURLRequestTests: XCTestCase {
89
125
} ,
90
126
TestCase ( name: " test upsert not ignoring duplicates " ) { client in
91
127
try await client. from ( " users " )
92
- . upsert ( [ " email " : " [email protected] " ] )
128
+ . upsert ( User ( email
: " [email protected] " ) )
129
+ } ,
130
+ TestCase ( name: " bulk upsert " ) { client in
131
+ try await client. from ( " users " )
132
+ . upsert (
133
+ [
134
+
135
+ User ( email
: " [email protected] " , username
: " johndoe2 " ) ,
136
+ ]
137
+ )
93
138
} ,
94
139
TestCase ( name: " test upsert ignoring duplicates " ) { client in
95
140
try await client. from ( " users " )
96
- . upsert ( [ " email " : " [email protected] " ] , ignoreDuplicates
: true )
141
+ . upsert ( User ( email
: " [email protected] " ) , ignoreDuplicates
: true )
97
142
} ,
98
143
TestCase ( name: " query with + character " ) { client in
99
144
await client. from ( " users " )
@@ -110,7 +155,7 @@ final class BuildURLRequestTests: XCTestCase {
110
155
await client. schema ( " storage " )
111
156
. from ( " objects " )
112
157
. select ( )
113
- }
158
+ } ,
114
159
]
115
160
116
161
for testCase in testCases {
0 commit comments