Skip to content

Add tests for SnapTrade#742

Merged
jjmata merged 1 commit into
we-promise:mainfrom
luckyPipewrench:add-snaptrade-tests
Jan 22, 2026
Merged

Add tests for SnapTrade#742
jjmata merged 1 commit into
we-promise:mainfrom
luckyPipewrench:add-snaptrade-tests

Conversation

@luckyPipewrench

@luckyPipewrench luckyPipewrench commented Jan 22, 2026

Copy link
Copy Markdown
Collaborator

Created two new test files:

test/models/snaptrade_account_processor_test.rb (17 tests):

  • HoldingsProcessor: creating holdings, storing cost basis, respecting manual cost basis priority, skipping invalid entries
  • ActivitiesProcessor: BUY/SELL type mapping, DIVIDEND handling, withdrawal amount normalization, unmapped type fallback, idempotency

test/models/snaptrade_data_helpers_test.rb (17 tests):

  • parse_decimal: BigDecimal, String, Integer, Float, nil, invalid string
  • parse_date: Date, ISO string, Time, DateTime, nil, invalid string
  • resolve_security: find existing, create new, uppercase ticker, blank ticker, race condition
  • extract_currency: hash with code, string currency, fallback to symbol_data, fallback param, nil

Fixed Fixture Inconsistency:

Renamed unconfigured_item to pending_registration_item with:

  • Added client_id and consumer_key (required on create)
  • Left snaptrade_user_id and snaptrade_user_secret blank (represents "credentials saved, not yet connected to SnapTrade portal")
  • Added explanatory comments

Summary by CodeRabbit

  • Tests
    • Updated fixture data for pending registration scenarios
    • Added comprehensive test coverage for account data processing, including holdings management, transaction categorization, and activity mapping
    • Expanded test suite for data validation utilities covering decimal parsing, date handling, security resolution, and currency extraction with edge case handling

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Test coverage additions for Snaptrade account processing functionality. A fixture file is updated to reflect pending registration state, while two new test suites comprehensively validate account processor logic and data helper methods for handling holdings, activities, decimal parsing, date conversion, security resolution, and currency extraction.

Changes

Cohort / File(s) Summary
Fixture Update
test/fixtures/snaptrade_items.yml
Replaces unconfigured_item fixture with pending_registration_item, adds pending_client_id and pending_consumer_key credential fields, updates comments to clarify pending registration state
Account Processor Tests
test/models/snaptrade_account_processor_test.rb
New test suite validating holdings creation from raw payloads, cost basis handling, BUY/SELL/DIVIDEND activity mapping, withdrawal normalization, idempotency with external_id deduplication, and handling of incomplete/malformed data
Data Helper Tests
test/models/snaptrade_data_helpers_test.rb
New test suite with TestHelper wrapper exposing private methods; validates parse_decimal, parse_date, resolve_security, and extract_currency across multiple input types (BigDecimal, String, Integer, Float, Date, Time, DateTime, nil) and edge cases

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Fix SnapTrade cursorbot comments #741: Modifies and expands SnaptradeAccount::DataHelpers module while this PR adds comprehensive unit tests for those helper methods, creating complementary coverage.

Suggested reviewers

  • jjmata
  • sokie

Poem

🐰 A fixture now ready, accounts to align,
Test helpers and processors in perfect design,
With holdings and activities, edge cases too,
Data flows smoothly, bright skies break through!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: adding comprehensive tests for SnapTrade functionality across multiple test files and fixing fixture inconsistencies.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jjmata jjmata merged commit 6279bfc into we-promise:main Jan 22, 2026
6 checks passed
binarygituser referenced this pull request in binarygituser/sure-dev Apr 26, 2026
…lpers. (#742)

Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
jaxver pushed a commit to jaxver/sure that referenced this pull request May 31, 2026
…lpers. (we-promise#742)

Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

2 participants