|
| 1 | +// |
| 2 | +// WidgetSessionSyncHandlerTests.swift |
| 3 | +// DevLogAppTests |
| 4 | +// |
| 5 | +// Created by opfic on 6/1/26. |
| 6 | +// |
| 7 | + |
| 8 | +import Combine |
| 9 | +import Foundation |
| 10 | +import Testing |
| 11 | +import DevLogData |
| 12 | +@testable import DevLog |
| 13 | + |
| 14 | +struct WidgetSessionSyncHandlerTests { |
| 15 | + @Test("로그인 세션 true 첫 진입에서만 위젯 초기 동기화를 요청한다") |
| 16 | + func 로그인_세션_true_첫_진입에서만_위젯_초기_동기화를_요청한다() async { |
| 17 | + let authServiceSpy = AuthServiceSpy() |
| 18 | + let widgetSyncEventBusSpy = WidgetSyncEventBusSpy() |
| 19 | + let widgetSessionSyncHandler = WidgetSessionSyncHandler( |
| 20 | + authService: authServiceSpy, |
| 21 | + widgetSyncEventBus: widgetSyncEventBusSpy |
| 22 | + ) |
| 23 | + |
| 24 | + authServiceSpy.send(true) |
| 25 | + authServiceSpy.send(true) |
| 26 | + |
| 27 | + await withCheckedContinuation { continuation in |
| 28 | + DispatchQueue.main.async { |
| 29 | + continuation.resume() |
| 30 | + } |
| 31 | + } |
| 32 | + #expect(widgetSyncEventBusSpy.events == [.syncRequested]) |
| 33 | + _ = widgetSessionSyncHandler |
| 34 | + } |
| 35 | + |
| 36 | + @Test("로그아웃 이후 재로그인 시 위젯 초기 동기화를 다시 요청한다") |
| 37 | + func 로그아웃_이후_재로그인_시_위젯_초기_동기화를_다시_요청한다() async { |
| 38 | + let authServiceSpy = AuthServiceSpy() |
| 39 | + let widgetSyncEventBusSpy = WidgetSyncEventBusSpy() |
| 40 | + let widgetSessionSyncHandler = WidgetSessionSyncHandler( |
| 41 | + authService: authServiceSpy, |
| 42 | + widgetSyncEventBus: widgetSyncEventBusSpy |
| 43 | + ) |
| 44 | + |
| 45 | + authServiceSpy.send(true) |
| 46 | + authServiceSpy.send(false) |
| 47 | + authServiceSpy.send(true) |
| 48 | + |
| 49 | + await withCheckedContinuation { continuation in |
| 50 | + DispatchQueue.main.async { |
| 51 | + continuation.resume() |
| 52 | + } |
| 53 | + } |
| 54 | + #expect(widgetSyncEventBusSpy.events == [.syncRequested, .syncRequested]) |
| 55 | + _ = widgetSessionSyncHandler |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +private final class AuthServiceSpy: AuthService { |
| 60 | + private let currentValueSubject = CurrentValueSubject<Bool, Never>(false) |
| 61 | + |
| 62 | + var uid: String? { nil } |
| 63 | + var providerIDs: [String] { [] } |
| 64 | + var currentUserEmail: String? { nil } |
| 65 | + var providerCount: Int { 0 } |
| 66 | + |
| 67 | + func observeSignedIn() -> AnyPublisher<Bool, Never> { |
| 68 | + currentValueSubject.eraseToAnyPublisher() |
| 69 | + } |
| 70 | + |
| 71 | + func beginSignIn() { } |
| 72 | + func completeSignIn() { } |
| 73 | + func cancelSignIn() { } |
| 74 | + func getProviderID() async throws -> String? { nil } |
| 75 | + func deleteCurrentUser() async throws { } |
| 76 | + func clearCurrentSession() async throws { } |
| 77 | + |
| 78 | + func send(_ isSignedIn: Bool) { |
| 79 | + currentValueSubject.send(isSignedIn) |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +private final class WidgetSyncEventBusSpy: WidgetSyncEventBus { |
| 84 | + private(set) var events = [WidgetSyncEvent]() |
| 85 | + |
| 86 | + func publish(_ event: WidgetSyncEvent) { |
| 87 | + events.append(event) |
| 88 | + } |
| 89 | + |
| 90 | + func observe() -> AnyPublisher<WidgetSyncEvent, Never> { |
| 91 | + Empty().eraseToAnyPublisher() |
| 92 | + } |
| 93 | +} |
0 commit comments