import XCTest
@testable import ByteLystPlatformSDK

final class BLKeychainTests: XCTestCase {

    private let service = "com.bytelyst.test"

    override func tearDown() {
        BLKeychain.delete(service: service, key: "test_key")
        super.tearDown()
    }

    func testSaveAndRead() {
        BLKeychain.save(service: service, key: "test_key", value: "hello")
        XCTAssertEqual(BLKeychain.read(service: service, key: "test_key"), "hello")
    }

    func testReadNonExistent() {
        XCTAssertNil(BLKeychain.read(service: service, key: "nonexistent"))
    }

    func testDelete() {
        BLKeychain.save(service: service, key: "test_key", value: "hello")
        BLKeychain.delete(service: service, key: "test_key")
        XCTAssertNil(BLKeychain.read(service: service, key: "test_key"))
    }

    func testOverwrite() {
        BLKeychain.save(service: service, key: "test_key", value: "first")
        BLKeychain.save(service: service, key: "test_key", value: "second")
        XCTAssertEqual(BLKeychain.read(service: service, key: "test_key"), "second")
    }
}
