#!/usr/bin/env elixir # Test script to verify the routing fix Mix.install([]) # Load the project System.put_env("MIX_ENV", "dev") Code.require_file("mix.exs") # Compile and load the application Mix.Task.run("compile") # Now test the routing processor defmodule RoutingTest do require Logger def test_ysp_routing do Logger.configure(level: :debug) # Simulate the ISO message from your log iso_message = %DaProductApp.MercuryISO8583.Packagers.ISOMsg{ mti: "0200", fields: %{ 2 => "4854980600736740", 3 => "000000", 4 => "000000003500", 11 => "000344", 14 => "3105", 22 => "051", 23 => "000", 24 => "782", # This should route to YSP 25 => "00", 35 => "4854980600736740=31052060011790", 41 => "12345671", 42 => "123456789012345", 49 => "784", 52 => <<0x8E, 0x88, 0xD0, 0x9E, 0x13, 0xF2, 0x7C, 0x0D>>, 55 => <<0x9F, 0x27, 0x01, 0x40>>, # Simplified 62 => "000001", 63 => "12345678901234400072", 64 => "4Vx4Vx" } } # Test configuration matching what's in processor_pipelines.exs config = %{ "routing_mode" => "field_based_routing", "field_routes" => %{ "24" => %{ "782" => "ysp_plain" } }, "bin_routes" => %{ "4" => "visa_network" }, "default_route" => "generic_processor" } # Create minimal channel context channel_context = %{name: "test_channel"} # Call the routing processor case DaProductApp.MercuryISO8583.Processors.RoutingProcessor.process(iso_message, channel_context, config) do {:ok, updated_message, metadata} -> Logger.info("✅ Routing successful!") Logger.info("Routing metadata: #{inspect(metadata)}") # Check if routed to YSP case metadata[:routing_result] do {:ok, "ysp_plain", routing_info} -> Logger.info("✅ SUCCESS: Message routed to YSP (ysp_plain)") Logger.info("Routing info: #{inspect(routing_info)}") :success {:ok, network_id, routing_info} -> Logger.error("❌ FAILURE: Message routed to #{network_id} instead of ysp_plain") Logger.error("Routing info: #{inspect(routing_info)}") :failure error -> Logger.error("❌ ROUTING ERROR: #{inspect(error)}") :error end {:error, reason} -> Logger.error("❌ Processing failed: #{inspect(reason)}") :error end end end # Run the test case RoutingTest.test_ysp_routing() do :success -> IO.puts("\n🎉 Test PASSED - Routing fix works!") System.halt(0) :failure -> IO.puts("\n❌ Test FAILED - Still routing to wrong network") System.halt(1) :error -> IO.puts("\n💥 Test ERROR - Something went wrong") System.halt(2) end