aboutsummaryrefslogtreecommitdiff
path: root/HutchTests/SettingsViewModelTests.swift
blob: fc1816292db9e37e6710bb1d39fa700b5ec368f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
    }
}