Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct PushNotificationSettingsFeature {
case binding(BindingAction<State>)
case timePicker(PresentationAction<TimePicker>)
case fetchSettings
case applyFetchedSettings(PushNotificationSettings)
case setAlert
case tapCustomTime
case selectPresetTime(Date)
Expand Down Expand Up @@ -86,6 +87,13 @@ struct PushNotificationSettingsFeature {
break
case .fetchSettings:
return fetchPushNotificationSettingsEffect()
case .applyFetchedSettings(let settings):
state.pushNotificationEnable = settings.isEnabled
if let hour = settings.scheduledTime.hour,
let minute = settings.scheduledTime.minute,
let date = Calendar.current.date(bySettingHour: hour, minute: minute, second: 0, of: Date()) {
state.viewPushNotificationTime = date
}
Comment thread
opficdev marked this conversation as resolved.
case .setAlert:
state.alert = Self.alertState()
case .tapCustomTime:
Expand Down Expand Up @@ -154,12 +162,7 @@ private extension PushNotificationSettingsFeature {
await send(.loading(.begin(target: .default, mode: .delayed)))
do {
let settings = try await fetchPushSettingsUseCase.execute()
await send(.binding(.set(\.pushNotificationEnable, settings.isEnabled)))
if let hour = settings.scheduledTime.hour,
let minute = settings.scheduledTime.minute,
let date = Calendar.current.date(bySettingHour: hour, minute: minute, second: 0, of: Date()) {
await send(.binding(.set(\.viewPushNotificationTime, date)))
}
await send(.applyFetchedSettings(settings))
await send(.loading(.end(target: .default, mode: .delayed)))
} catch {
await send(.loading(.end(target: .default, mode: .delayed)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,39 @@ struct PushNotificationSettingsFeatureTests {
settings: makePushNotificationSettings(isEnabled: true, hour: 9, minute: 0)
)
let adapter = PushNotificationSettingsStoreTestAdapter(fetchUseCase: fetchSpy)

await adapter.fetchSettings()

#expect(adapter.pushNotificationEnable)
#expect(adapter.pushNotificationHour == 9)
#expect(adapter.pushNotificationMinute == 0)
#expect(adapter.sheetPushNotificationTime == adapter.viewPushNotificationTime)
}

@Test("fetchSettings는 서버 상태 반영 중 설정 업데이트를 다시 호출하지 않는다")
func fetchSettings는_서버_상태_반영_중_설정_업데이트를_다시_호출하지_않는다() async {
let fetchSpy = FetchPushSettingsUseCaseSpy(
settings: makePushNotificationSettings(isEnabled: true, hour: 9, minute: 0)
)
let updateSpy = UpdatePushSettingsUseCaseSpy()
let adapter = PushNotificationSettingsStoreTestAdapter(
fetchUseCase: fetchSpy,
updateUseCase: updateSpy
)
await adapter.fetchSettings()
#expect(updateSpy.executeCallCount == 0)
}

@Test("setPushNotificationEnable은 활성화 상태를 변경한다")
func setPushNotificationEnable은_활성화_상태를_변경한다() async {
let adapter = PushNotificationSettingsStoreTestAdapter()

await adapter.setPushNotificationEnable(true)

#expect(adapter.pushNotificationEnable)
}

@Test("selectPresetTime은 화면과 시트 시간을 함께 변경한다")
func selectPresetTime은_화면과_시트_시간을_함께_변경한다() async {
let adapter = PushNotificationSettingsStoreTestAdapter()
let date = makeDate(hour: 15, minute: 0)

await adapter.selectPresetTime(date)

#expect(adapter.viewPushNotificationTime == date)
#expect(adapter.sheetPushNotificationTime == date)
#expect(adapter.pushNotificationHour == 15)
Expand All @@ -54,10 +62,8 @@ struct PushNotificationSettingsFeatureTests {
func setShowTimePicker는_현재_화면_시간으로_시트를_연다() async {
let adapter = PushNotificationSettingsStoreTestAdapter()
let date = makeDate(hour: 18, minute: 0)

await adapter.setPushNotificationTime(view: date)
await adapter.setShowTimePicker(true)

#expect(adapter.showTimePicker)
#expect(adapter.sheetPushNotificationTime == date)
}
Expand Down Expand Up @@ -111,10 +117,8 @@ struct PushNotificationSettingsFeatureTests {
@Test("setSheetHeight는 시트 높이 상태를 변경한다")
func setSheetHeight는_시트_높이_상태를_변경한다() async {
let adapter = PushNotificationSettingsStoreTestAdapter()

await adapter.setShowTimePicker(true)
await adapter.setSheetHeight(240)

#expect(adapter.sheetHeight == 240)
}

Expand Down Expand Up @@ -345,8 +349,10 @@ private final class FetchPushSettingsUseCaseSpy: FetchPushSettingsUseCase {

private final class UpdatePushSettingsUseCaseSpy: UpdatePushSettingsUseCase {
var error: Error?
private(set) var executeCallCount = 0

func execute(_: PushNotificationSettings) async throws {
executeCallCount += 1
if let error {
self.error = nil
throw error
Expand Down Expand Up @@ -374,12 +380,7 @@ private func makeDate(
minute: Int
) -> Date {
let baseDate = Date(timeIntervalSince1970: 0)
return Calendar.current.date(
bySettingHour: hour,
minute: minute,
second: 0,
of: baseDate
) ?? baseDate
return Calendar.current.date(bySettingHour: hour, minute: minute, second: 0, of: baseDate) ?? baseDate
}

private func expectedPushNotificationSettingsErrorAlert() -> AlertState<Never> {
Expand Down
8 changes: 4 additions & 4 deletions Tuist/ProjectDescriptionHelpers/Project+Packages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import ProjectDescription
public enum DevLogPackages {
public static let markdownUIPackage: Package = .package(
url: "https://github.com/gonzalezreal/swift-markdown-ui.git",
.upToNextMajor(from: "2.4.1")
.exact("2.4.1")
)
public static let swiftCollectionsPackage: Package = .package(
url: "https://github.com/apple/swift-collections.git",
.upToNextMajor(from: "1.3.0")
.exact("1.3.0")
)
public static let composableArchitecturePackage: Package = .package(
url: "https://github.com/pointfreeco/swift-composable-architecture",
.upToNextMinor(from: "1.25.5")
.exact("1.25.5")
)
public static let firebasePackage: Package = .package(
url: "https://github.com/firebase/firebase-ios-sdk",
.upToNextMajor(from: "11.15.0")
.exact("11.15.0")
)
public static let googleSignInPackage: Package = .package(
url: "https://github.com/google/GoogleSignIn-iOS",
Expand Down
Loading