Skip to content

Commit 7e37b0e

Browse files
chore: extract CoderSDK to framework (#19)
Closes #2.
1 parent 51bc926 commit 7e37b0e

File tree

21 files changed

+787
-325
lines changed

21 files changed

+787
-325
lines changed

Coder Desktop/Coder Desktop.xcodeproj/project.pbxproj

+344-59
Large diffs are not rendered by default.

Coder Desktop/Coder Desktop.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
{
2-
"originHash" : "1cd4f7368eeddbaa35ef829e13093bc7081a4e6d3da9492d22db0757464ad473",
2+
"originHash" : "ec40e522ec1a2416e8e8f5cbe97424ab3e4a614e6ef453c10ea28e84e88b6771",
33
"pins" : [
4-
{
5-
"identity" : "alamofire",
6-
"kind" : "remoteSourceControl",
7-
"location" : "https://github.com/Alamofire/Alamofire",
8-
"state" : {
9-
"revision" : "513364f870f6bfc468f9d2ff0a95caccc10044c5",
10-
"version" : "5.10.2"
11-
}
12-
},
134
{
145
"identity" : "fluid-menu-bar-extra",
156
"kind" : "remoteSourceControl",

Coder Desktop/Coder Desktop.xcodeproj/xcshareddata/xcschemes/Coder Desktop.xcscheme

+11
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@
7979
ReferencedContainer = "container:Coder Desktop.xcodeproj">
8080
</BuildableReference>
8181
</TestableReference>
82+
<TestableReference
83+
skipped = "NO"
84+
parallelizable = "YES">
85+
<BuildableReference
86+
BuildableIdentifier = "primary"
87+
BlueprintIdentifier = "AA3B40972D2FC8560099996A"
88+
BuildableName = "CoderSDKTests.xctest"
89+
BlueprintName = "CoderSDKTests"
90+
ReferencedContainer = "container:Coder Desktop.xcodeproj">
91+
</BuildableReference>
92+
</TestableReference>
8293
</Testables>
8394
</TestAction>
8495
<LaunchAction

Coder Desktop/Coder Desktop.xctestplan

+13-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@
1919
{
2020
"target" : {
2121
"containerPath" : "container:Coder Desktop.xcodeproj",
22-
"identifier" : "9616790E2CFF100E00B2B6DF",
23-
"name" : "Coder DesktopTests"
22+
"identifier" : "AA3B40972D2FC8560099996A",
23+
"name" : "CoderSDKTests"
24+
}
25+
},
26+
{
27+
"enabled" : false,
28+
"parallelizable" : true,
29+
"target" : {
30+
"containerPath" : "container:Coder Desktop.xcodeproj",
31+
"identifier" : "961679182CFF100E00B2B6DF",
32+
"name" : "Coder DesktopUITests"
2433
}
2534
},
2635
{
@@ -31,12 +40,10 @@
3140
}
3241
},
3342
{
34-
"enabled" : false,
35-
"parallelizable" : true,
3643
"target" : {
3744
"containerPath" : "container:Coder Desktop.xcodeproj",
38-
"identifier" : "961679182CFF100E00B2B6DF",
39-
"name" : "Coder DesktopUITests"
45+
"identifier" : "9616790E2CFF100E00B2B6DF",
46+
"name" : "Coder DesktopTests"
4047
}
4148
}
4249
],

Coder Desktop/Coder Desktop/Coder_DesktopApp.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct DesktopApp: App {
1111
EmptyView()
1212
}
1313
Window("Sign In", id: Windows.login.rawValue) {
14-
LoginForm<PreviewClient, PreviewSession>()
14+
LoginForm<PreviewSession>()
1515
}.environmentObject(appDelegate.session)
1616
.windowResizability(.contentSize)
1717
}

Coder Desktop/Coder Desktop/Preview Content/PreviewClient.swift

-29
This file was deleted.

Coder Desktop/Coder Desktop/SDK/Client.swift

-140
This file was deleted.

Coder Desktop/Coder Desktop/SDK/User.swift

-37
This file was deleted.

Coder Desktop/Coder Desktop/Views/LoginForm.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import CoderSDK
12
import SwiftUI
23

3-
struct LoginForm<C: Client, S: Session>: View {
4+
struct LoginForm<S: Session>: View {
45
@EnvironmentObject var session: S
56
@Environment(\.dismiss) private var dismiss
67

@@ -69,7 +70,7 @@ struct LoginForm<C: Client, S: Session>: View {
6970
}
7071
loading = true
7172
defer { loading = false }
72-
let client = C(url: url, token: sessionToken)
73+
let client = Client(url: url, token: sessionToken)
7374
do {
7475
_ = try await client.user("me")
7576
} catch {
@@ -188,6 +189,6 @@ enum LoginField: Hashable {
188189
}
189190

190191
#Preview {
191-
LoginForm<PreviewClient, PreviewSession>()
192+
LoginForm<PreviewSession>()
192193
.environmentObject(PreviewSession())
193194
}

Coder Desktop/Coder DesktopTests/LoginFormTests.swift

+34-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@testable import Coder_Desktop
2+
@testable import CoderSDK
3+
import Mocker
24
import SwiftUI
35
import Testing
46
import ViewInspector
@@ -7,12 +9,12 @@ import ViewInspector
79
@Suite(.timeLimit(.minutes(1)))
810
struct LoginTests {
911
let session: MockSession
10-
let sut: LoginForm<MockClient, MockSession>
12+
let sut: LoginForm<MockSession>
1113
let view: any View
1214

1315
init() {
1416
session = MockSession()
15-
sut = LoginForm<MockClient, MockSession>()
17+
sut = LoginForm<MockSession>()
1618
view = sut.environmentObject(session)
1719
}
1820

@@ -68,14 +70,16 @@ struct LoginTests {
6870

6971
@Test
7072
func testFailedAuthentication() async throws {
71-
let login = LoginForm<MockErrorClient, MockSession>()
73+
let login = LoginForm<MockSession>()
74+
let url = URL(string: "https://testFailedAuthentication.com")!
75+
Mock(url: url.appendingPathComponent("/api/v2/users/me"), statusCode: 401, data: [.get: Data()]).register()
7276

7377
try await ViewHosting.host(login.environmentObject(session)) {
7478
try await login.inspection.inspect { view in
75-
try view.find(ViewType.TextField.self).setInput("https://coder.example.com")
79+
try view.find(ViewType.TextField.self).setInput(url.absoluteString)
7680
try view.find(button: "Next").tap()
7781
#expect(throws: Never.self) { try view.find(text: "Session Token") }
78-
try view.find(ViewType.SecureField.self).setInput("valid-token")
82+
try view.find(ViewType.SecureField.self).setInput("invalid-token")
7983
try await view.actualView().submit()
8084
#expect(throws: Never.self) { try view.find(ViewType.Alert.self) }
8185
}
@@ -84,9 +88,33 @@ struct LoginTests {
8488

8589
@Test
8690
func testSuccessfulLogin() async throws {
91+
let url = URL(string: "https://testSuccessfulLogin.com")!
92+
93+
let user = User(
94+
id: UUID(),
95+
username: "admin",
96+
avatar_url: "",
97+
name: "admin",
98+
99+
created_at: Date.now,
100+
updated_at: Date.now,
101+
last_seen_at: Date.now,
102+
status: "active",
103+
login_type: "none",
104+
theme_preference: "dark",
105+
organization_ids: [],
106+
roles: []
107+
)
108+
109+
try Mock(
110+
url: url.appendingPathComponent("/api/v2/users/me"),
111+
statusCode: 200,
112+
data: [.get: Client.encoder.encode(user)]
113+
).register()
114+
87115
try await ViewHosting.host(view) {
88116
try await sut.inspection.inspect { view in
89-
try view.find(ViewType.TextField.self).setInput("https://coder.example.com")
117+
try view.find(ViewType.TextField.self).setInput(url.absoluteString)
90118
try view.find(button: "Next").tap()
91119
try view.find(ViewType.SecureField.self).setInput("valid-token")
92120
try await view.actualView().submit()

0 commit comments

Comments
 (0)