Skip to content

Commit 3b74720

Browse files
authored
test(realtime): add realtime integration tests (#333)
* Move to ObservationTokenTests * test(realtime): add integration tests for realtime v2 * Rename schema to key_value_storage * chore: move realtime integration tests to IntegrationTests target * test: comment out failing test * test: fix optional type for receivedMessage * chore: fix dot-env target * chore: fix load env script * test: use mock web socket * chore: swift format
1 parent aca50a5 commit 3b74720

21 files changed

+499
-45
lines changed

.env

Lines changed: 0 additions & 3 deletions
This file was deleted.

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Get these from your API settings: https://supabase.com/dashboard/project/_/settings/api
2+
3+
SUPABASE_URL=https://mysupabasereference.supabase.co
4+
SUPABASE_ANON_KEY=my.supabase.anon.key

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ iOSInjectionProject/
9797

9898

9999
# Environment
100-
.env.local
100+
.env
101101
Secrets.swift
102-
Tests/IntegrationTests/Environment.swift
102+
DotEnv.swift

Makefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@ PLATFORM_WATCHOS = watchOS Simulator,name=Apple Watch Series 9 (41mm)
77
SCHEME ?= Supabase
88
PLATFORM ?= iOS Simulator,name=iPhone 15 Pro
99

10-
set-env:
11-
@source scripts/setenv.sh > Tests/IntegrationTests/Environment.swift
10+
export SECRETS
11+
define SECRETS
12+
enum DotEnv {
13+
static let SUPABASE_URL = "$(SUPABASE_URL)"
14+
static let SUPABASE_ANON_KEY = "$(SUPABASE_ANON_KEY)"
15+
}
16+
endef
1217

13-
test-all: set-env
18+
load-env:
19+
@. ./scripts/load_env.sh
20+
21+
dot-env:
22+
@echo "$$SECRETS" > Tests/IntegrationTests/DotEnv.swift
23+
24+
test-all: dot-env
1425
set -o pipefail && \
1526
xcodebuild test \
1627
-skipMacroValidation \
@@ -19,7 +30,7 @@ test-all: set-env
1930
-testPlan AllTests \
2031
-destination platform="$(PLATFORM)" | xcpretty
2132

22-
test-library: set-env
33+
test-library: dot-env
2334
set -o pipefail && \
2435
xcodebuild test \
2536
-skipMacroValidation \
@@ -28,8 +39,8 @@ test-library: set-env
2839
-derivedDataPath /tmp/derived-data \
2940
-destination platform="$(PLATFORM)" | xcpretty
3041

31-
test-integration: set-env
32-
@set -o pipefail && \
42+
test-integration: dot-env
43+
set -o pipefail && \
3344
xcodebuild test \
3445
-skipMacroValidation \
3546
-workspace supabase-swift.xcworkspace \

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ let package = Package(
7979
"Auth",
8080
"TestHelpers",
8181
"PostgREST",
82+
"Realtime",
8283
]
8384
),
8485
.target(
@@ -127,6 +128,7 @@ let package = Package(
127128
name: "RealtimeTests",
128129
dependencies: [
129130
"Realtime",
131+
"PostgREST",
130132
"TestHelpers",
131133
.product(name: "CustomDump", package: "swift-custom-dump"),
132134
]

Sources/PostgREST/PostgrestClient.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ConcurrencyExtras
33
import Foundation
44

55
public typealias PostgrestError = _Helpers.PostgrestError
6+
public typealias AnyJSON = _Helpers.AnyJSON
67

78
#if canImport(FoundationNetworking)
89
import FoundationNetworking

Sources/Realtime/V2/RealtimeClientV2.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Foundation
1515
let NSEC_PER_SEC: UInt64 = 1000000000
1616
#endif
1717

18+
public typealias JSONObject = _Helpers.JSONObject
19+
1820
public actor RealtimeClientV2 {
1921
public struct Configuration: Sendable {
2022
var url: URL
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// AsyncSequence.swift
3+
//
4+
//
5+
// Created by Guilherme Souza on 04/04/24.
6+
//
7+
8+
import Foundation
9+
10+
extension AsyncSequence {
11+
package func collect() async rethrows -> [Element] {
12+
try await reduce(into: [Element]()) { $0.append($1) }
13+
}
14+
}

Tests/IntegrationTests/AuthClientIntegrationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import XCTest
1414
final class AuthClientIntegrationTests: XCTestCase {
1515
let authClient = AuthClient(
1616
configuration: AuthClient.Configuration(
17-
url: URL(string: "\(Environment.SUPABASE_URL)/auth/v1")!,
17+
url: URL(string: "\(DotEnv.SUPABASE_URL)/auth/v1")!,
1818
headers: [
19-
"apikey": Environment.SUPABASE_ANON_KEY,
19+
"apikey": DotEnv.SUPABASE_ANON_KEY,
2020
],
2121
localStorage: InMemoryLocalStorage(),
2222
logger: nil

Tests/IntegrationTests/PostgrestIntegrationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ struct User: Codable, Hashable {
3636
@available(iOS 15.0.0, macOS 12.0.0, tvOS 13.0, *)
3737
final class IntegrationTests: XCTestCase {
3838
let client = PostgrestClient(
39-
url: URL(string: "\(Environment.SUPABASE_URL)/rest/v1")!,
39+
url: URL(string: "\(DotEnv.SUPABASE_URL)/rest/v1")!,
4040
headers: [
41-
"Apikey": Environment.SUPABASE_ANON_KEY,
41+
"Apikey": DotEnv.SUPABASE_ANON_KEY,
4242
],
4343
logger: nil
4444
)

0 commit comments

Comments
 (0)