Back to Repositories

Testing Exchange Rate Provider Missing Controller Integration in maybe-finance

This test suite validates the exchange rate provider missing functionality in the Maybe Finance application. It focuses on testing the controller actions for handling missing exchange rate provider issues and verifies the proper enqueuing of sync jobs after updates.

Test Coverage Overview

The test suite covers the core functionality of updating exchange rate provider issues through the controller endpoint.

Key areas tested include:
  • Authentication handling via user sign-in
  • Issue update functionality with synthetic API key
  • Job enqueuing verification
  • Proper redirect behavior after updates

Implementation Analysis

The testing approach utilizes ActionDispatch::IntegrationTest to simulate HTTP requests and verify controller behavior. The implementation leverages fixtures for test data setup and employs Rails’ built-in assertion methods to validate job enqueuing and redirects.

The test demonstrates proper use of controller testing patterns with setup blocks and params structure.

Technical Details

Testing tools and configuration:
  • Minitest framework with Rails integration
  • ActionDispatch for integration testing
  • Fixtures for test data management
  • ActiveJob assertions for background job verification
  • Rails authentication helpers for user context

Best Practices Demonstrated

The test exhibits several testing best practices including proper test isolation through setup blocks, focused test scenarios, and clear assertion patterns.

Notable practices include:
  • Clear test method naming
  • Proper authentication setup
  • Specific assertions for both job enqueuing and redirects
  • Efficient use of fixtures for test data

maybe-finance/maybe

test/controllers/issue/exchange_rate_provider_missings_controller_test.rb

            
require "test_helper"

class Issue::ExchangeRateProviderMissingsControllerTest < ActionDispatch::IntegrationTest
  setup do
    sign_in users(:family_admin)
    @issue = issues(:one)
  end

  test "should update issue" do
    patch issue_exchange_rate_provider_missing_url(@issue), params: {
      issue_exchange_rate_provider_missing: {
        synth_api_key: "1234"
      }
    }

    assert_enqueued_with job: SyncJob
    assert_redirected_to @issue.issuable
  end
end