Skip to content

send reponse as json in rr#285

Merged
polographer merged 5 commits intotrunkfrom
clickup_868fubywe
Oct 3, 2025
Merged

send reponse as json in rr#285
polographer merged 5 commits intotrunkfrom
clickup_868fubywe

Conversation

@ymhari
Copy link
Copy Markdown
Contributor

@ymhari ymhari commented Oct 2, 2025

https://app.clickup.com/t/868fubywe

Summary by CodeRabbit

  • New Features

    • Process multiple VLP verification responses per applicant.
    • Automatically trigger VLP citizenship verification when SSN is verified but citizenship is not.
    • Close-case flow accepts and uses a VLP transaction when building requests.
  • Bug Fixes

    • Stored response payloads standardized to JSON for consistent recording and comparisons.
    • Stop marking immigration evidence as outstanding in affected scenarios.
  • Tests

    • Expanded SSA and VLP test fixtures and adjusted expectations for richer verification payloads.

Signed-off-by: HARIDHAR YAMJALA <hariym471@gmail.com>
@ymhari ymhari requested a review from saipraveen18 October 2, 2025 18:39
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 2, 2025

Walkthrough

Serializes stored raw_payload to JSON, drops immigration_evidence from two SSA evidence branches, processes multiple VLP verification transactions per applicant, conditionally triggers VLP when SSN verified but citizenship not, threads vlp_transaction through close-case flows, and updates tests/fixtures to richer SSA/VLP payloads.

Changes

