Add 57 tests covering all data mutation paths

Refactor ShowBasedOnVoteLogics to accept injectable `now: Date` parameter
across all methods, enabling deterministic testing of voting date logic
without simulator clock manipulation.

Test coverage (55 new tests across 3 files):
- Pipeline 1: Streak calculation (7 tests) — consecutive, gaps, missing/placeholder exclusion
- Pipeline 2: Duplicate prevention (5 tests) — add replaces, removeDuplicates keeps best
- Pipeline 3: Fill missing dates (4 tests) — gap fill, idempotent, no overwrite
- Pipeline 4: Delete flows (5 tests) — clearDB, deleteLast, deleteAllEntries
- Pipeline 5: Update flows (5 tests) — mood, notes, photo set/clear
- Pipeline 6: Batch import (4 tests) — bulk insert, replace, dedup in batch
- Pipeline 7: Data listeners (3 tests) — fire on save, multiple listeners, refreshFromDisk
- Pipeline 8: Boundary edge cases (5 tests) — midnight, 23:59, day boundary leak
- Pipeline 9: Voting date logic (5 tests) — Today/Previous x before/after voting time
- Pipeline 10: Side effects orchestration (7 tests) — logMood, updateMood, deleteMood
- Pipeline 11: Full integration (5 tests) — streak grows/breaks/rebuilds, voting lifecycle

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-02-14 23:25:14 -06:00
parent f1cd81c395
commit 4125c93dfe
6 changed files with 978 additions and 24 deletions

View File

@@ -13,6 +13,9 @@
1CB4D0A028787D8A00902A56 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CB4D09F28787D8A00902A56 /* StoreKit.framework */; };
1CD90B07278C7DE0001C4FEA /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B06278C7DE0001C4FEA /* Tests_iOS.swift */; };
1CD90B09278C7DE0001C4FEA /* Tests_iOSLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B08278C7DE0001C4FEA /* Tests_iOSLaunchTests.swift */; };
1CA1B00130000001001C4FEA /* DataListenerAndVotingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA1B00130000000001C4FEA /* DataListenerAndVotingTests.swift */; };
1CA1B00130000003001C4FEA /* DataControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA1B00130000002001C4FEA /* DataControllerTests.swift */; };
1CA1B00130000005001C4FEA /* MoodLoggerIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA1B00130000004001C4FEA /* MoodLoggerIntegrationTests.swift */; };
1CD90B13278C7DE0001C4FEA /* Tests_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B12278C7DE0001C4FEA /* Tests_macOS.swift */; };
1CD90B15278C7DE0001C4FEA /* Tests_macOSLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B14278C7DE0001C4FEA /* Tests_macOSLaunchTests.swift */; };
1CD90B48278C7E7A001C4FEA /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CD90B47278C7E7A001C4FEA /* WidgetKit.framework */; platformFilter = maccatalyst; };
@@ -72,6 +75,9 @@
1CD90AFD278C7DE0001C4FEA /* macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macOS.entitlements; sourceTree = "<group>"; };
1CD90B02278C7DE0001C4FEA /* Tests iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
1CD90B06278C7DE0001C4FEA /* Tests_iOS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests_iOS.swift; sourceTree = "<group>"; };
1CA1B00130000000001C4FEA /* DataListenerAndVotingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataListenerAndVotingTests.swift; sourceTree = "<group>"; };
1CA1B00130000002001C4FEA /* DataControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataControllerTests.swift; sourceTree = "<group>"; };
1CA1B00130000004001C4FEA /* MoodLoggerIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoodLoggerIntegrationTests.swift; sourceTree = "<group>"; };
1CD90B08278C7DE0001C4FEA /* Tests_iOSLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests_iOSLaunchTests.swift; sourceTree = "<group>"; };
1CD90B0E278C7DE0001C4FEA /* Tests macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests macOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
1CD90B12278C7DE0001C4FEA /* Tests_macOS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests_macOS.swift; sourceTree = "<group>"; };
@@ -245,6 +251,9 @@
children = (
1CD90B06278C7DE0001C4FEA /* Tests_iOS.swift */,
1CD90B08278C7DE0001C4FEA /* Tests_iOSLaunchTests.swift */,
1CA1B00130000000001C4FEA /* DataListenerAndVotingTests.swift */,
1CA1B00130000002001C4FEA /* DataControllerTests.swift */,
1CA1B00130000004001C4FEA /* MoodLoggerIntegrationTests.swift */,
);
path = "Tests iOS";
sourceTree = "<group>";
@@ -331,7 +340,7 @@
name = "Tests iOS";
productName = "Tests iOS";
productReference = 1CD90B02278C7DE0001C4FEA /* Tests iOS.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
productType = "com.apple.product-type.bundle.unit-test";
};
1CD90B0D278C7DE0001C4FEA /* Tests macOS */ = {
isa = PBXNativeTarget;
@@ -537,6 +546,9 @@
files = (
1CD90B09278C7DE0001C4FEA /* Tests_iOSLaunchTests.swift in Sources */,
1CD90B07278C7DE0001C4FEA /* Tests_iOS.swift in Sources */,
1CA1B00130000001001C4FEA /* DataListenerAndVotingTests.swift in Sources */,
1CA1B00130000003001C4FEA /* DataControllerTests.swift in Sources */,
1CA1B00130000005001C4FEA /* MoodLoggerIntegrationTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -881,10 +893,11 @@
1CD90B29278C7DE0001C4FEA /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.88oak.Tests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -892,6 +905,7 @@
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Feels.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Feels";
TEST_TARGET_NAME = "Feels (iOS)";
};
name = Debug;
@@ -899,10 +913,11 @@
1CD90B2A278C7DE0001C4FEA /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.88oak.Tests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -910,6 +925,7 @@
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Feels.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Feels";
TEST_TARGET_NAME = "Feels (iOS)";
VALIDATE_PRODUCT = YES;
};