@@ -5,23 +5,27 @@ struct Todo: Codable, Hashable {
5
5
let id : UUID
6
6
var description : String
7
7
var isComplete : Bool
8
+ var tags : [ String ]
8
9
let createdAt : Date
9
10
10
11
enum CodingKeys : String , CodingKey {
11
12
case id
12
13
case description
13
14
case isComplete = " is_complete "
15
+ case tags
14
16
case createdAt = " created_at "
15
17
}
16
18
}
17
19
18
20
struct NewTodo : Codable , Hashable {
19
21
var description : String
20
22
var isComplete : Bool = false
23
+ var tags : [ String ]
21
24
22
25
enum CodingKeys : String , CodingKey {
23
26
case description
24
27
case isComplete = " is_complete "
28
+ case tags
25
29
}
26
30
}
27
31
@@ -44,8 +48,9 @@ final class IntegrationTests: XCTestCase {
44
48
" INTEGRATION_TESTS not defined. "
45
49
)
46
50
47
- // Run fresh test by deleting all todos.
48
- try await client. from ( " todo " ) . delete ( ) . execute ( )
51
+ // Run fresh test by deleting all todos. Delete without a where clause isn't supported, so have
52
+ // to do this `neq` trick to delete all data.
53
+ try await client. from ( " todo " ) . delete ( ) . neq ( column: " id " , value: UUID ( ) . uuidString) . execute ( )
49
54
}
50
55
51
56
func testIntegration( ) async throws {
@@ -54,7 +59,10 @@ final class IntegrationTests: XCTestCase {
54
59
55
60
let insertedTodo : Todo = try await client. from ( " todo " )
56
61
. insert (
57
- values: NewTodo ( description: " Implement integration tests for postgrest-swift " ) ,
62
+ values: NewTodo (
63
+ description: " Implement integration tests for postgrest-swift " ,
64
+ tags: [ " tag 01 " , " tag 02 " ]
65
+ ) ,
58
66
returning: . representation
59
67
)
60
68
. single ( )
@@ -67,8 +75,8 @@ final class IntegrationTests: XCTestCase {
67
75
let insertedTodos : [ Todo ] = try await client. from ( " todo " )
68
76
. insert (
69
77
values: [
70
- NewTodo ( description: " Make supabase swift libraries production ready " ) ,
71
- NewTodo ( description: " Drink some coffee " ) ,
78
+ NewTodo ( description: " Make supabase swift libraries production ready " , tags : [ " tag 01 " ] ) ,
79
+ NewTodo ( description: " Drink some coffee " , tags : [ " tag 02 " ] ) ,
72
80
] ,
73
81
returning: . representation
74
82
)
@@ -97,5 +105,9 @@ final class IntegrationTests: XCTestCase {
97
105
try await client. from ( " todo " ) . delete ( ) . eq ( column: " is_complete " , value: true ) . execute ( )
98
106
todos = try await client. from ( " todo " ) . select ( ) . execute ( ) . value
99
107
XCTAssertTrue ( completedTodos. allSatisfy { todo in !todos. contains ( todo) } )
108
+
109
+ let todosWithSpecificTag : [ Todo ] = try await client. from ( " todo " ) . select ( )
110
+ . contains ( column: " tags " , value: [ " tag 01 " ] ) . execute ( ) . value
111
+ XCTAssertEqual ( todosWithSpecificTag, [ insertedTodo, insertedTodos [ 0 ] ] )
100
112
}
101
113
}
0 commit comments