krz/hutch
an ios client for sourcehut
clone: git clone https://gitbay.org/krz/hutch.git
v2.7.0: HutchTests/SettingsViewModelTests.swift · raw
1import Foundation
2import Testing
3@testable import Hutch
4
5private struct DeletePGPKeyEnvelope: Decodable {
6 let deletePGPKey: DeleteResultPayload?
7}
8
9private struct DeleteResultPayload: Decodable {
10 let id: Int?
11}
12
13struct SettingsViewModelTests {
14
15 @Test
16 @MainActor
17 func deletePGPKeyResponseDecodesNullPayloadWithGraphQLErrors() throws {
18 let json = """
19 {
20 "errors": [
21 {
22 "message": "PGP key ID 13629 is set as the user's preferred PGP key - it must be unset before removing the key"
23 }
24 ],
25 "data": {
26 "deletePGPKey": null
27 }
28 }
29 """
30
31 let decoded = try JSONDecoder().decode(
32 GraphQLResponse<DeletePGPKeyEnvelope>.self,
33 from: Data(json.utf8)
34 )
35
36 #expect(decoded.data?.deletePGPKey == nil)
37 #expect(decoded.errors?.first?.message.contains("preferred PGP key") == true)
38 }
39}