Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Nov 12, 2024
1 parent 6223f3d commit faa13a9
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions Tests/IntegrationTests/Potsgrest/PostgresTransformsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ final class PostgrestTransformsTests: XCTestCase {
configuration: PostgrestClient.Configuration(
url: URL(string: "\(DotEnv.SUPABASE_URL)/rest/v1")!,
headers: [
"apikey": DotEnv.SUPABASE_ANON_KEY,
"apikey": DotEnv.SUPABASE_ANON_KEY
],
logger: nil
)
)

func testOrder() async throws {
let res = try await client.from("users")
let res =
try await client.from("users")
.select()
.order("username", ascending: false)
.execute().value as AnyJSON
Expand Down Expand Up @@ -63,7 +64,8 @@ final class PostgrestTransformsTests: XCTestCase {
}

func testOrderOnMultipleColumns() async throws {
let res = try await client.from("messages")
let res =
try await client.from("messages")
.select()
.order("channel_id", ascending: false)
.order("username", ascending: false)
Expand Down Expand Up @@ -92,7 +94,8 @@ final class PostgrestTransformsTests: XCTestCase {
}

func testLimit() async throws {
let res = try await client.from("users")
let res =
try await client.from("users")
.select()
.limit(1)
.execute().value as AnyJSON
Expand All @@ -113,7 +116,8 @@ final class PostgrestTransformsTests: XCTestCase {
}

func testRange() async throws {
let res = try await client.from("users")
let res =
try await client.from("users")
.select()
.range(from: 1, to: 3)
.execute().value as AnyJSON
Expand Down Expand Up @@ -148,7 +152,8 @@ final class PostgrestTransformsTests: XCTestCase {
}

func testSingle() async throws {
let res = try await client.from("users")
let res =
try await client.from("users")
.select()
.limit(1)
.single()
Expand All @@ -168,7 +173,8 @@ final class PostgrestTransformsTests: XCTestCase {
}

func testSingleOnInsert() async throws {
let res = try await client.from("users")
let res =
try await client.from("users")
.insert(["username": "foo"])
.select()
.single()
Expand All @@ -193,7 +199,8 @@ final class PostgrestTransformsTests: XCTestCase {
}

func testSelectOnInsert() async throws {
let res = try await client.from("users")
let res =
try await client.from("users")
.insert(["username": "foo"])
.select("status")
.execute().value as AnyJSON
Expand All @@ -215,7 +222,8 @@ final class PostgrestTransformsTests: XCTestCase {
}

func testSelectOnRpc() async throws {
let res = try await client.rpc("get_username_and_status", params: ["name_param": "supabot"])
let res =
try await client.rpc("get_username_and_status", params: ["name_param": "supabot"])
.select("status")
.execute().value as AnyJSON

Expand All @@ -230,6 +238,29 @@ final class PostgrestTransformsTests: XCTestCase {
}
}

func testRpcWithArray() async throws {
struct Params: Encodable {
let arr: [Int]
let index: Int
}
let res =
try await client.rpc("get_array_element", params: Params(arr: [37, 420, 64], index: 2))
.execute().value as Int
XCTAssertEqual(res, 420)
}

func testRpcWithReadOnlyAccessMode() async throws {
struct Params: Encodable {
let arr: [Int]
let index: Int
}
let res =
try await client.rpc(
"get_array_element", params: Params(arr: [37, 420, 64], index: 2), get: true
).execute().value as Int
XCTAssertEqual(res, 420)
}

func testCsv() async throws {
let res = try await client.from("users").select().csv().execute().string()
assertInlineSnapshot(of: res, as: .json) {
Expand Down

0 comments on commit faa13a9

Please sign in to comment.