//
//  AMapBootstrapTests.swift
//  suixinkanTests
//

import XCTest
@testable import suixinkan

/// 高德 SDK 初始化 gate 测试。
final class AMapBootstrapTests: XCTestCase {

    private var defaults: UserDefaults!
    private var appStore: AppStore!

    override func setUp() {
        super.setUp()
        AMapBootstrap.resetForTesting()
        defaults = UserDefaults(suiteName: "AMapBootstrapTests")!
        defaults.removePersistentDomain(forName: "AMapBootstrapTests")
        appStore = AppStore(defaults: defaults)
    }

    override func tearDown() {
        AMapBootstrap.resetForTesting()
        super.tearDown()
    }

    func testConfigureReturnsFalseWhenPrivacyNotAccepted() {
        appStore.session.privacyAgreementAccepted = false

        XCTAssertFalse(AMapBootstrap.configureIfNeeded(appStore: appStore))
        XCTAssertFalse(AMapBootstrap.isConfigured)
    }

    func testConfigureIsIdempotentWhenPrivacyAccepted() {
        appStore.session.privacyAgreementAccepted = true

        XCTAssertTrue(AMapBootstrap.configureIfNeeded(appStore: appStore))
        XCTAssertTrue(AMapBootstrap.isConfigured)
        XCTAssertTrue(AMapBootstrap.configureIfNeeded(appStore: appStore))
        XCTAssertTrue(AMapBootstrap.isConfigured)
    }

    func testRequireConfiguredThrowsWhenPrivacyNotAccepted() {
        appStore.session.privacyAgreementAccepted = false

        XCTAssertThrowsError(try AMapBootstrap.requireConfigured(appStore: appStore)) { error in
            XCTAssertEqual(error as? LocationProviderError, .privacyNotAccepted)
        }
    }
}
