Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Nov 29, 2024
1 parent aedd2ad commit 7b65aa7
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Sources/Supabase/SupabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public final class SupabaseClient {
_headers.dictionary
}

private var listenForAuthEventsTask: Task<Void, Never>?
var listenForAuthEventsTask: Task<Void, Never>?
private var _storage: SupabaseStorageClient?
private var _rest: PostgrestClient?
private var _functions: FunctionsClient?
Expand Down
1 change: 1 addition & 0 deletions Tests/AuthTests/AuthClientMultipleInstancesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import TestHelpers
import XCTest

@MainActor
final class AuthClientMultipleInstancesTests: XCTestCase {
func testMultipleAuthClientInstances() {
let url = URL(string: "http://localhost:54321/auth")!
Expand Down
1 change: 1 addition & 0 deletions Tests/AuthTests/AuthClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import XCTest
import FoundationNetworking
#endif

@MainActor
final class AuthClientTests: XCTestCase {
var sessionManager: SessionManager!

Expand Down
1 change: 1 addition & 0 deletions Tests/AuthTests/RequestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import XCTest

struct UnimplementedError: Error {}

@MainActor
final class RequestsTests: XCTestCase {
func testSignUpWithEmailAndPassword() async {
let sut = makeSUT()
Expand Down
1 change: 1 addition & 0 deletions Tests/FunctionsTests/FunctionsClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import XCTest
import FoundationNetworking
#endif

@MainActor
final class FunctionsClientTests: XCTestCase {
let url = URL(string: "http://localhost:5432/functions/v1")!
let apiKey = "supabase.anon.key"
Expand Down
1 change: 1 addition & 0 deletions Tests/FunctionsTests/RequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import SnapshotTesting
import XCTest

@MainActor
final class RequestTests: XCTestCase {
let url = URL(string: "http://localhost:5432/functions/v1")!
let apiKey = "supabase.anon.key"
Expand Down
7 changes: 4 additions & 3 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ struct User: Encodable {
var username: String?
}

@MainActor
final class BuildURLRequestTests: XCTestCase {
let url = URL(string: "https://example.supabase.co")!

struct TestCase: Sendable {
struct TestCase {
let name: String
let record: Bool
let file: StaticString
let line: UInt
let build: @Sendable (PostgrestClient) async throws -> PostgrestBuilder
let build: (PostgrestClient) async throws -> PostgrestBuilder

init(
name: String,
record: Bool = false,
file: StaticString = #file,
line: UInt = #line,
build: @escaping @Sendable (PostgrestClient) async throws -> PostgrestBuilder
build: @escaping (PostgrestClient) async throws -> PostgrestBuilder
) {
self.name = name
self.record = record
Expand Down
5 changes: 3 additions & 2 deletions Tests/PostgRESTTests/PostgrestBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@testable import PostgREST
import XCTest

@MainActor
final class PostgrestBuilderTests: XCTestCase {
let url = URL(string: "http://localhost:54321/rest/v1")!

Expand All @@ -16,8 +17,8 @@ final class PostgrestBuilderTests: XCTestCase {
let postgrest2 = try postgrest1.rpc("void_func").setHeader(name: .init("apikey")!, value: "bar")

// Original client object isn't affected
XCTAssertEqual(postgrest1.from("users").select().mutableState.request.headers[.init("apikey")!], "foo")
XCTAssertEqual(postgrest1.from("users").select().request.headers[.init("apikey")!], "foo")
// Derived client object uses new header value
XCTAssertEqual(postgrest2.mutableState.request.headers[.init("apikey")!], "bar")
XCTAssertEqual(postgrest2.request.headers[.init("apikey")!], "bar")
}
}
19 changes: 10 additions & 9 deletions Tests/RealtimeTests/RealtimeChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import XCTestDynamicOverlay

@testable import Realtime

@MainActor
final class RealtimeChannelTests: XCTestCase {
var socket: RealtimeClientV2!
var sut: RealtimeChannelV2!
Expand Down Expand Up @@ -47,34 +48,34 @@ final class RealtimeChannelTests: XCTestCase {
func testAttachCallbacks() async {
var subscriptions = Set<RealtimeSubscription>()

await sut.onPostgresChange(
sut.onPostgresChange(
AnyAction.self,
schema: "public",
table: "users",
filter: "id=eq.1"
) { _ in }.store(in: &subscriptions)
await sut.onPostgresChange(
sut.onPostgresChange(
InsertAction.self,
schema: "private"
) { _ in }.store(in: &subscriptions)
await sut.onPostgresChange(
sut.onPostgresChange(
UpdateAction.self,
table: "messages"
) { _ in }.store(in: &subscriptions)
await sut.onPostgresChange(
sut.onPostgresChange(
DeleteAction.self
) { _ in }.store(in: &subscriptions)

await sut.onBroadcast(event: "test") { _ in }.store(in: &subscriptions)
await sut.onBroadcast(event: "cursor-pos") { _ in }.store(in: &subscriptions)
sut.onBroadcast(event: "test") { _ in }.store(in: &subscriptions)
sut.onBroadcast(event: "cursor-pos") { _ in }.store(in: &subscriptions)

await sut.onPresenceChange { _ in }.store(in: &subscriptions)
sut.onPresenceChange { _ in }.store(in: &subscriptions)

await sut.onSystem {
sut.onSystem {
}
.store(in: &subscriptions)

let callbacks = await sut.callbackManager.callbacks
let callbacks = sut.callbackManager.callbacks
assertInlineSnapshot(of: callbacks, as: .dump) {
"""
▿ 8 elements
Expand Down
1 change: 1 addition & 0 deletions Tests/RealtimeTests/_PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import XCTest

@testable import Realtime

@MainActor
final class _PushTests: XCTestCase {
var ws: FakeWebSocket!
var socket: RealtimeClientV2!
Expand Down
1 change: 1 addition & 0 deletions Tests/StorageTests/SupabaseStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import XCTestDynamicOverlay
import FoundationNetworking
#endif

@MainActor
final class SupabaseStorageTests: XCTestCase {
let supabaseURL = URL(string: "http://localhost:54321/storage/v1")!
let bucketId = "tests"
Expand Down
5 changes: 3 additions & 2 deletions Tests/SupabaseTests/SupabaseClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class AuthLocalStorageMock: AuthLocalStorage {
func remove(key _: String) throws {}
}

@MainActor
final class SupabaseClientTests: XCTestCase {
func testClientInitialization() async {
final class Logger: SupabaseLogger {
Expand Down Expand Up @@ -88,7 +89,7 @@ final class SupabaseClientTests: XCTestCase {
XCTAssertEqual(client.auth.configuration.storageKey, "sb-project-ref-auth-token")

XCTAssertNotNil(
client.mutableState.listenForAuthEventsTask,
client.listenForAuthEventsTask,
"should listen for internal auth events"
)
}
Expand Down Expand Up @@ -117,7 +118,7 @@ final class SupabaseClientTests: XCTestCase {
)

XCTAssertNil(
client.mutableState.listenForAuthEventsTask,
client.listenForAuthEventsTask,
"should not listen for internal auth events when using 3p authentication"
)

Expand Down

0 comments on commit 7b65aa7

Please sign in to comment.