Cohort / File(s) Summary
Response utils
app/operations/fdsh/ssa_vlp/rj3/response_processor_utils.rb
build_request_result now stores raw_payload as @response.to_json (was raw @response); added inline comment on source.
SSA evidence state logic
app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb
calculate_evidence_states removed immigration_evidence: :outstanding from the ssn_verified && !citizenship_verified and !ssn_verified branches; those branches now omit the immigration_evidence key.
Applicant response processing (VLP multi-response)
app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb
find_vlp_verification_response now returns a collection; update_dhs_verification_response iterates all vlp_verification_response transactions (ascending created_at), applying per-transaction processing and updating application_hash, with early exit on failure.
SSA applicant request (VLP trigger)
app/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request.rb
Added trigger_vlp_for_citizenship and can_trigger_vlp_for_citizenship?; after saving SSA response may invoke VLP ApplicantRequest when SSN verified but citizenship not; defensive rescue added.
VLP close-case threading
app/operations/fdsh/ssa_vlp/rj3/vlp/close_case/applicant_request.rb, app/operations/fdsh/ssa_vlp/rj3/vlp/close_case/handle_request.rb
Threaded vlp_transaction through calls: validate_params requires it; success tuple returns applicant, job, vlp_transaction; generate_request_payload uses @vlp_transaction.json_payload.deep_symbolize_keys; handle_request iterates applicant vlp_verification_response transactions and calls ApplicantRequest with vlp_transaction:; invocation sites updated and failure aggregation flattened.
Specs — fixtures & VLP wiring
spec/operations/fdsh/ssa_vlp/rj3/handle_verification_request_spec.rb, spec/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request_spec.rb, spec/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response_spec.rb, spec/operations/fdsh/ssa_vlp/rj3/vlp/close_case/*_spec.rb
Tests use richer SSA mock (ssnVerificationIndicator: true plus extra fields), add VLP request/response stubs and InitialVerificationResponse fixture, assert vlp_verification_response transactions exist and compare evidence raw_payload to JSON-serialized SSA payload; some immigration-evidence assertions removed.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant ApplicantResponses
  participant TransactionStore
  participant Processor

  Caller->>ApplicantResponses: update_dhs_verification_response(application_hash)
  ApplicantResponses->>TransactionStore: find_vlp_verification_response(applicant_id)  -- returns array
  TransactionStore-->>ApplicantResponses: [tx1, tx2, ...] 
  loop each tx (ascending created_at)
    ApplicantResponses->>Processor: process_vlp_verification_response(tx)
    alt success
      Processor-->>ApplicantResponses: application_hash (updated)
    else failure
      Processor-->>ApplicantResponses: Failure (early return)
    end
  end
  ApplicantResponses-->>Caller: final application_hash
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant SSAApplicantRequest
  participant VLPService

  Caller->>SSAApplicantRequest: call(params) -> save SSA response
  SSAApplicantRequest->>SSAApplicantRequest: can_trigger_vlp_for_citizenship?(ssa_response)
  alt SSN verified && Citizenship not verified
    SSAApplicantRequest->>VLPService: Fdsh::SsaVlp::Rj3::Vlp::ApplicantRequest.call(params)
    VLPService-->>SSAApplicantRequest: vlp_response
  else
    SSAApplicantRequest-->>Caller: Success(true) (no VLP triggered)
  end
  SSAApplicantRequest-->>Caller: result
Loading
sequenceDiagram
  autonumber
  participant Caller
  participant ResponseProcessorUtils

  Caller->>ResponseProcessorUtils: build_request_result(@response)
  Note over ResponseProcessorUtils: raw_payload serialized via toJSON
  ResponseProcessorUtils-->>Caller: {result, code, code_description, source, raw_payload(JSON)}
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

cr-120+

Suggested reviewers

  • saipraveen18
  • vkghub
  • kristinmerbach

Poem

Thump-thump, I hop through JSON dew,
I tuck each payload safe and true.
I follow transactions, one by one,
nudge a key, call VLP, get it done. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title is vague, misspells “response,” and only refers to JSON conversion in a single utility, ignoring the broader VLP integration and evidence processing changes introduced across multiple modules. Revise the title to accurately and concisely reflect the primary changes, such as standardizing JSON serialization for all raw_payload responses and adding comprehensive VLP verification flow support.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run `@coderabbitai generate docstrings` to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit's high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch clickup_868fubywe

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 231d04f and 19f1cf7.

📒 Files selected for processing (2)
  • app/operations/fdsh/ssa_vlp/rj3/response_processor_utils.rb (1 hunks)
  • app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-07-14T19:06:48.270Z
Learnt from: ymhari
PR: ideacrew/fdsh_gateway#268
File: app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb:99-119
Timestamp: 2025-07-14T19:06:48.270Z
Learning: In `app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb`, the evidence appending approach in `update_evidences_with_failure` and `update_evidences_with_results` methods is intentionally designed to accumulate evidence entries rather than replace them, as confirmed by ymhari.

Applied to files:

  • app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb
📚 Learning: 2025-07-16T13:34:53.451Z
Learnt from: ymhari
PR: ideacrew/fdsh_gateway#268
File: app/operations/fdsh/ssa_vlp/rj3/vlp/process_verification_response.rb:129-138
Timestamp: 2025-07-16T13:34:53.451Z
Learning: In `app/operations/fdsh/ssa_vlp/rj3/vlp/process_verification_response.rb`, the evidence appending approach in `update_evidences_with_failure` and `update_evidences_with_results` methods is intentionally designed to accumulate evidence entries rather than replace them, as confirmed by ymhari.

Applied to files:

  • app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb
🧬 Code graph analysis (1)
app/operations/fdsh/ssa_vlp/rj3/response_processor_utils.rb (2)
app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb (2)
  • service_name (31-33)
  • response_metadata (55-57)
app/operations/fdsh/ssa_vlp/rj3/vlp/process_verification_response.rb (2)
  • service_name (33-35)
  • response_metadata (71-73)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build-and-upload-image
  • GitHub Check: rspec
  • GitHub Check: docsite
🔇 Additional comments (2)
app/operations/fdsh/ssa_vlp/rj3/response_processor_utils.rb (1)

109-109: Good documentation improvement.

The inline comment clarifies the purpose of the source field, improving code maintainability.

app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb (1)

72-81: Confirm removal of immigration_evidence in specific branches.

The ssn_verified && !citizenship_verified and !ssn_verified branches in calculate_evidence_states no longer include immigration_evidence, even though it’s listed in EVIDENCE_KEYS and returned in other branches. Omitting the key will skip updating immigration evidence in these cases. Should this be intentional? Restore immigration_evidence or adjust EVIDENCE_KEYS/branches for consistency?

kristinmerbach
kristinmerbach previously approved these changes Oct 2, 2025
Copy link
Copy Markdown
Contributor

@kristinmerbach kristinmerbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kristinmerbach kristinmerbach enabled auto-merge (squash) October 2, 2025 19:11
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19f1cf7 and 5efd894.

📒 Files selected for processing (6)
  • app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (2 hunks)
  • app/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request.rb (2 hunks)
  • app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb (1 hunks)
  • spec/operations/fdsh/ssa_vlp/rj3/handle_verification_request_spec.rb (1 hunks)
  • spec/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request_spec.rb (3 hunks)
  • spec/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response_spec.rb (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response.rb
🧰 Additional context used
🧬 Code graph analysis (3)
app/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request.rb (1)
app/operations/fdsh/ssa_vlp/rj3/vlp/applicant_request.rb (1)
  • call (15-31)
spec/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request_spec.rb (3)
app/operations/fdsh/ssa_vlp/rj3/vlp/process_verification_response.rb (1)
  • call (18-29)
app/operations/fdsh/ssa_vlp/rj3/handle_verification_request.rb (1)
  • call (13-22)
app/operations/fdsh/ssa_vlp/rj3/vlp/applicant_request.rb (1)
  • call (15-31)
app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (1)
app/models/transmittable/transmission.rb (1)
  • transactions (127-129)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-and-upload-image
  • GitHub Check: rspec
🔇 Additional comments (10)
spec/operations/fdsh/ssa_vlp/rj3/ssa/process_verification_response_spec.rb (2)

146-146: LGTM: JSON payload standardization.

The test expectations correctly validate that raw_payload is now stored as JSON string format (ssa_response_payload.to_json) rather than raw Ruby objects. This aligns with the PR objective to standardize stored raw payloads to JSON.

Also applies to: 151-151


203-203: LGTM: Consistent JSON serialization in test assertions.

The remaining test cases consistently validate JSON-serialized payloads, ensuring comprehensive coverage of the new JSON storage approach across different verification scenarios.

Also applies to: 242-242, 247-247

app/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request.rb (3)

103-106: LGTM: Conditional VLP triggering logic.

The method correctly implements conditional VLP triggering based on the citizenship verification status. The early return pattern is appropriate when VLP processing is not needed.


108-118: LGTM: Robust citizenship verification check with appropriate error handling.

The method correctly:

  • Guards against missing response data (line 109)
  • Navigates the nested JSON structure matching the actual response format (lines 111-113)
  • Implements the correct conditional logic: trigger VLP only when SSN is verified but citizenship is not (line 114)
  • Provides fail-safe error handling by returning false on any exception (lines 116-117)

The field names (ssnVerificationIndicator, personUSCitizenIndicator) align with the mock response structure used in tests.


26-26: LGTM: VLP integration point correctly positioned.

The VLP triggering call is appropriately placed after the SSA response payload is saved, ensuring the VLP flow has access to the necessary SSA verification results.

spec/operations/fdsh/ssa_vlp/rj3/ssa/applicant_request_spec.rb (3)

68-71: LGTM: Test data correctly configured to trigger VLP flow.

The mock SSA response is configured with ssnVerificationIndicator: true and personUSCitizenIndicator: false, which correctly triggers the VLP verification flow as per the implementation logic in can_trigger_vlp_for_citizenship?.


79-86: LGTM: VLP test fixtures properly configured.

The VLP mock setup correctly references the XML response fixture and creates appropriate mock instances for the VLP verification flow, maintaining consistency with the existing SSA mock pattern.


92-93: LGTM: VLP integration thoroughly tested.

The test correctly:

  • Mocks the VLP verification request/response flow (lines 92-93)
  • Verifies the VLP response transaction is created and succeeded (lines 151-162)
  • Validates that the response payload is persisted

This ensures end-to-end coverage of the new VLP triggering functionality.

Also applies to: 151-162

spec/operations/fdsh/ssa_vlp/rj3/handle_verification_request_spec.rb (1)

103-106: LGTM: Mock SSA response enriched to align with VLP integration.

The mock response has been enhanced with:

  • ssnVerificationIndicator changed from false to true, enabling the SSN verification path
  • Additional fields (deathConfirmationCode, personUSCitizenIndicator, personIncarcerationInformationIndicator) to match the actual SSA response structure

This configuration (ssnVerificationIndicator: true, personUSCitizenIndicator: false) correctly triggers the VLP verification flow, consistent with the test scenarios in other spec files.

app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (1)

80-80: LGTM: Method signature correctly updated for multi-transaction support.

The method now returns all matching VLP verification response transactions instead of just the last one, enabling the processing of multiple VLP responses per applicant as implemented in update_dhs_verification_response.

@ymhari ymhari requested a review from kristinmerbach October 2, 2025 21:26
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e49f98c and f59b452.

📒 Files selected for processing (1)
  • app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-16T13:34:53.451Z
Learnt from: ymhari
PR: ideacrew/fdsh_gateway#268
File: app/operations/fdsh/ssa_vlp/rj3/vlp/process_verification_response.rb:129-138
Timestamp: 2025-07-16T13:34:53.451Z
Learning: In `app/operations/fdsh/ssa_vlp/rj3/vlp/process_verification_response.rb`, the evidence appending approach in `update_evidences_with_failure` and `update_evidences_with_results` methods is intentionally designed to accumulate evidence entries rather than replace them, as confirmed by ymhari.

Applied to files:

  • app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb
🧬 Code graph analysis (1)
app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (1)
app/models/transmittable/transmission.rb (1)
  • transactions (127-129)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-and-upload-image
  • GitHub Check: rspec

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (2)

50-57: Good fix on Mongoid ordering; remove redundant nil-check and guard against duplicate determined applicants.

  • order_by is correct; resolves the prior NoMethodError.
  • response_transactions is always truthy (Mongoid::Criteria), so the nil-check never skips. Remove it.
  • Iterating multiple transactions can append the same hbx_id multiple times; dedupe.

Apply minimal cleanup:

-            response_transactions = find_vlp_response_transaction(applicant)
-            next unless response_transactions
-            response_transactions.order_by(created_at: :asc).each do |response_transaction|
+            response_transactions = find_vlp_response_transaction(applicant)
+            response_transactions.order_by(created_at: :asc).each do |response_transaction|

Optional: dedupe determined applicants (outside this hunk). One simple approach:

def record_determined_applicant(response_transaction, applicant, key)
  return unless response_transaction.process_status&.latest_state == :succeeded
  hbx_id = applicant.hbx_id
  return unless hbx_id
  @determined_applicants[key] << hbx_id unless @determined_applicants[key].include?(hbx_id)
end

80-81: Return an ordered collection and rename to plural for clarity.

Encapsulate ordering in the finder and reflect that it returns a collection.

-def find_vlp_response_transaction(applicant)
-  applicant.transactions.where(key: :vlp_verification_response)
+def find_vlp_response_transactions(applicant)
+  applicant.transactions.where(key: :vlp_verification_response).order_by(created_at: :asc)

Then update call site to:

response_transactions = find_vlp_response_transactions(applicant)
response_transactions.each do |response_transaction|
  ...
end
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f59b452 and 2ba1352.

📒 Files selected for processing (1)
  • app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/operations/fdsh/ssa_vlp/rj3/process_applicant_responses.rb (1)
app/models/transmittable/transmission.rb (1)
  • transactions (127-129)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-and-upload-image
  • GitHub Check: rspec

@ymhari ymhari added the cr-120+ PRs associated with the CR-120+, QHP Application, or Eligibility 3.0 label Oct 3, 2025
Copy link
Copy Markdown
Contributor

@saipraveen18 saipraveen18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍

@ymhari ymhari removed the request for review from vkghub October 3, 2025 16:15
@ymhari ymhari disabled auto-merge October 3, 2025 16:16
@ymhari ymhari enabled auto-merge (squash) October 3, 2025 16:16
@ymhari ymhari disabled auto-merge October 3, 2025 17:21
@ymhari ymhari enabled auto-merge (squash) October 3, 2025 17:21
@polographer polographer disabled auto-merge October 3, 2025 17:43
@polographer polographer merged commit 4135adb into trunk Oct 3, 2025
10 checks passed
@polographer polographer deleted the clickup_868fubywe branch October 3, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cr-120+ PRs associated with the CR-120+, QHP Application, or Eligibility 3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants