Conversation
- Updated the logger initialization in main.go and handler.go to use Init and InitNop methods instead of creating new logger instances. - Removed logger dependency from QuestionUseCase and Handler, streamlining their constructors. - Adjusted related tests to reflect the changes in logger handling, ensuring no logger instances are created during testing. - Introduced MockClock for deterministic time handling in integration tests, improving test reliability.
…se tests - Introduced multiple tests for MockClock, including consistency checks, deterministic behavior, and interface compliance. - Enhanced existing tests in QuestionUseCase to improve clarity and maintainability by using a simplified structure for familiarity levels. - Added new tests for question history retrieval, importance filtering, due-only filtering, and ordering of questions, ensuring robust coverage of use case functionalities.
- Added FormatTimeAgo method to IOHandler for consistent time formatting across the application. - Refactored the handler to utilize the new FormatTimeAgo method, improving code clarity. - Introduced comprehensive tests for the new FormatTimeAgo method, covering various time scenarios. - Enhanced existing handler tests to verify migration, reset, and settings functionalities, ensuring robust coverage and reliability.
…rage - Introduced a fixed test time variable to ensure consistent timestamps across tests in handler_test.go and file_test.go. - Updated all relevant test cases to utilize the fixed timestamp instead of time.Now(), enhancing test reliability and predictability.
- Introduced a new test function to validate the extractQuestionNameFromURL method in handler_test.go. - Added various test cases for LeetCode and HackerRank URLs, including valid and invalid formats, ensuring comprehensive coverage of the URL extraction logic. - Updated the extractQuestionNameFromURL method in handler.go to support multiple platforms and handle errors gracefully.
…r tests for deterministic behavior - Enhanced logger initialization in main.go to handle errors gracefully, ensuring the application exits with a clear message if logger setup fails. - Updated tests in scheduler_test.go to utilize a fixed random generator for consistent scheduling behavior, improving test reliability and predictability. - Refactored the SM2Scheduler to accept a random number generator interface, allowing for easier testing and deterministic outcomes in integration tests.
- Introduced multiple tests for configuration settings in config_test.go, including validation for getting, setting, and retrieving setting values and information. - Added new tests in model_test.go to verify string representations of Platform and ActionType enums. - Enhanced use case tests in usecase_test.go to cover settings retrieval, updating, and data migration to UTC, ensuring robust functionality and error handling. - Implemented a test for deleting all data in file_test.go, verifying that the storage is cleared correctly.
- Added tests for the new SettingCommand, VersionCommand, MigrateCommand, and ResetCommand in command_test.go, ensuring proper execution and handler interactions. - Introduced comprehensive tests for the IOHandler, including Println, Printf, and error handling methods, to verify output formatting and behavior under various conditions. - Enhanced existing tests in scheduler_test.go and fileutil_test.go to improve coverage and reliability, ensuring consistent behavior across different scenarios.
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughRefactors logging to package-level loggers, removes logger dependencies from handlers and use cases, introduces testable Rand and MockClock abstractions, adds IOHandler.FormatTimeAgo, improves URL parsing, and expands deterministic tests across core, handler, internal, and storage packages. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (8)
handler/io.go (1)
222-248: Consider handling future timestamps.The implementation correctly formats relative time strings with proper singular/plural handling. However, if
tis in the future (i.e.,diff < 0), the current logic would produce unexpected results like negative minutes.Consider adding a check at the beginning:
if diff < 0 { return "in the future" }This would make the behavior more predictable for edge cases.
core/scheduler_test.go (1)
10-33: Consider using the shared MockClock frominternal/clock.Based on the relevant code snippets,
internal/clock/clock.goalready providesNewMockClock. This localMockClockduplicates that implementation. Consider importing and usingclock.NewMockClockinstead to reduce duplication and ensure consistency.However, if this is intentional to avoid circular dependencies or keep test utilities self-contained within the package, this is acceptable.
internal/logger/logger_test.go (5)
9-26: Init return value should be checked.Per the relevant code snippet,
Initreturns anerror. The test ignores this return value. While the test passes implicitly (file creation succeeds), explicitly checking the error would make the test more robust and serve as documentation.🔎 Proposed fix
// Should not panic - Init(infoPath, errorPath) + if err := Init(infoPath, errorPath); err != nil { + t.Fatalf("Init failed: %v", err) + }
45-66: Check Init return value.Same issue as
TestInit- the error return fromInitshould be checked.🔎 Proposed fix
- Init(infoPath, errorPath) + if err := Init(infoPath, errorPath); err != nil { + t.Fatalf("Init failed: %v", err) + }
68-89: Check Init return value.Same issue - the error return from
Initshould be checked.🔎 Proposed fix
- Init(infoPath, errorPath) + if err := Init(infoPath, errorPath); err != nil { + t.Fatalf("Init failed: %v", err) + }
91-99: Test mutates package-level state without restoration.This test sets
infoLoggeranderrorLoggertonil, which could interfere with other tests if run in parallel or in a specific order. Consider restoring the original state after the test.🔎 Proposed fix
func TestInfof_BeforeInit(t *testing.T) { + // Save original state + origInfo := infoLogger + origError := errorLogger + defer func() { + infoLogger = origInfo + errorLogger = origError + }() + // Reset loggers to nil infoLogger = nil errorLogger = nil // Should not panic when loggers are nil Infof("test message") Errorf("test error") }
101-122: Check Init return value and consider using sync.WaitGroup.The
Initerror should be checked. Additionally,sync.WaitGroupis more idiomatic for waiting on goroutines than a channel-based approach.🔎 Proposed fix
+import "sync" + func TestConcurrentLogging(t *testing.T) { infoPath := filepath.Join(os.TempDir(), "test_concurrent_info.log") errorPath := filepath.Join(os.TempDir(), "test_concurrent_error.log") defer os.Remove(infoPath) defer os.Remove(errorPath) - Init(infoPath, errorPath) + if err := Init(infoPath, errorPath); err != nil { + t.Fatalf("Init failed: %v", err) + } - done := make(chan bool) + var wg sync.WaitGroup for i := 0; i < 10; i++ { + wg.Add(1) go func(n int) { + defer wg.Done() Infof("concurrent info message %d", n) Errorf("concurrent error message %d", n) - done <- true }(i) } - for i := 0; i < 10; i++ { - <-done - } + wg.Wait() }usecase/usecase_integration_test.go (1)
14-27: Consider extracting shared test time constant.Both
usecase_test.goandusecase_integration_test.godefine nearly identical fixed times (testTimeandintegrationTestTime). While using the same value is good for consistency, you might consider extracting this to a shared test utilities file to ensure they stay in sync.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (21)
command/command_test.goconfig/config_test.gocore/model_test.gocore/scheduler.gocore/scheduler_test.gohandler/handler.gohandler/handler_test.gohandler/io.gohandler/io_test.gointernal/clock/clock.gointernal/clock/clock_test.gointernal/errs/codederr_test.gointernal/fileutil/fileutil_test.gointernal/logger/logger.gointernal/logger/logger_test.gointernal/urlparser/urlparser_test.gomain.gostorage/file_test.gousecase/usecase.gousecase/usecase_integration_test.gousecase/usecase_test.go
🧰 Additional context used
🧬 Code graph analysis (18)
internal/fileutil/fileutil_test.go (1)
internal/fileutil/fileutil.go (1)
NewJSONFileUtil(23-25)
internal/urlparser/urlparser_test.go (1)
internal/errs/errors.go (1)
ErrInvalidURLFormat(16-16)
internal/errs/codederr_test.go (1)
internal/errs/codederr.go (4)
CodedError(11-16)SystemErrorKind(8-8)BusinessErrorKind(7-7)ValidationErrorKind(6-6)
config/config_test.go (3)
config/test_utils.go (1)
MockFileUtil(9-13)config/config.go (1)
NewConfig(223-247)internal/logger/logger.go (1)
Errorf(54-58)
handler/io.go (1)
internal/clock/clock.go (1)
Clock(8-13)
command/command_test.go (2)
command/command.go (5)
Command(11-13)SettingCommand(160-162)VersionCommand(169-171)MigrateCommand(178-180)ResetCommand(187-189)handler/handler.go (1)
Handler(19-36)
handler/handler.go (2)
handler/io.go (1)
IOHandler(44-57)internal/urlparser/urlparser.go (1)
Parse(58-88)
internal/clock/clock_test.go (1)
internal/clock/clock.go (2)
NewMockClock(44-46)Clock(8-13)
usecase/usecase.go (5)
storage/file.go (1)
Storage(10-16)core/scheduler.go (1)
Scheduler(12-16)internal/clock/clock.go (1)
Clock(8-13)internal/logger/logger.go (2)
Infof(47-51)Errorf(54-58)core/model.go (1)
Question(63-75)
internal/logger/logger_test.go (1)
internal/logger/logger.go (4)
Init(19-38)InitNop(41-44)Infof(47-51)Errorf(54-58)
usecase/usecase_integration_test.go (5)
usecase/usecase.go (2)
QuestionUseCaseImpl(39-44)NewQuestionUseCase(47-54)internal/clock/clock.go (1)
NewMockClock(44-46)storage/file.go (1)
NewFileStorage(18-24)core/scheduler.go (1)
NewSM2SchedulerWithRand(67-122)internal/logger/logger.go (1)
InitNop(41-44)
core/model_test.go (1)
core/model.go (7)
Platform(37-37)PlatformLeetCode(40-40)PlatformHackerRank(41-41)ActionType(78-78)ActionAdd(81-81)ActionUpdate(82-82)ActionDelete(83-83)
core/scheduler.go (2)
config/config.go (1)
Config(204-221)internal/clock/clock.go (1)
Clock(8-13)
handler/io_test.go (6)
core/scheduler_test.go (1)
NewMockClock(15-17)handler/io.go (2)
IOHandlerImpl(59-63)NewIOHandler(65-71)internal/clock/clock.go (1)
Clock(8-13)internal/logger/logger.go (1)
Errorf(54-58)core/model.go (7)
Question(63-75)Familiarity(18-18)Medium(23-23)Importance(9-9)HighImportance(14-14)MediumImportance(13-13)Easy(24-24)internal/errs/codederr.go (1)
CodedError(11-16)
usecase/usecase_test.go (6)
config/test_utils.go (3)
TestConfig(28-47)MockEnv(50-138)MockFileUtil(9-13)usecase/usecase.go (2)
QuestionUseCaseImpl(39-44)NewQuestionUseCase(47-54)internal/clock/clock.go (1)
NewMockClock(44-46)storage/file.go (2)
NewFileStorage(18-24)Storage(10-16)core/scheduler.go (2)
NewSM2SchedulerWithRand(67-122)FixedRand(30-32)internal/logger/logger.go (1)
InitNop(41-44)
core/scheduler_test.go (1)
core/scheduler.go (1)
Scheduler(12-16)
handler/handler_test.go (4)
internal/logger/logger.go (2)
InitNop(41-44)Errorf(54-58)handler/handler.go (1)
NewHandler(45-52)core/model.go (3)
Question(63-75)Familiarity(18-18)Importance(9-9)config/test_utils.go (1)
MockEnv(50-138)
main.go (6)
internal/logger/logger.go (1)
Init(19-38)storage/file.go (1)
NewFileStorage(18-24)core/scheduler.go (1)
NewSM2Scheduler(63-65)usecase/usecase.go (1)
NewQuestionUseCase(47-54)handler/io.go (1)
NewIOHandler(65-71)handler/handler.go (1)
NewHandler(45-52)
🔇 Additional comments (67)
core/model_test.go (3)
5-22: LGTM! Well-structured table-driven test.The test provides good coverage of the Platform.String() method, including both known platforms and the edge case of an unknown platform value. The table-driven approach and use of subtests follow Go best practices.
24-42: LGTM! Comprehensive enum testing.The test thoroughly covers ActionType.String() behavior, including the edge case where unknown action types return an empty string. The consistent table-driven structure makes the tests easy to maintain.
44-62: LGTM! Solid coverage of past tense formatting.The test provides complete coverage of ActionType.PastTenseString(), including proper handling of unknown action types. The test structure is consistent with the rest of the file, making the test suite cohesive and maintainable.
internal/errs/codederr_test.go (2)
177-225: LGTM! Comprehensive branch coverage for Error() method.The table-driven test systematically validates all formatting branches of
Error(), including edge cases whereErrandTechnicalMsgare absent. The expected outputs correctly match the formatting logic.
227-265: LGTM! Thorough validation of UserMessage() fallback chain.The table-driven test comprehensively validates the fallback behavior:
UserMsg→Err.Error()→Kind. All three branches are correctly tested, including the edge case where bothUserMsgandErrare absent.storage/file_test.go (3)
15-16: LGTM! Deterministic test time improves test reliability.The fixed test time variable aligns with the PR's goal of removing non-deterministic behavior from tests.
34-38: LGTM! Consistent use of deterministic time.Using
testTimefor all time-based fields ensures reproducible test behavior and makes test expectations clearer.
795-855: LGTM! Comprehensive test coverage for DeleteAllData.The test properly validates:
- Data exists before deletion
- Both question store and deltas are cleared after deletion
- Cache is invalidated so subsequent loads return empty data
internal/fileutil/fileutil_test.go (2)
392-419: LGTM! Proper test for Delete with cleanup.The test correctly verifies that:
- The file exists before deletion
- Delete returns no error
- The file no longer exists after deletion
- Includes cleanup in case of test failure (line 417)
421-431: LGTM! Validates idempotent delete behavior.Correctly verifies that deleting a non-existent file returns no error, which is the expected idempotent behavior for file deletion operations.
handler/io.go (2)
10-10: LGTM! Required import for new time functionality.
56-56: LGTM! Clean interface extension for time formatting.The new method signature is straightforward and follows Go conventions.
internal/urlparser/urlparser_test.go (1)
272-276: LGTM! Validates malformed URL error handling.Good edge case test ensuring the parser correctly returns
ErrInvalidURLFormatfor URLs with invalid schemes.internal/clock/clock.go (2)
38-46: LGTM! Clean mock implementation for deterministic testing.The
MockClockstruct and constructor are well-designed for injecting fixed times into tests, supporting the PR's goal of removing non-deterministic behavior.
48-62: LGTM! Complete Clock interface implementation.All four methods are correctly implemented:
Now()returns the fixed timeToday()properly extracts the date portion at midnight UTCToDate()andAddDays()mirror the production implementationThe mock enables deterministic testing of time-dependent code.
command/command_test.go (2)
22-31: LGTM! MockHandler extended to support new commands.The MockHandler properly tracks calls and arguments for the new SettingCommand, VersionCommand, MigrateCommand, and ResetCommand, maintaining consistency with the existing mock implementation pattern.
538-606: Excellent test coverage for new commands.The test functions for SettingCommand, VersionCommand, MigrateCommand, and ResetCommand follow the established testing patterns and properly verify:
- Handler methods are invoked
- Quit behavior remains correct (returns false)
- Arguments are passed correctly (e.g., settingArgs for SettingCommand)
usecase/usecase.go (2)
47-54: Clean refactoring to package-level logging.The constructor signature change removes the logger parameter, centralizing logging at the package level. This is a breaking API change but aligns with the PR's objective to improve testability and remove per-instance dependencies.
223-223: Logging calls properly migrated to package-level logger.All logging statements correctly updated from instance-level (
u.logger.Infof/Errorf) to package-level (logger.Infof/Errorf), maintaining the same logging behavior while improving testability.Also applies to: 323-323, 329-329, 370-370, 376-376, 416-416, 627-627
handler/handler_test.go (4)
20-21: Excellent use of fixed test time for determinism.Defining a constant
testTimeeliminates time-based test flakiness and makes test expectations predictable.
106-109: Good mock implementation for FormatTimeAgo.Returning a fixed string "just now" provides deterministic test behavior for time formatting assertions.
264-271: setupTestHandler properly updated for new architecture.The test helper correctly initializes the no-op logger and uses the updated NewHandler signature without a logger parameter, aligning with the refactored logging approach.
1326-1585: Comprehensive test coverage for new handler functionality.The new test functions provide thorough coverage:
- TestHandler_HandleVersion: Verifies version display
- TestHandler_GetChanges: Tests change detection logic with multiple scenarios
- TestHandler_HandleMigrate_*: Tests migration flow with success and cancellation
- TestHandler_HandleReset_*: Tests reset flow with success and cancellation
- TestHandler_HandleSetting_*: Tests settings display and validation
- TestHandler_ExtractQuestionNameFromURL: Tests URL parsing for multiple platforms
config/config_test.go (4)
138-159: Well-structured test for settings registry.TestGetSettingsRegistry properly verifies:
- Registry is non-empty
- Known configurable settings exist (randomizeinterval, overduepenalty, overduelimit)
161-194: Thorough testing of GetSettingValue.The test properly validates:
- Successful retrieval of valid settings
- Case-insensitive lookup (lines 180-187)
- Error handling for unknown settings
196-223: Good coverage of SetSettingValue functionality.Tests verify:
- Setting int values (OverdueLimit)
- Setting bool values (RandomizeInterval)
- Error handling for unknown settings
225-249: GetSettingInfo properly tested.The test validates metadata retrieval including Name and Type fields, with proper error handling for unknown settings.
internal/clock/clock_test.go (4)
131-141: Good validation of MockClock construction.TestNewMockClock properly verifies the constructor returns a non-nil instance with the correct FixedTime.
143-157: Excellent test for deterministic Now() behavior.The test verifies that multiple calls to Now() return the same fixed time, which is the key feature of MockClock for eliminating test flakiness.
183-207: Comprehensive AddDays test coverage.The table-driven test covers important scenarios:
- Positive and negative day additions
- Zero days (identity)
- Month boundary crossing
214-225: Strong validation of deterministic behavior.Running 100 iterations ensures MockClock consistently returns the same fixed time across many calls, which is critical for test reliability.
handler/io_test.go (4)
15-89: Excellent test coverage for time formatting edge cases.The test suite comprehensively covers FormatTimeAgo with deterministic timing using MockClock, including boundary conditions (59 seconds, 59 minutes, 23 hours). This ensures reliable, non-flaky tests.
176-225: Good coverage of empty note edge case.The separate test for empty notes (lines 205-225) ensures the "(none)" fallback is displayed correctly, preventing UI inconsistencies.
257-306: Comprehensive error type handling tests.The test covers all CodedError kinds (ValidationError, BusinessError, SystemError) plus nil error handling, ensuring PrintError behaves correctly across error scenarios.
367-437: Delta visualization tests cover both new and update scenarios.Tests verify both new question creation and updates with change indicators (arrows), ensuring the upsert detail display handles all cases correctly.
handler/handler.go (3)
45-52: Constructor simplified by removing logger dependency.The removal of the logger parameter aligns with the package-level logger refactoring, reducing constructor complexity and enabling easier testing.
475-475: Time formatting now delegated to IO handler.Using
h.IO.FormatTimeAgoinstead of a local helper enables deterministic testing via MockClock injection and maintains consistent time formatting across the UI layer.
593-602: Multi-platform URL parsing with robust error handling.The switch to
urlparser.Parseadds multi-platform support (LeetCode, HackerRank) and returns "unknown" on parse errors, preventing panics and improving resilience.core/scheduler.go (3)
18-34: Well-designed RNG abstraction for deterministic testing.The Rand interface with DefaultRand (production) and FixedRand (testing) implementations is a clean pattern that eliminates non-deterministic test behavior while preserving production randomization.
63-65: Constructor delegation maintains backward compatibility.NewSM2Scheduler delegates to NewSM2SchedulerWithRand with DefaultRand, preserving existing behavior for production code while enabling test injection.
179-196: Randomization now uses injected RNG.Line 185 correctly uses
s.Rand.IntN(4)instead of package-levelrand.IntN, enabling deterministic testing. The comment accurately explains the range transformation (-1 to +2 days).main.go (2)
40-43: Graceful error handling for logger initialization.The logger.Init call now returns an error instead of using log.Fatalf, allowing the application to handle initialization failures gracefully with a clear error message before exiting.
46-48: Constructor calls updated for logger refactoring.Both QuestionUseCase and Handler constructors correctly omit the logger parameter, aligning with the package-level logger architecture introduced in this PR.
internal/logger/logger.go (3)
16-38: Error return instead of fatal exit improves testability.Replacing
log.Fatalfwith error returns (lines 23, 29) allows callers to handle initialization failures gracefully, which is essential for testing and improves application robustness.
40-44: InitNop enables clean test setup.The InitNop function provides a simple way to configure no-op loggers for tests, eliminating unnecessary log output and file I/O during test execution.
46-58: Defensive nil checks prevent panics.The nil checks in Infof (line 48) and Errorf (line 55) are good defensive programming, protecting against calls before Init while adding minimal overhead.
core/scheduler_test.go (7)
35-55: LGTM!The
TestRandImplementationstests correctly verify:
DefaultRand.IntN(n)returns values within the expected range[0, n-1]FixedRand.IntN(n)consistently returns the fixed value regardless of inputGood coverage for the RNG abstraction.
57-119: LGTM!Good test structure:
TestNewSM2Scheduler_Defaultvalidates the default constructor properly initializesClockandRandTestNewSM2Schedulerthoroughly verifies all configuration values (intervals, multipliers, ease factor bounds)The separation between default and explicit RNG injection tests is clean.
121-215: LGTM!Excellent test coverage for
ScheduleNewQuestion:
- Clear comments explaining the expected interval calculations
- Deterministic assertions using exact date comparisons
- Good variety of test cases covering different importance levels and memory types
217-294: LGTM!
TestScheduleproperly tests:
- Reset behavior for
VeryHardfamiliarity- Normal scheduling with growth based on ease factor
The deterministic RNG ensures reproducible test results.
443-487: LGTM!
TestSetNextReviewthoroughly tests interval bounds:
- Normal intervals pass through correctly
- Minimum interval enforced at 1 day
- Maximum interval capped at 90 days
Good boundary testing.
590-637: LGTM!
TestEdgeCasesproperly validates edge conditions:
- Zero interval → minimum 1 day
- Negative interval → minimum 1 day
- Very large interval → capped at maxInterval (90 days)
Essential coverage for robustness.
639-670: LGTM!
TestMemoryMultiplierscorrectly validates that different memory types produce different intervals as expected:
MemoryReasoned: 8 days (×1.00)MemoryPartial: 9 days (×1.10)MemoryFull: 10 days (×1.25)internal/logger/logger_test.go (1)
28-43: LGTM!
TestInitNopcorrectly verifies:
- Loggers are initialized (non-nil) after
InitNop- Logging calls don't panic with discard writers
usecase/usecase_test.go (9)
16-40: LGTM!Excellent test setup:
testTimeprovides deterministic time baselinesetupTestEnvironmentproperly initializes all dependencies with mocks- Mock clock, fixed RNG scheduler, and no-op logger ensure reproducible tests
42-56: LGTM!
createTestQuestionproperly usestestTimefor all time fields, ensuring consistency with the mock clock.
58-125: LGTM!
TestQuestionUseCase_UpsertQuestioncomprehensively tests:
- Creating a new question with all fields verified
- Updating an existing question and verifying changes
- Storage persistence validation
215-276: LGTM!Good test for
ListQuestionsSummary:
- Uses
testTimeas reference for yesterday/tomorrow calculations- Properly verifies all summary fields
280-378: LGTM!Comprehensive search test coverage:
- Text-based search with query terms
- Filter-based search (familiarity)
- Empty query returning all questions
Using
UpsertQuestionto populate tries is the correct approach for realistic testing.
380-523: LGTM!Excellent undo test coverage:
Undo_AddAction: Verifies question is removed after undoing addUndo_UpdateAction: Verifies original state is restored after undoing updateUndo_DeleteAction: Verifies question is restored after undoing deleteUndo_NoActions: Verifies error when undo stack is empty
588-619: LGTM!
TestQuestionUseCase_SchedulerIntegrationproperly verifies:
- Questions with different familiarity levels are scheduled correctly
- All scheduled times are in the future relative to
testTime- Clean test isolation by deleting each question after verification
795-845: LGTM!
TestQuestionUseCase_MigrateToUTCproperly:
- Creates a question, then manually sets non-UTC times to simulate legacy data
- Calls
MigrateToUTCand verifies the migration counts- Validates that all times are now in UTC location
847-889: LGTM!
TestQuestionUseCase_ResetDataproperly verifies:
- Data exists before reset
- Reset returns correct counts
- Data is cleared after reset
usecase/usecase_integration_test.go (4)
29-80: LGTM!
TestQuestionUseCase_Integration_UpsertAndGetproperly exercises the full upsert-and-retrieve flow:
- Creates a question via
UpsertQuestion- Retrieves by ID and URL
- Verifies all fields match
128-174: LGTM!
TestQuestionUseCase_Integration_DeleteAndUndoprovides excellent coverage of the delete-undo cycle:
- Creates a question
- Deletes and verifies it's gone
- Undoes the deletion
- Verifies the question is restored
176-235: LGTM!
TestQuestionUseCase_Integration_ListQuestionsSummarycorrectly:
- Uses
integrationTestTimefor relative date calculations- Manually populates the store with due/upcoming questions
- Verifies all summary counts
237-257: LGTM!
TestQuestionUseCase_Integration_ErrorHandlingcovers essential error cases:
- Getting non-existent question
- Deleting non-existent question
- Undo with empty stack
- Modified the confirmation prompts in HandleMigrate and HandleReset methods to provide clearer instructions for user input, enhancing usability and reducing potential confusion during critical operations.
Description
log.Fatalfwith error return inlogger.Init()for graceful error handlingRandinterface into scheduler for deterministic testing (fixes flaky tests)Type of Change
Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.