#!/usr/bin/env elixir # Test the complete MessageHandler with Mercury Device data Mix.install([ {:iso_8583, "~> 0.1.5"} ]) Code.require_file("lib/da_product_app/switch/message_handler.ex") defmodule MessageHandlerTest do alias DaProductApp.Switch.MessageHandler def test_mercury_device_data do IO.puts("=== Testing Mercury Device Message Handler ===") # Your actual Mercury device data (with length header) hex_data = "001A600078200004007030000000000004000000" binary_data = Base.decode16!(hex_data) IO.puts("Input hex data: #{hex_data}") IO.puts("Input binary data: #{inspect(binary_data)}") IO.puts("Input size: #{byte_size(binary_data)} bytes") # Test parsing case MessageHandler.parse(binary_data) do {:ok, parsed_message, remaining} -> IO.puts("\n✅ Successfully parsed message!") IO.puts("Parsed message: #{inspect(parsed_message, limit: :infinity)}") IO.puts("Remaining data: #{inspect(remaining)}") # Test encoding the response IO.puts("\n=== Testing Response Encoding ===") response = MessageHandler.create_response(parsed_message, "00", %{}) case MessageHandler.encode(response) do {:ok, encoded} -> IO.puts("✅ Successfully encoded response!") IO.puts("Encoded response hex: #{Base.encode16(encoded)}") IO.puts("Encoded response size: #{byte_size(encoded)} bytes") {:error, reason} -> IO.puts("❌ Encoding failed: #{inspect(reason)}") end {:incomplete, data} -> IO.puts("⚠️ Incomplete data: #{inspect(data)}") {:error, reason} -> IO.puts("❌ Parsing failed: #{inspect(reason)}") end end def test_tpdu_configuration do IO.puts("\n=== TPDU Configuration Test ===") MessageHandler.log_supported_tpdus() # Test TPDU detection directly tpdu_data = <<0x60, 0x00, 0x78, 0x20, 0x00>> tpdu_info = MessageHandler.parse_tpdu_info(tpdu_data) IO.puts("TPDU Info: #{inspect(tpdu_info)}") end end # Run the tests MessageHandlerTest.test_mercury_device_data() MessageHandlerTest.test_tpdu_configuration()