feat: 新增 Fake 仓库实现(含可提交的打卡/计划与会话)

This commit is contained in:
AndyChen1024
2026-09-15 14:35:52 +08:00
parent ec1eed8f04
commit c39a324534
5 changed files with 316 additions and 12 deletions

View File

@@ -0,0 +1,39 @@
import Combine
import CoreDomain
import Foundation
/// Fake 会话仓库(登录态在进程内共享,默认未登录)。
public final class FakeSessionRepository: SessionRepository, @unchecked Sendable {
private let isLoggedIn = CurrentValueSubject<Bool, Never>(false)
public init() {}
public func observeIsLoggedIn() -> AsyncThrowingStream<Bool, Error> {
AsyncThrowingStream { continuation in
let cancellable = self.isLoggedIn.sink { continuation.yield($0) }
continuation.onTermination = { _ in cancellable.cancel() }
}
}
public func requestSmsCode(phone: String) async throws {
try await Task.sleep(for: .milliseconds(500))
guard phone.range(of: #"^1\d{10}$"#, options: .regularExpression) != nil else {
throw SessionError.invalidPhone
}
}
public func login(phone: String, code: String) async throws {
try await Task.sleep(for: .milliseconds(500))
guard code == "123456" else {
throw SessionError.wrongCode
}
guard phone == "13812341234" else {
throw SessionError.phoneNotMatched
}
isLoggedIn.value = true
}
public func logout() async throws {
isLoggedIn.value = false
}
}