-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |