Skip to content

Commit

Permalink
chore: move realtime integration tests to IntegrationTests target
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Apr 4, 2024
1 parent 5d374a1 commit 6c62ea6
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 28 deletions.
3 changes: 0 additions & 3 deletions .env

This file was deleted.

4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Get these from your API settings: https://supabase.com/dashboard/project/_/settings/api

SUPABASE_URL=https://mysupabasereference.supabase.co
SUPABASE_ANON_KEY=my.supabase.anon.key
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ iOSInjectionProject/


# Environment
.env.local
.env
Secrets.swift
Tests/IntegrationTests/Environment.swift
DotEnv.swift
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ PLATFORM_WATCHOS = watchOS Simulator,name=Apple Watch Series 9 (41mm)
SCHEME ?= Supabase
PLATFORM ?= iOS Simulator,name=iPhone 15 Pro

set-env:
@source scripts/setenv.sh > Tests/IntegrationTests/Environment.swift
dot-env:
@./scripts/dotenv.sh > Tests/IntegrationTests/DotEnv.swift

test-all: set-env
test-all: dot-env
set -o pipefail && \
xcodebuild test \
-skipMacroValidation \
Expand All @@ -19,7 +19,7 @@ test-all: set-env
-testPlan AllTests \
-destination platform="$(PLATFORM)" | xcpretty

test-library: set-env
test-library: dot-env
set -o pipefail && \
xcodebuild test \
-skipMacroValidation \
Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ let package = Package(
"Auth",
"TestHelpers",
"PostgREST",
"Realtime",
]
),
.target(
Expand Down
14 changes: 14 additions & 0 deletions Sources/TestHelpers/AsyncSequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AsyncSequence.swift
//
//
// Created by Guilherme Souza on 04/04/24.
//

import Foundation

extension AsyncSequence {
package func collect() async rethrows -> [Element] {
try await reduce(into: [Element]()) { $0.append($1) }
}
}
4 changes: 2 additions & 2 deletions Tests/IntegrationTests/AuthClientIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import XCTest
final class AuthClientIntegrationTests: XCTestCase {
let authClient = AuthClient(
configuration: AuthClient.Configuration(
url: URL(string: "\(Environment.SUPABASE_URL)/auth/v1")!,
url: URL(string: "\(DotEnv.SUPABASE_URL)/auth/v1")!,
headers: [
"apikey": Environment.SUPABASE_ANON_KEY,
"apikey": DotEnv.SUPABASE_ANON_KEY,
],
localStorage: InMemoryLocalStorage(),
logger: nil
Expand Down
4 changes: 2 additions & 2 deletions Tests/IntegrationTests/PostgrestIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ struct User: Codable, Hashable {
@available(iOS 15.0.0, macOS 12.0.0, tvOS 13.0, *)
final class IntegrationTests: XCTestCase {
let client = PostgrestClient(
url: URL(string: "\(Environment.SUPABASE_URL)/rest/v1")!,
url: URL(string: "\(DotEnv.SUPABASE_URL)/rest/v1")!,
headers: [
"Apikey": Environment.SUPABASE_ANON_KEY,
"Apikey": DotEnv.SUPABASE_ANON_KEY,
],
logger: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@ import ConcurrencyExtras
import CustomDump
import PostgREST
@testable import Realtime
import Supabase
import TestHelpers
import XCTest

struct Logger: SupabaseLogger {
func log(message: SupabaseLogMessage) {
print(message.description)
}
}

final class RealtimeIntegrationTests: XCTestCase {
let realtime = RealtimeClientV2(
config: RealtimeClientV2.Configuration(
url: URL(string: "http://localhost:54321/realtime/v1")!,
apiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0"
url: URL(string: "\(DotEnv.SUPABASE_URL)/realtime/v1")!,
apiKey: DotEnv.SUPABASE_ANON_KEY,
logger: Logger()
)
)

let db = PostgrestClient(
url: URL(string: "http://localhost:54321/rest/v1")!,
url: URL(string: "\(DotEnv.SUPABASE_URL)/rest/v1")!,
headers: [
"apikey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU",
"apikey": DotEnv.SUPABASE_ANON_KEY,
],
logger: nil
logger: Logger()
)

func testBroadcast() async throws {
Expand Down
6 changes: 0 additions & 6 deletions Tests/RealtimeTests/RealtimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ final class RealtimeTests: XCTestCase {
}
}

extension AsyncSequence {
func collect() async rethrows -> [Element] {
try await reduce(into: [Element]()) { $0.append($1) }
}
}

extension RealtimeMessageV2 {
static let subscribeToMessages = Self(
joinRef: "1",
Expand Down
8 changes: 4 additions & 4 deletions scripts/setenv.sh → scripts/dotenv.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
env_file="${1:-.env}"

if [[ -f "$env_file" ]]; then
echo "enum Environment {"
echo "enum DotEnv {"
while IFS='=' read -r key value || [[ -n "$key" ]]; do
if [[ -n "$key" ]]; then
if [[ -n "$key" && ! "$key" =~ ^# ]]; then
if [[ -z "$value" ]]; then
value=$(eval "echo \$$key")
fi
echo " static let $key = \"$value\""
fi
done < "$env_file"
done < <(grep -v '^#' "$env_file")
echo "}"
fi
fi

0 comments on commit 6c62ea6

Please sign in to comment.