Skip to content

Commit 14e68f2

Browse files
authored
test(auth): add integration tests to Auth (#280)
* test(auth): add integration tests to Auth test: lower expectation timeout ci: run test library with local supabase ci: run docker on macos wip Revert package folder structure revert ci * Add IntegrationTests test plan * chore: get secrets from environment * ci: add integration-tests jobs * chore: baseURL raw string * chore: fix test plan * revert: PostgrestIntegrationTests * chore: load env from file * chore: set-env before test-library * chore: move setenv.sh to scripts folder * chore: allow test prefix on commit * chore: allow package prefix
1 parent acd991c commit 14e68f2

File tree

17 files changed

+417
-47
lines changed

17 files changed

+417
-47
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SUPABASE_URL=
2+
SUPABASE_ANON_KEY=
3+
SUPABASE_SERVICE_KEY=

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ jobs:
4040
- name: Build for library evolution
4141
run: make build-for-library-evolution
4242

43+
integration-tests:
44+
runs-on: macos-14
45+
name: Integration Tests
46+
steps:
47+
- uses: actions/checkout@v3
48+
with:
49+
fetch-depth: 0
50+
- name: Select Xcode 15.3
51+
run: sudo xcode-select -s /Applications/Xcode_15.3.app
52+
- name: Run tests
53+
run: make test-integration
54+
env:
55+
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
56+
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
57+
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
58+
59+
4360
examples:
4461
runs-on: macos-14
4562
name: Build Examples

.github/workflows/conventional-commits-lint.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ALLOWED_CONVENTIONAL_COMMIT_PREFIXES = [
1515
"docs",
1616
"chore",
1717
"style",
18+
"test",
1819
];
1920

2021
const object = process.argv[2];
@@ -72,12 +73,6 @@ validate.forEach((payload) => {
7273
);
7374
failed = true;
7475
}
75-
76-
if (groups.package && groups.prefix !== "chore") {
77-
console.warn(
78-
"Avoid using package specifications in PR titles or commits except for the `chore` prefix.",
79-
);
80-
}
8176
} else {
8277
console.error(
8378
"PR or commit title must match conventional commit structure.",

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@ iOSInjectionProject/
9595
/*.xcodeproj
9696
# /.swiftpm
9797

98+
99+
# Environment
100+
.env.local
98101
Secrets.swift
99-
.env
102+
Tests/IntegrationTests/Environment.swift

.swiftpm/xcode/xcshareddata/xcschemes/Supabase.xcscheme

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
reference = "container:Supabase.xctestplan"
3333
default = "YES">
3434
</TestPlanReference>
35+
<TestPlanReference
36+
reference = "container:IntegrationTests.xctestplan">
37+
</TestPlanReference>
3538
</TestPlans>
3639
</TestAction>
3740
<LaunchAction

IntegrationTests.xctestplan

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "EFD3DB79-4307-4515-8158-5E17BF4577D4",
5+
"name" : "Configuration 1",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
13+
},
14+
"testTargets" : [
15+
{
16+
"target" : {
17+
"containerPath" : "container:",
18+
"identifier" : "IntegrationTests",
19+
"name" : "IntegrationTests"
20+
}
21+
}
22+
],
23+
"version" : 1
24+
}

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ PLATFORM_MAC_CATALYST = macOS,variant=Mac Catalyst
44
PLATFORM_TVOS = tvOS Simulator,name=Apple TV
55
PLATFORM_WATCHOS = watchOS Simulator,name=Apple Watch Series 9 (41mm)
66

7+
set-env:
8+
@source scripts/setenv.sh > Tests/IntegrationTests/Environment.swift
9+
710
test-all: test-library test-linux
811

9-
test-library:
12+
test-library: set-env
1013
for platform in "$(PLATFORM_IOS)" "$(PLATFORM_MACOS)" "$(PLATFORM_MAC_CATALYST)" "$(PLATFORM_TVOS)" "$(PLATFORM_WATCHOS)"; do \
1114
set -o pipefail && \
1215
xcodebuild test \
@@ -17,6 +20,16 @@ test-library:
1720
-destination platform="$$platform" | xcpretty; \
1821
done;
1922

23+
test-integration: set-env
24+
@set -o pipefail && \
25+
xcodebuild test \
26+
-skipMacroValidation \
27+
-workspace supabase-swift.xcworkspace \
28+
-scheme Supabase \
29+
-testPlan IntegrationTests \
30+
-destination platform="$(PLATFORM_IOS)" | xcpretty
31+
32+
2033
test-linux:
2134
docker build -t supabase-swift .
2235
docker run supabase-swift

Package.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,30 @@ let package = Package(
7070
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
7171
]
7272
),
73+
.testTarget(
74+
name: "IntegrationTests",
75+
dependencies: [
76+
.product(name: "CustomDump", package: "swift-custom-dump"),
77+
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
78+
"_Helpers",
79+
"Auth",
80+
"TestHelpers",
81+
"PostgREST",
82+
]
83+
),
7384
.target(
7485
name: "Auth",
7586
dependencies: goTrueDependencies
7687
),
7788
.testTarget(
7889
name: "AuthTests",
7990
dependencies: [
80-
"Auth",
81-
"_Helpers",
82-
"TestHelpers",
91+
.product(name: "CustomDump", package: "swift-custom-dump"),
8392
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
8493
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
94+
"_Helpers",
95+
"Auth",
96+
"TestHelpers",
8597
],
8698
exclude: [
8799
"__Snapshots__",
@@ -104,7 +116,6 @@ let package = Package(
104116
],
105117
exclude: ["__Snapshots__"]
106118
),
107-
.testTarget(name: "PostgRESTIntegrationTests", dependencies: ["PostgREST"]),
108119
.target(
109120
name: "Realtime",
110121
dependencies: [
@@ -141,7 +152,13 @@ let package = Package(
141152
]
142153
),
143154
.testTarget(name: "SupabaseTests", dependencies: ["Supabase"]),
144-
.target(name: "TestHelpers"),
155+
.target(
156+
name: "TestHelpers",
157+
dependencies: [
158+
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
159+
"Auth",
160+
]
161+
),
145162
]
146163
)
147164

Sources/Auth/AuthError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Foundation
22

3-
public enum AuthError: LocalizedError, Sendable {
3+
public enum AuthError: LocalizedError, Sendable, Equatable {
44
case missingExpClaim
55
case malformedJWT
66
case sessionNotFound
77
case api(APIError)
88
case pkce(PKCEFailureReason)
99
case invalidImplicitGrantFlowURL
1010

11-
public struct APIError: Error, Decodable, Sendable {
11+
public struct APIError: Error, Decodable, Sendable, Equatable {
1212
/// A basic message describing the problem with the request. Usually missing if
1313
/// ``AuthError/APIError/error`` is present.
1414
public var msg: String?
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Auth
2+
import ConcurrencyExtras
3+
import Foundation
4+
5+
package final class InMemoryLocalStorage: AuthLocalStorage, @unchecked Sendable {
6+
let _storage = LockIsolated([String: Data]())
7+
8+
package var storage: [String: Data] {
9+
_storage.value
10+
}
11+
12+
package init() {}
13+
14+
package func store(key: String, value: Data) throws {
15+
_storage.withValue {
16+
$0[key] = value
17+
}
18+
}
19+
20+
package func retrieve(key: String) throws -> Data? {
21+
_storage.value[key]
22+
}
23+
24+
package func remove(key: String) throws {
25+
_storage.withValue {
26+
$0[key] = nil
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)