Skip to content

Commit

Permalink
Add support for watchOS
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed May 14, 2022
1 parent ce3c347 commit a0d7bbb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/Flight-School/AnyCodable",
"state": {
"branch": null,
"revision": "b1a7a8a6186f2fcb28f7bda67cfc545de48b3c80",
"version": "0.6.2"
"revision": "f9fda69a7b704d46fb5123005f2f7e43dbb8a0fa",
"version": "0.6.5"
}
},
{
Expand Down
10 changes: 9 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let package = Package(
.iOS(.v11),
.macOS(.v10_10),
.tvOS(.v10),
.watchOS(.v3),
],
products: [
.library(
Expand All @@ -30,7 +31,14 @@ let package = Package(
),
.testTarget(
name: "PostgRESTTests",
dependencies: ["PostgREST", "SnapshotTesting"],
dependencies: [
"PostgREST",
.product(
name: "SnapshotTesting",
package: "SnapshotTesting",
condition: .when(platforms: [.iOS, .macOS, .tvOS])
),
],
exclude: [
"__Snapshots__"
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgREST/Concurrency.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

#if compiler(>=5.5) && canImport(_Concurrency)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension PostgrestBuilder {
@discardableResult
public func execute(head: Bool = false, count: CountOption? = nil) async throws
Expand Down
106 changes: 54 additions & 52 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
@@ -1,59 +1,61 @@
import Foundation
import SnapshotTesting
import XCTest
#if !os(watchOS)
import Foundation
import SnapshotTesting
import XCTest

@testable import PostgREST
@testable import PostgREST

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

final class BuildURLRequestTests: XCTestCase {
let url = "https://example.supabase.co"
final class BuildURLRequestTests: XCTestCase {
let url = "https://example.supabase.co"

struct TestCase {
let name: String
var record = false
let build: (PostgrestClient) throws -> URLRequest
}
struct TestCase {
let name: String
var record = false
let build: (PostgrestClient) throws -> URLRequest
}

func testBuildURLRequest() throws {
let client = PostgrestClient(url: url, schema: nil)

let testCases: [TestCase] = [
TestCase(name: "select all users where email ends with '@supabase.co'") { client in
try client.from("users")
.select()
.like(column: "email", value: "%@supabase.co")
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "insert new user") { client in
try client.from("users")
.insert(values: ["email": "[email protected]"])
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "call rpc") { client in
try client.rpc(fn: "test_fcn", parameters: ["KEY": "VALUE"])
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "call rpc without parameter") { client in
try client.rpc(fn: "test_fcn")
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "test all filters and count") { client in
var query = client.from("todos").select()

for op in PostgrestFilterBuilder.Operator.allCases {
query = query.filter(column: "column", operator: op, value: "Some value")
}

return try query.buildURLRequest(head: false, count: .exact)
},
]

for testCase in testCases {
let request = try testCase.build(client)
assertSnapshot(matching: request, as: .curl, named: testCase.name, record: testCase.record)
func testBuildURLRequest() throws {
let client = PostgrestClient(url: url, schema: nil)

let testCases: [TestCase] = [
TestCase(name: "select all users where email ends with '@supabase.co'") { client in
try client.from("users")
.select()
.like(column: "email", value: "%@supabase.co")
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "insert new user") { client in
try client.from("users")
.insert(values: ["email": "[email protected]"])
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "call rpc") { client in
try client.rpc(fn: "test_fcn", parameters: ["KEY": "VALUE"])
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "call rpc without parameter") { client in
try client.rpc(fn: "test_fcn")
.buildURLRequest(head: false, count: nil)
},
TestCase(name: "test all filters and count") { client in
var query = client.from("todos").select()

for op in PostgrestFilterBuilder.Operator.allCases {
query = query.filter(column: "column", operator: op, value: "Some value")
}

return try query.buildURLRequest(head: false, count: .exact)
},
]

for testCase in testCases {
let request = try testCase.build(client)
assertSnapshot(matching: request, as: .curl, named: testCase.name, record: testCase.record)
}
}
}
}
#endif

0 comments on commit a0d7bbb

Please sign in to comment.