summaryrefslogtreecommitdiff
path: root/HutchTests/SettingsViewModelTests.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-23 17:39:13 -0500
committerChristian Cleberg <[email protected]>2026-04-23 17:39:13 -0500
commit66601a8091a73f3e31f4fb534c38b3eca4756e93 (patch)
treef85cd883e63177d25dfe5993a4d545efa4812923 /HutchTests/SettingsViewModelTests.swift
parent380fb866d090c5f13b2ad3f88f1fe23c4ade4801 (diff)
downloadhutch-3.2.1.tar.gz
hutch-3.2.1.tar.bz2
hutch-3.2.1.zip
fix: profile loading error and user-timeline prefs updatev3.2.1
Diffstat (limited to 'HutchTests/SettingsViewModelTests.swift')
-rw-r--r--HutchTests/SettingsViewModelTests.swift55
1 files changed, 55 insertions, 0 deletions
diff --git a/HutchTests/SettingsViewModelTests.swift b/HutchTests/SettingsViewModelTests.swift
index fc18162..9e4b912 100644
--- a/HutchTests/SettingsViewModelTests.swift
+++ b/HutchTests/SettingsViewModelTests.swift
@@ -2,6 +2,37 @@ import Foundation
import Testing
@testable import Hutch
+private final class SettingsViewModelCapturingURLProtocol: URLProtocol, @unchecked Sendable {
+ nonisolated(unsafe) static var capturedRequests: [URLRequest] = []
+
+ override class func canInit(with _: URLRequest) -> Bool { true }
+ override class func canonicalRequest(for request: URLRequest) -> URLRequest { request }
+
+ override func startLoading() {
+ Self.capturedRequests.append(request)
+
+ let response = HTTPURLResponse(
+ url: request.url!,
+ statusCode: 401,
+ httpVersion: nil,
+ headerFields: nil
+ )!
+ client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
+ client?.urlProtocol(self, didLoad: Data())
+ client?.urlProtocolDidFinishLoading(self)
+ }
+
+ override func stopLoading() {
+ // No cleanup is needed because the stub responds immediately in `startLoading()`.
+ }
+
+ static func makeSession() -> URLSession {
+ let config = URLSessionConfiguration.ephemeral
+ config.protocolClasses = [Self.self]
+ return URLSession(configuration: config)
+ }
+}
+
private struct DeletePGPKeyEnvelope: Decodable {
let deletePGPKey: DeleteResultPayload?
}
@@ -10,6 +41,7 @@ private struct DeleteResultPayload: Decodable {
let id: Int?
}
+@Suite(.serialized)
struct SettingsViewModelTests {
@Test
@@ -36,4 +68,27 @@ struct SettingsViewModelTests {
#expect(decoded.data?.deletePGPKey == nil)
#expect(decoded.errors?.first?.message.contains("preferred PGP key") == true)
}
+
+ @Test
+ @MainActor
+ func loadProfileDoesNotRequestSSHKeyFingerprintField() async throws {
+ SettingsViewModelCapturingURLProtocol.capturedRequests = []
+
+ let client = SRHTClient(
+ session: SettingsViewModelCapturingURLProtocol.makeSession(),
+ token: "test-token"
+ )
+ let viewModel = SettingsViewModel(client: client)
+
+ await viewModel.loadProfile()
+
+ let request = try #require(SettingsViewModelCapturingURLProtocol.capturedRequests.first)
+ let body = try #require(request.httpBody)
+ let jsonObject = try #require(JSONSerialization.jsonObject(with: body) as? [String: Any])
+ let query = try #require(jsonObject["query"] as? String)
+
+ #expect(query.contains("sshKeys"))
+ #expect(!query.contains("results { id fingerprint comment created lastUsed }"))
+ #expect(!query.contains("fingerprint comment created lastUsed"))
+ }
}