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