- Update Plant test fixtures to use roomID instead of deprecated location - Add URLDataFetcher protocol to ImageCache for dependency injection - Update ImageCacheTests to use protocol-based mock instead of URLSession subclass - Add missing cancelReminders(for:plantID:) method to MockNotificationService - Add Equatable conformance to ImageCacheError for test assertions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
213 lines
6.7 KiB
Swift
213 lines
6.7 KiB
Swift
//
|
|
// Plant+TestFixtures.swift
|
|
// PlantGuideTests
|
|
//
|
|
// Test fixtures for Plant entity - provides factory methods for creating
|
|
// test instances with sensible defaults.
|
|
//
|
|
|
|
import Foundation
|
|
@testable import PlantGuide
|
|
|
|
// MARK: - Plant Test Fixtures
|
|
|
|
extension Plant {
|
|
|
|
// MARK: - Factory Methods
|
|
|
|
/// Creates a mock plant with default values for testing
|
|
/// - Parameters:
|
|
/// - id: The plant's unique identifier. Defaults to a new UUID.
|
|
/// - scientificName: Scientific name. Defaults to "Monstera deliciosa".
|
|
/// - commonNames: Array of common names. Defaults to ["Swiss Cheese Plant"].
|
|
/// - family: Botanical family. Defaults to "Araceae".
|
|
/// - genus: Botanical genus. Defaults to "Monstera".
|
|
/// - imageURLs: Remote image URLs. Defaults to empty.
|
|
/// - dateIdentified: When plant was identified. Defaults to current date.
|
|
/// - identificationSource: Source of identification. Defaults to .onDeviceML.
|
|
/// - localImagePaths: Local storage paths. Defaults to empty.
|
|
/// - dateAdded: When added to collection. Defaults to nil.
|
|
/// - confidenceScore: Identification confidence. Defaults to 0.95.
|
|
/// - notes: User notes. Defaults to nil.
|
|
/// - isFavorite: Favorite status. Defaults to false.
|
|
/// - customName: User-assigned name. Defaults to nil.
|
|
/// - roomID: Room ID where plant is located. Defaults to nil.
|
|
/// - Returns: A configured Plant instance for testing
|
|
static func mock(
|
|
id: UUID = UUID(),
|
|
scientificName: String = "Monstera deliciosa",
|
|
commonNames: [String] = ["Swiss Cheese Plant"],
|
|
family: String = "Araceae",
|
|
genus: String = "Monstera",
|
|
imageURLs: [URL] = [],
|
|
dateIdentified: Date = Date(),
|
|
identificationSource: IdentificationSource = .onDeviceML,
|
|
localImagePaths: [String] = [],
|
|
dateAdded: Date? = nil,
|
|
confidenceScore: Double? = 0.95,
|
|
notes: String? = nil,
|
|
isFavorite: Bool = false,
|
|
customName: String? = nil,
|
|
roomID: UUID? = nil
|
|
) -> Plant {
|
|
Plant(
|
|
id: id,
|
|
scientificName: scientificName,
|
|
commonNames: commonNames,
|
|
family: family,
|
|
genus: genus,
|
|
imageURLs: imageURLs,
|
|
dateIdentified: dateIdentified,
|
|
identificationSource: identificationSource,
|
|
localImagePaths: localImagePaths,
|
|
dateAdded: dateAdded,
|
|
confidenceScore: confidenceScore,
|
|
notes: notes,
|
|
isFavorite: isFavorite,
|
|
customName: customName,
|
|
roomID: roomID
|
|
)
|
|
}
|
|
|
|
/// Creates a mock Monstera plant
|
|
static func mockMonstera(
|
|
id: UUID = UUID(),
|
|
isFavorite: Bool = false
|
|
) -> Plant {
|
|
mock(
|
|
id: id,
|
|
scientificName: "Monstera deliciosa",
|
|
commonNames: ["Swiss Cheese Plant", "Monstera"],
|
|
family: "Araceae",
|
|
genus: "Monstera",
|
|
isFavorite: isFavorite
|
|
)
|
|
}
|
|
|
|
/// Creates a mock Pothos plant
|
|
static func mockPothos(
|
|
id: UUID = UUID(),
|
|
isFavorite: Bool = false
|
|
) -> Plant {
|
|
mock(
|
|
id: id,
|
|
scientificName: "Epipremnum aureum",
|
|
commonNames: ["Pothos", "Devil's Ivy", "Golden Pothos"],
|
|
family: "Araceae",
|
|
genus: "Epipremnum",
|
|
isFavorite: isFavorite
|
|
)
|
|
}
|
|
|
|
/// Creates a mock Snake Plant
|
|
static func mockSnakePlant(
|
|
id: UUID = UUID(),
|
|
isFavorite: Bool = false
|
|
) -> Plant {
|
|
mock(
|
|
id: id,
|
|
scientificName: "Sansevieria trifasciata",
|
|
commonNames: ["Snake Plant", "Mother-in-law's Tongue"],
|
|
family: "Asparagaceae",
|
|
genus: "Sansevieria",
|
|
isFavorite: isFavorite
|
|
)
|
|
}
|
|
|
|
/// Creates a mock Peace Lily plant
|
|
static func mockPeaceLily(
|
|
id: UUID = UUID(),
|
|
isFavorite: Bool = false
|
|
) -> Plant {
|
|
mock(
|
|
id: id,
|
|
scientificName: "Spathiphyllum wallisii",
|
|
commonNames: ["Peace Lily", "Spathe Flower"],
|
|
family: "Araceae",
|
|
genus: "Spathiphyllum",
|
|
isFavorite: isFavorite
|
|
)
|
|
}
|
|
|
|
/// Creates a mock Fiddle Leaf Fig plant
|
|
static func mockFiddleLeafFig(
|
|
id: UUID = UUID(),
|
|
isFavorite: Bool = false
|
|
) -> Plant {
|
|
mock(
|
|
id: id,
|
|
scientificName: "Ficus lyrata",
|
|
commonNames: ["Fiddle Leaf Fig", "Fiddle-leaf Fig"],
|
|
family: "Moraceae",
|
|
genus: "Ficus",
|
|
isFavorite: isFavorite
|
|
)
|
|
}
|
|
|
|
/// Creates an array of mock plants for collection testing
|
|
static func mockCollection(count: Int = 5) -> [Plant] {
|
|
var plants: [Plant] = []
|
|
let generators: [() -> Plant] = [
|
|
{ .mockMonstera() },
|
|
{ .mockPothos() },
|
|
{ .mockSnakePlant() },
|
|
{ .mockPeaceLily() },
|
|
{ .mockFiddleLeafFig() }
|
|
]
|
|
|
|
for i in 0..<count {
|
|
plants.append(generators[i % generators.count]())
|
|
}
|
|
return plants
|
|
}
|
|
|
|
/// Creates a plant with an image URL for caching tests
|
|
static func mockWithImages(
|
|
id: UUID = UUID(),
|
|
imageCount: Int = 3
|
|
) -> Plant {
|
|
let imageURLs = (0..<imageCount).map { index in
|
|
URL(string: "https://example.com/images/plant_\(id.uuidString)_\(index).jpg")!
|
|
}
|
|
return mock(
|
|
id: id,
|
|
imageURLs: imageURLs
|
|
)
|
|
}
|
|
|
|
/// Creates a plant with local image paths for storage tests
|
|
static func mockWithLocalImages(
|
|
id: UUID = UUID(),
|
|
imageCount: Int = 2
|
|
) -> Plant {
|
|
let localPaths = (0..<imageCount).map { index in
|
|
"\(id.uuidString)/image_\(index).jpg"
|
|
}
|
|
return mock(
|
|
id: id,
|
|
localImagePaths: localPaths
|
|
)
|
|
}
|
|
|
|
/// Creates a fully populated plant with all optional fields
|
|
static func mockComplete(id: UUID = UUID()) -> Plant {
|
|
mock(
|
|
id: id,
|
|
scientificName: "Monstera deliciosa",
|
|
commonNames: ["Swiss Cheese Plant", "Monstera", "Split-leaf Philodendron"],
|
|
family: "Araceae",
|
|
genus: "Monstera",
|
|
imageURLs: [URL(string: "https://example.com/monstera.jpg")!],
|
|
dateIdentified: Date(),
|
|
identificationSource: .plantNetAPI,
|
|
localImagePaths: ["\(id.uuidString)/captured.jpg"],
|
|
dateAdded: Date(),
|
|
confidenceScore: 0.98,
|
|
notes: "Needs regular watering and indirect light",
|
|
isFavorite: true,
|
|
customName: "My Beautiful Monstera",
|
|
roomID: nil
|
|
)
|
|
}
|
|
}
|