summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPNTests/MullvadVPN/View controllers/Tunnel/OutgoingConnectionServiceTests.swift
blob: 1c4b5290b2dd1769f05d7ab146e8e884d151d84c (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
//
//  OutgoingConnectionServiceTests.swift
//  MullvadVPNTests
//
//  Created by Mojgan on 2023-11-02.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import XCTest

@testable import MullvadMockData

final class OutgoingConnectionServiceTests: XCTestCase {
    func testSuccessGetOutgoingConnectionInfo() async throws {
        let mockOutgoingConnectionProxy = OutgoingConnectionProxyStub(
            ipV4: .mock,
            ipV6: .mock,
            error: nil
        )
        let outgoingConnectionService = OutgoingConnectionService(outgoingConnectionProxy: mockOutgoingConnectionProxy)
        let successExpectation = expectation(description: "Did receive exit IPs")
        let result = try await outgoingConnectionService.getOutgoingConnectionInfo()
        if result.ipv4 == .mock,
            result.ipv6 == .mock
        {
            successExpectation.fulfill()
        }
        await fulfillment(of: [successExpectation], timeout: .UnitTest.timeout)
    }

    func testFailureGetOutgoingConnectionInfo() async throws {
        let mockOutgoingConnectionProxy = OutgoingConnectionProxyStub(
            ipV4: .mock,
            ipV6: .mock,
            error: NetworkErrorStub.somethingWentWrong
        )
        let outgoingConnectionService = OutgoingConnectionService(outgoingConnectionProxy: mockOutgoingConnectionProxy)

        let failExpectation = expectation(description: "Did not receive exit IPs")
        do {
            _ = try await outgoingConnectionService.getOutgoingConnectionInfo()
        } catch {
            failExpectation.fulfill()
        }
        await fulfillment(of: [failExpectation], timeout: .UnitTest.timeout)
    }
}

enum NetworkErrorStub: Error {
    case somethingWentWrong
}