Skip to content

chore: extract CoderSDK to framework #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 344 additions & 59 deletions Coder Desktop/Coder Desktop.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"originHash" : "1cd4f7368eeddbaa35ef829e13093bc7081a4e6d3da9492d22db0757464ad473",
"originHash" : "ec40e522ec1a2416e8e8f5cbe97424ab3e4a614e6ef453c10ea28e84e88b6771",
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "513364f870f6bfc468f9d2ff0a95caccc10044c5",
"version" : "5.10.2"
}
},
{
"identity" : "fluid-menu-bar-extra",
"kind" : "remoteSourceControl",
Original file line number Diff line number Diff line change
@@ -79,6 +79,17 @@
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AA3B40972D2FC8560099996A"
BuildableName = "CoderSDKTests.xctest"
BlueprintName = "CoderSDKTests"
ReferencedContainer = "container:Coder Desktop.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
19 changes: 13 additions & 6 deletions Coder Desktop/Coder Desktop.xctestplan
Original file line number Diff line number Diff line change
@@ -19,8 +19,17 @@
{
"target" : {
"containerPath" : "container:Coder Desktop.xcodeproj",
"identifier" : "9616790E2CFF100E00B2B6DF",
"name" : "Coder DesktopTests"
"identifier" : "AA3B40972D2FC8560099996A",
"name" : "CoderSDKTests"
}
},
{
"enabled" : false,
"parallelizable" : true,
"target" : {
"containerPath" : "container:Coder Desktop.xcodeproj",
"identifier" : "961679182CFF100E00B2B6DF",
"name" : "Coder DesktopUITests"
}
},
{
@@ -31,12 +40,10 @@
}
},
{
"enabled" : false,
"parallelizable" : true,
"target" : {
"containerPath" : "container:Coder Desktop.xcodeproj",
"identifier" : "961679182CFF100E00B2B6DF",
"name" : "Coder DesktopUITests"
"identifier" : "9616790E2CFF100E00B2B6DF",
"name" : "Coder DesktopTests"
}
}
],
2 changes: 1 addition & 1 deletion Coder Desktop/Coder Desktop/Coder_DesktopApp.swift
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ struct DesktopApp: App {
EmptyView()
}
Window("Sign In", id: Windows.login.rawValue) {
LoginForm<PreviewClient, PreviewSession>()
LoginForm<PreviewSession>()
}.environmentObject(appDelegate.session)
.windowResizability(.contentSize)
}
29 changes: 0 additions & 29 deletions Coder Desktop/Coder Desktop/Preview Content/PreviewClient.swift

This file was deleted.

140 changes: 0 additions & 140 deletions Coder Desktop/Coder Desktop/SDK/Client.swift

This file was deleted.

37 changes: 0 additions & 37 deletions Coder Desktop/Coder Desktop/SDK/User.swift

This file was deleted.

7 changes: 4 additions & 3 deletions Coder Desktop/Coder Desktop/Views/LoginForm.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CoderSDK
import SwiftUI

struct LoginForm<C: Client, S: Session>: View {
struct LoginForm<S: Session>: View {
@EnvironmentObject var session: S
@Environment(\.dismiss) private var dismiss

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

#Preview {
LoginForm<PreviewClient, PreviewSession>()
LoginForm<PreviewSession>()
.environmentObject(PreviewSession())
}
40 changes: 34 additions & 6 deletions Coder Desktop/Coder DesktopTests/LoginFormTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@testable import Coder_Desktop
@testable import CoderSDK
import Mocker
import SwiftUI
import Testing
import ViewInspector
@@ -7,12 +9,12 @@ import ViewInspector
@Suite(.timeLimit(.minutes(1)))
struct LoginTests {
let session: MockSession
let sut: LoginForm<MockClient, MockSession>
let sut: LoginForm<MockSession>
let view: any View

init() {
session = MockSession()
sut = LoginForm<MockClient, MockSession>()
sut = LoginForm<MockSession>()
view = sut.environmentObject(session)
}

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

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

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

@Test
func testSuccessfulLogin() async throws {
let url = URL(string: "https://testSuccessfulLogin.com")!

let user = User(
id: UUID(),
username: "admin",
avatar_url: "",
name: "admin",
email: "[email protected]",
created_at: Date.now,
updated_at: Date.now,
last_seen_at: Date.now,
status: "active",
login_type: "none",
theme_preference: "dark",
organization_ids: [],
roles: []
)

try Mock(
url: url.appendingPathComponent("/api/v2/users/me"),
statusCode: 200,
data: [.get: Client.encoder.encode(user)]
).register()

try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
try view.find(ViewType.TextField.self).setInput("https://coder.example.com")
try view.find(ViewType.TextField.self).setInput(url.absoluteString)
try view.find(button: "Next").tap()
try view.find(ViewType.SecureField.self).setInput("valid-token")
try await view.actualView().submit()
Loading