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
@@ -0,0 +1,52 @@
//
// PushNotificationListTestSpies.swift
// NotificationTabTests
//
// Created by opfic on 7/6/26.
//

import Domain

final class DeletePushNotificationUseCaseSpy: DeletePushNotificationUseCase {
private(set) var calledNotificationIds = [String]()

func execute(_ notificationID: String) async throws {
calledNotificationIds.append(notificationID)
}
}

final class UndoDeletePushNotificationUseCaseSpy: UndoDeletePushNotificationUseCase {
private(set) var calledNotificationIds = [String]()

func execute(_ notificationID: String) async throws {
calledNotificationIds.append(notificationID)
}
}

final class TogglePushNotificationReadUseCaseSpy: TogglePushNotificationReadUseCase {
private(set) var calledTodoIds = [String]()
var error: Error?

func execute(_ todoId: String) async throws {
calledTodoIds.append(todoId)
if let error {
throw error
}
}
}

final class FetchPushNotificationQueryUseCaseSpy: FetchPushNotificationQueryUseCase {
var pushNotificationQuery = PushNotificationQuery.default

func execute() -> PushNotificationQuery {
pushNotificationQuery
}
}

final class UpdatePushNotificationQueryUseCaseSpy: UpdatePushNotificationQueryUseCase {
private(set) var queries = [PushNotificationQuery]()

func execute(_ query: PushNotificationQuery) {
queries.append(query)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

import Testing
import Foundation
import Combine
import Core
import Domain
@testable import PresentationShared

@MainActor
func waitUntil(
Expand All @@ -25,254 +21,3 @@ func waitUntil(
try? await Task.sleep(for: pollInterval)
}
}

final class FetchPushNotificationsUseCaseSpy: FetchPushNotificationsUseCase {
var pushNotificationPage: PushNotificationPage
private(set) var executeCallCount = 0

init(pushNotificationPage: PushNotificationPage) {
self.pushNotificationPage = pushNotificationPage
}

func execute(
_ query: PushNotificationQuery,
cursor: PushNotificationCursor?
) async throws -> PushNotificationPage {
executeCallCount += 1
return pushNotificationPage
}

func observe(
_ query: PushNotificationQuery,
limit: Int
) throws -> AnyPublisher<PushNotificationPage, Error> {
Empty().eraseToAnyPublisher()
}
}

final class SignInUseCaseSpy: SignInUseCase {
var error: Error?
var signedIn = true
var shouldSuspend = false
private(set) var calledProviders: [AuthProvider] = []
private(set) var successfulProviders = [AuthProvider]()
private var continuation: CheckedContinuation<Void, Never>?
private var shouldResume = false

func execute(_ provider: AuthProvider) async throws -> Bool {
calledProviders.append(provider)

if shouldSuspend {
await withCheckedContinuation { continuation in
if shouldResume {
shouldResume = false
continuation.resume()
} else {
self.continuation = continuation
}
}
}

if let error {
throw error
}

if signedIn {
successfulProviders.append(provider)
}

return signedIn
}

func resume() {
guard let continuation else {
shouldResume = true
return
}
self.continuation = nil
continuation.resume()
}
}

final class DeletePushNotificationUseCaseSpy: DeletePushNotificationUseCase {
private(set) var calledNotificationIds: [String] = []

func execute(_ notificationID: String) async throws {
calledNotificationIds.append(notificationID)
}
}

final class UndoDeletePushNotificationUseCaseSpy: UndoDeletePushNotificationUseCase {
private(set) var calledNotificationIds: [String] = []

func execute(_ notificationID: String) async throws {
calledNotificationIds.append(notificationID)
}
}

final class TogglePushNotificationReadUseCaseSpy: TogglePushNotificationReadUseCase {
private(set) var calledTodoIds: [String] = []
var error: Error?

func execute(_ todoId: String) async throws {
calledTodoIds.append(todoId)
if let error {
throw error
}
}
}

final class FetchPushNotificationQueryUseCaseSpy: FetchPushNotificationQueryUseCase {
var pushNotificationQuery = PushNotificationQuery.default

func execute() -> PushNotificationQuery {
pushNotificationQuery
}
}

final class UpdatePushNotificationQueryUseCaseSpy: UpdatePushNotificationQueryUseCase {
private(set) var queries: [PushNotificationQuery] = []

func execute(_ query: PushNotificationQuery) {
queries.append(query)
}
}

final class FetchTodoCategoryPreferencesUseCaseSpy: FetchTodoCategoryPreferencesUseCase {
var todoCategoryPreferences: [TodoCategoryPreference] = []

func execute() async throws -> [TodoCategoryPreference] {
todoCategoryPreferences
}
}

final class UpdateTodoCategoryPreferencesUseCaseSpy: UpdateTodoCategoryPreferencesUseCase {
private(set) var updates: [[TodoCategoryPreference]] = []

func execute(_ preferences: [TodoCategoryPreference]) async throws {
updates.append(preferences)
}
}

final class AddWebPageUseCaseSpy: AddWebPageUseCase {
var error: Error?
private(set) var calledUrlStrings: [String] = []

func execute(_ urlString: String) async throws {
calledUrlStrings.append(urlString)
if let error {
throw error
}
}
}

final class DeleteWebPageUseCaseSpy: DeleteWebPageUseCase {
private(set) var calls: [(id: String, urlString: String)] = []

func execute(id: String, urlString: String) async throws {
calls.append((id, urlString))
}
}

final class UndoDeleteWebPageUseCaseSpy: UndoDeleteWebPageUseCase {
private(set) var calledIDs: [String] = []

func execute(_ id: String) async throws {
calledIDs.append(id)
}
}

final class UpsertTodoUseCaseSpy: UpsertTodoUseCase {
private(set) var todos: [Todo] = []
private(set) var todoDrafts: [TodoDraft] = []

func execute(_ todo: Todo) async throws {
todos.append(todo)
}

func execute(_ todoDraft: TodoDraft) async throws {
todoDrafts.append(todoDraft)
}
}

final class FetchTodosUseCaseSpy: FetchTodosUseCase {
var todoPage = TodoPage(items: [], nextCursor: nil)
private(set) var queries: [TodoQuery] = []

func execute(_ query: TodoQuery, cursor: TodoCursor?) async throws -> TodoPage {
queries.append(query)
return todoPage
}
}

final class FetchUserDataUseCaseSpy: FetchUserDataUseCase {
var profile: UserProfile

init(profile: UserProfile) {
self.profile = profile
}

func execute() async throws -> UserProfile {
profile
}
}

final class FetchProfileImageDataUseCaseSpy: FetchProfileImageDataUseCase {
var data: Data
private(set) var calledURLs: [URL] = []

init(data: Data) {
self.data = data
}

func execute(from url: URL) async throws -> Data {
calledURLs.append(url)
return data
}
}

final class UpsertStatusMessageUseCaseSpy: UpsertStatusMessageUseCase {
private(set) var messages: [String] = []

func execute(_ message: String) async throws {
messages.append(message)
}
}

final class FetchHeatmapActivityTypesUseCaseSpy: FetchHeatmapActivityTypesUseCase {
var activityTypes: [String] = []

func execute() -> [String] {
activityTypes
}
}

final class UpdateHeatmapActivityTypesUseCaseSpy: UpdateHeatmapActivityTypesUseCase {
private(set) var activityTypes: [[String]] = []

func execute(_ activityTypes: [String]) {
self.activityTypes.append(activityTypes)
}
}

final class FetchWebPagesUseCaseSpy: FetchWebPagesUseCase {
var webPages: [WebPage]
private(set) var calledQueries: [String] = []

init(webPages: [WebPage]) {
self.webPages = webPages
}

func execute(_ query: String) async throws -> [WebPage] {
calledQueries.append(query)
return webPages
}
}

final class ObserveNetworkConnectivityUseCaseSpy: ObserveNetworkConnectivityUseCase {
let currentValueSubject = CurrentValueSubject<Bool, Never>(true)

func observe() -> AnyPublisher<Bool, Never> {
currentValueSubject.eraseToAnyPublisher()
}
}
Loading