summaryrefslogtreecommitdiff
path: root/HutchTests
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-03-18 20:03:39 -0500
committerChristian Cleberg <[email protected]>2026-03-18 20:03:39 -0500
commit090c829a5f800266da7f4ff0e59fb389f0dbfdd8 (patch)
tree8861ac737cf90f38a740f9f7ce913f192585af2a /HutchTests
parent01ce5ee73feb8bda35749a186c0efcd3d6d7a060 (diff)
downloadhutch-090c829a5f800266da7f4ff0e59fb389f0dbfdd8.tar.gz
hutch-090c829a5f800266da7f4ff0e59fb389f0dbfdd8.tar.bz2
hutch-090c829a5f800266da7f4ff0e59fb389f0dbfdd8.zip
show tracker creation errors inside the creation sheet
Diffstat (limited to 'HutchTests')
-rw-r--r--HutchTests/SettingsViewModelTests.swift39
-rw-r--r--HutchTests/TrackerListViewModelTests.swift16
2 files changed, 55 insertions, 0 deletions
diff --git a/HutchTests/SettingsViewModelTests.swift b/HutchTests/SettingsViewModelTests.swift
new file mode 100644
index 0000000..fc18162
--- /dev/null
+++ b/HutchTests/SettingsViewModelTests.swift
@@ -0,0 +1,39 @@
+import Foundation
+import Testing
+@testable import Hutch
+
+private struct DeletePGPKeyEnvelope: Decodable {
+ let deletePGPKey: DeleteResultPayload?
+}
+
+private struct DeleteResultPayload: Decodable {
+ let id: Int?
+}
+
+struct SettingsViewModelTests {
+
+ @Test
+ @MainActor
+ func deletePGPKeyResponseDecodesNullPayloadWithGraphQLErrors() throws {
+ let json = """
+ {
+ "errors": [
+ {
+ "message": "PGP key ID 13629 is set as the user's preferred PGP key - it must be unset before removing the key"
+ }
+ ],
+ "data": {
+ "deletePGPKey": null
+ }
+ }
+ """
+
+ let decoded = try JSONDecoder().decode(
+ GraphQLResponse<DeletePGPKeyEnvelope>.self,
+ from: Data(json.utf8)
+ )
+
+ #expect(decoded.data?.deletePGPKey == nil)
+ #expect(decoded.errors?.first?.message.contains("preferred PGP key") == true)
+ }
+}
diff --git a/HutchTests/TrackerListViewModelTests.swift b/HutchTests/TrackerListViewModelTests.swift
new file mode 100644
index 0000000..1caedea
--- /dev/null
+++ b/HutchTests/TrackerListViewModelTests.swift
@@ -0,0 +1,16 @@
+import Foundation
+import Testing
+@testable import Hutch
+
+struct TrackerListViewModelTests {
+
+ @Test
+ @MainActor
+ func graphQLErrorDescriptionIsPreservedForTrackerCreationFailures() {
+ let error = SRHTError.graphQLErrors([
+ GraphQLError(message: "A tracker named bugs already exists", locations: nil)
+ ])
+
+ #expect(error.localizedDescription == "GraphQL error: A tracker named bugs already exists")
+ }
+}