diff options
Diffstat (limited to 'HutchTests/SettingsViewModelTests.swift')
| -rw-r--r-- | HutchTests/SettingsViewModelTests.swift | 39 |
1 files changed, 39 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) + } +} |
