From 090c829a5f800266da7f4ff0e59fb389f0dbfdd8 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Wed, 18 Mar 2026 20:03:39 -0500 Subject: show tracker creation errors inside the creation sheet --- HutchTests/SettingsViewModelTests.swift | 39 ++++++++++++++++++++++++++++++ HutchTests/TrackerListViewModelTests.swift | 16 ++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 HutchTests/SettingsViewModelTests.swift create mode 100644 HutchTests/TrackerListViewModelTests.swift (limited to 'HutchTests') 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.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") + } +} -- cgit v1.2.3