learning_ai_common_plat/packages/swift-platform-sdk/Tests/ByteLystPlatformTests.swift
saravanakumardb1 933390e89b feat(swift-sdk): add ByteLystPlatform unified entry point + 5 new test files (4.1)
New source:
- ByteLystPlatform.swift — unified entry point wiring all services
  (config, client, telemetry, flags, killSwitch, crashReporter, keychain, auditLog, auth)
- BLKeychainAccessor — convenience wrapper binding BLKeychain to a bundleId
- start(userId:) / stop() lifecycle for telemetry + flags + killSwitch

New tests (5 files, ~25 test cases):
- ByteLystPlatformTests — init, start/stop, idempotency, keychain accessor
- BLPlatformConfigTests — default + custom init
- BLKillSwitchClientTests — default state, reset
- BLFeatureFlagClientTests — empty flags, unknown key, stop
- BLTelemetryClientTests — installId stability, session rotation, track/flush

Also: add .build/ and .swiftpm/ to .gitignore
2026-03-19 21:05:58 -07:00

68 lines
2.1 KiB
Swift

import XCTest
@testable import ByteLystPlatformSDK
final class ByteLystPlatformTests: XCTestCase {
private func makeConfig() -> BLPlatformConfig {
BLPlatformConfig(
productId: "testapp",
baseURL: "http://localhost:4003/api",
platform: "ios",
channel: "native",
bundleId: "com.bytelyst.test"
)
}
func testInitCreatesAllServices() {
let platform = ByteLystPlatform(config: makeConfig())
XCTAssertEqual(platform.config.productId, "testapp")
XCTAssertNotNil(platform.client)
XCTAssertNotNil(platform.telemetry)
XCTAssertNotNil(platform.flags)
XCTAssertNotNil(platform.killSwitch)
XCTAssertNotNil(platform.crashReporter)
XCTAssertNotNil(platform.keychain)
XCTAssertNotNil(platform.auditLog)
XCTAssertNotNil(platform.auth)
}
func testStartSetsIsStarted() {
let platform = ByteLystPlatform(config: makeConfig())
XCTAssertFalse(platform.isStarted)
platform.start()
XCTAssertTrue(platform.isStarted)
}
func testStopClearsIsStarted() {
let platform = ByteLystPlatform(config: makeConfig())
platform.start()
XCTAssertTrue(platform.isStarted)
platform.stop()
XCTAssertFalse(platform.isStarted)
}
func testDoubleStartIsIdempotent() {
let platform = ByteLystPlatform(config: makeConfig())
platform.start()
platform.start() // Should not crash or double-start
XCTAssertTrue(platform.isStarted)
platform.stop()
}
func testDoubleStopIsIdempotent() {
let platform = ByteLystPlatform(config: makeConfig())
platform.start()
platform.stop()
platform.stop() // Should not crash
XCTAssertFalse(platform.isStarted)
}
func testKeychainAccessor() {
let accessor = BLKeychainAccessor(service: "com.bytelyst.test.accessor")
accessor.save(key: "test_key", value: "hello")
XCTAssertEqual(accessor.read(key: "test_key"), "hello")
accessor.delete(key: "test_key")
XCTAssertNil(accessor.read(key: "test_key"))
}
}