// // CareTask+TestFixtures.swift // PlantGuideTests // // Test fixtures for CareTask entity - provides factory methods for // creating test instances with sensible defaults. // import Foundation @testable import PlantGuide // MARK: - CareTask Test Fixtures extension CareTask { // MARK: - Factory Methods /// Creates a mock care task with default values for testing /// - Parameters: /// - id: The task's unique identifier. Defaults to a new UUID. /// - plantID: ID of the plant this task belongs to. Defaults to a new UUID. /// - type: Type of care task. Defaults to .watering. /// - scheduledDate: When the task is scheduled. Defaults to tomorrow. /// - completedDate: When the task was completed. Defaults to nil (not completed). /// - notes: Additional notes. Defaults to empty string. /// - Returns: A configured CareTask instance for testing static func mock( id: UUID = UUID(), plantID: UUID = UUID(), type: CareTaskType = .watering, scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 1, to: Date())!, completedDate: Date? = nil, notes: String = "" ) -> CareTask { CareTask( id: id, plantID: plantID, type: type, scheduledDate: scheduledDate, completedDate: completedDate, notes: notes ) } /// Creates a mock watering task /// - Parameters: /// - plantID: ID of the plant this task belongs to /// - scheduledDate: When the task is scheduled. Defaults to tomorrow. /// - completedDate: When the task was completed. Defaults to nil. /// - Returns: A watering task static func mockWatering( id: UUID = UUID(), plantID: UUID = UUID(), scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 1, to: Date())!, completedDate: Date? = nil ) -> CareTask { mock( id: id, plantID: plantID, type: .watering, scheduledDate: scheduledDate, completedDate: completedDate, notes: "Water with moderate amount" ) } /// Creates a mock fertilizing task /// - Parameters: /// - plantID: ID of the plant this task belongs to /// - scheduledDate: When the task is scheduled. Defaults to next week. /// - completedDate: When the task was completed. Defaults to nil. /// - Returns: A fertilizing task static func mockFertilizing( id: UUID = UUID(), plantID: UUID = UUID(), scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 7, to: Date())!, completedDate: Date? = nil ) -> CareTask { mock( id: id, plantID: plantID, type: .fertilizing, scheduledDate: scheduledDate, completedDate: completedDate, notes: "Apply balanced fertilizer" ) } /// Creates a mock repotting task /// - Parameters: /// - plantID: ID of the plant this task belongs to /// - scheduledDate: When the task is scheduled. Defaults to next month. /// - Returns: A repotting task static func mockRepotting( id: UUID = UUID(), plantID: UUID = UUID(), scheduledDate: Date = Calendar.current.date(byAdding: .month, value: 1, to: Date())! ) -> CareTask { mock( id: id, plantID: plantID, type: .repotting, scheduledDate: scheduledDate, notes: "Move to larger pot with fresh soil" ) } /// Creates a mock pruning task /// - Parameters: /// - plantID: ID of the plant this task belongs to /// - scheduledDate: When the task is scheduled. Defaults to next week. /// - Returns: A pruning task static func mockPruning( id: UUID = UUID(), plantID: UUID = UUID(), scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 14, to: Date())! ) -> CareTask { mock( id: id, plantID: plantID, type: .pruning, scheduledDate: scheduledDate, notes: "Remove dead leaves and shape plant" ) } /// Creates a mock pest control task /// - Parameters: /// - plantID: ID of the plant this task belongs to /// - scheduledDate: When the task is scheduled. Defaults to tomorrow. /// - Returns: A pest control task static func mockPestControl( id: UUID = UUID(), plantID: UUID = UUID(), scheduledDate: Date = Calendar.current.date(byAdding: .day, value: 1, to: Date())! ) -> CareTask { mock( id: id, plantID: plantID, type: .pestControl, scheduledDate: scheduledDate, notes: "Apply neem oil treatment" ) } /// Creates an overdue task (scheduled in the past, not completed) static func mockOverdue( plantID: UUID = UUID(), daysOverdue: Int = 3 ) -> CareTask { mock( plantID: plantID, type: .watering, scheduledDate: Calendar.current.date(byAdding: .day, value: -daysOverdue, to: Date())!, completedDate: nil, notes: "Overdue watering task" ) } /// Creates a completed task static func mockCompleted( plantID: UUID = UUID(), type: CareTaskType = .watering ) -> CareTask { let scheduledDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())! return mock( plantID: plantID, type: type, scheduledDate: scheduledDate, completedDate: Date(), notes: "Completed task" ) } /// Creates a future task scheduled for a specific number of days ahead static func mockFuture( plantID: UUID = UUID(), type: CareTaskType = .watering, daysAhead: Int = 7 ) -> CareTask { mock( plantID: plantID, type: type, scheduledDate: Calendar.current.date(byAdding: .day, value: daysAhead, to: Date())! ) } /// Creates an array of watering tasks for the next several weeks static func mockWeeklyWateringTasks( plantID: UUID = UUID(), weeks: Int = 4 ) -> [CareTask] { (0.. [CareTask] { [ mockWatering(plantID: plantID), mockFertilizing(plantID: plantID), mockPruning(plantID: plantID) ] } }