summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadRESTTests/DefaultLocationServiceTests.swift
blob: 8d54efd20730c86f5c195afe314c436759b43c39 (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
//
//  DefaultLocationServiceTests.swift
//  MullvadVPN
//
//  Created by Jon Petersson on 2025-10-15.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import XCTest

@testable import MullvadMockData
@testable import MullvadREST

class DefaultLocationServiceTests: XCTestCase {
    private let encoder = JSONEncoder()

    func testFetchCurrentLocationIdentifier() async throws {
        let mockData = try encoder.encode(
            REST.ServerLocation(
                country: "USA",
                city: "Dallas, TX",
                latitude: 32.89748,
                longitude: -97.040443
            )
        )

        let locationService = DefaultLocationService(
            urlSession: URLSessionStub(
                response: (mockData, URLResponse())
            ),
            relayCache: try MockRelayCache().read().cachedRelays
        )

        let identifier = try await locationService.fetchCurrentLocationIdentifier()

        XCTAssertEqual(identifier?.country, "us")
        XCTAssertEqual(identifier?.city, "dal")
    }
}