Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Tests/PostgRESTIntegrationTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ struct Todo: Codable, Hashable {
let id: UUID
var description: String
var isComplete: Bool
var tags: [String]
let createdAt: Date

enum CodingKeys: String, CodingKey {
case id
case description
case isComplete = "is_complete"
case tags
case createdAt = "created_at"
}
}

struct NewTodo: Codable, Hashable {
var description: String
var isComplete: Bool = false
var tags: [String]

enum CodingKeys: String, CodingKey {
case description
case isComplete = "is_complete"
case tags
}
}

Expand All @@ -44,8 +48,9 @@ final class IntegrationTests: XCTestCase {
"INTEGRATION_TESTS not defined."
)

// Run fresh test by deleting all todos.
try await client.from("todo").delete().execute()
// Run fresh test by deleting all todos. Delete without a where clause isn't supported, so have
// to do this `neq` trick to delete all data.
try await client.from("todo").delete().neq(column: "id", value: UUID().uuidString).execute()
}

func testIntegration() async throws {
Expand All @@ -54,7 +59,10 @@ final class IntegrationTests: XCTestCase {

let insertedTodo: Todo = try await client.from("todo")
.insert(
values: NewTodo(description: "Implement integration tests for postgrest-swift"),
values: NewTodo(
description: "Implement integration tests for postgrest-swift",
tags: ["tag 01", "tag 02"]
),
returning: .representation
)
.single()
Expand All @@ -67,8 +75,8 @@ final class IntegrationTests: XCTestCase {
let insertedTodos: [Todo] = try await client.from("todo")
.insert(
values: [
NewTodo(description: "Make supabase swift libraries production ready"),
NewTodo(description: "Drink some coffee"),
NewTodo(description: "Make supabase swift libraries production ready", tags: ["tag 01"]),
NewTodo(description: "Drink some coffee", tags: ["tag 02"]),
],
returning: .representation
)
Expand Down Expand Up @@ -97,5 +105,9 @@ final class IntegrationTests: XCTestCase {
try await client.from("todo").delete().eq(column: "is_complete", value: true).execute()
todos = try await client.from("todo").select().execute().value
XCTAssertTrue(completedTodos.allSatisfy { todo in !todos.contains(todo) })

let todosWithSpecificTag: [Todo] = try await client.from("todo").select()
.contains(column: "tags", value: ["tag 01"]).execute().value
XCTAssertEqual(todosWithSpecificTag, [insertedTodo, insertedTodos[0]])
}
}
1 change: 1 addition & 0 deletions supabase/migrations/20220404094927_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ create table todo (
id uuid default uuid_generate_v4 () not null primary key,
description text not null,
is_complete boolean not null default false,
tags text[],
created_at timestamptz default (now() at time zone 'utc'::text) not null
);