Skip to content

EDI Test Order Generator

This document describes the rake tasks for generating and testing EDI orders across all partner integrations.

The EDI test order generator creates realistic test orders for all EDI partners using Faker to generate random but valid data. This is useful for:

  • Testing EDI order processing fixes
  • Verifying shipping cost calculations
  • Testing new EDI integrations
  • Load testing the system
  • Training and documentation

The generator supports 20 active EDI partner configurations:

Note: Only partners with active: true in their orchestrator configuration are included in the generator.

  • commercehub_thd_us - Home Depot US
  • commercehub_thd_ca - Home Depot Canada
  • commercehub_lowes_ca - Lowe’s Canada
  • commercehub_costco_ca - Costco Canada
  • amazon_seller_central_us - Amazon US
  • amazon_seller_central_ca - Amazon Canada
  • amazon_seller_central_fr - Amazon France
  • wayfair_us - Wayfair US
  • wayfair_ca - Wayfair Canada
  • mft_gateway_build_com - Build.com
  • mft_gateway_canadian_tire - Canadian Tire
  • mft_gateway_zoro_tools - Zoro Tools
  • leroymerlin_adeo - Leroy Merlin (France, Spain, Portugal, Italy)
  • bricodepot_es - Bricodepot Spain
  • bricodepot_pt - Bricodepot Portugal
  • bricomarche - Bricomarche
  • castorama - Castorama
  • leclerc - Leclerc
  • maxeda - Maxeda
  • houzz / houzz_us - Houzz

The following partners exist but are not active (active: false) and are excluded from the generator:

  • amazon_seller_central_uk - Amazon UK (inactive)
  • channel_engine_america - ChannelEngine Americas (archived)
  • channel_engine_europe - ChannelEngine Europe (archived)

The following partners are active in the system but don’t have generator implementations (not needed for testing):

  • European Amazon Seller Central: BE, DE, ES, IT, NL, PL, SE (FR is configured)
  • Amazon Vendor Central: amazon_vc_seller_api_wasn4, amazon_vc_seller_api_wat4d, amazon_vc_seller_api_watof, amazon_vc_seller_api_wax7v
  • MFT Gateway Amazon VC: mft_gateway_amazon_vc_edi_wasn4, mft_gateway_amazon_vc_edi_wat0f
  • Walmart: walmart_seller_us

Generate test EDI orders for one or all partners:

Terminal window
# Generate 1 order for a specific partner
bundle exec rake "edi:test_orders:generate[commercehub_thd_us,1]"
# Generate 5 orders for Wayfair US
bundle exec rake "edi:test_orders:generate[wayfair_us,5]"
# Generate 1 order for Amazon France
bundle exec rake "edi:test_orders:generate[amazon_seller_central_fr,1]"
# Generate 1 order for each partner (default count = 1)
bundle exec rake "edi:test_orders:generate[all]"
# Generate 3 orders for each partner
bundle exec rake "edi:test_orders:generate[all,3]"

Note: Orders are created in ready state but NOT automatically processed.

Process all test orders that are in ready state:

Terminal window
bundle exec rake edi:test_orders:process

This will:

  • Find all test ECLs in ‘ready’ state (identified by TEST or FAKE in the data)
  • Process each one
  • Create orders with line items, deliveries, and shipping costs
  • Report success or failures

Remove all test orders and related data:

Terminal window
bundle exec rake edi:test_orders:cleanup

This will:

  • Find all test ECLs (identified by file_name = 'TEST_EDI_ORDER_GENERATOR')
  • Delete associated orders (cascades to deliveries, line items, payments, etc.)
  • Delete the test ECLs

⚠️ Warning: This is destructive! It will permanently delete test orders.

Note: Only ECLs created by the test generator are marked with the special file_name field and will be cleaned up by this task. Manually created test ECLs will not be affected.

Terminal window
# 1. Generate test orders for all partners
bundle exec rake "edi:test_orders:generate[all,2]"
# 2. Process all test orders
bundle exec rake edi:test_orders:process
# 3. Verify results (optional - manual check in CRM)
# Visit the CRM and check that orders were created with deliveries
# 4. Clean up
bundle exec rake edi:test_orders:cleanup
Terminal window
# 1. Generate test order
bundle exec rake "edi:test_orders:generate[commercehub_thd_us,1]"
# 2. Get the ECL ID from output (e.g., "Created ECL #2898561")
# 3. Process it manually with more control
bundle exec rails runner 'ecl = EdiCommunicationLog.find(2898561); ecl.process'
# 4. Inspect the results
bundle exec rails runner '
ecl = EdiCommunicationLog.find(2898561)
order = ecl.orders.first
puts "Order: #{order.reference_number}"
puts "Deliveries: #{order.deliveries.count}"
puts "Shipping costs: #{order.deliveries.first&.shipping_costs&.count}"
'
# 5. Clean up when done
bundle exec rake edi:test_orders:cleanup

The test order generator creates realistic data using Faker:

  • Uses actual active catalog items from Home Depot USA catalog
  • Includes real SKUs, UPCs, and prices
  • Random quantity (currently fixed at 1)
  • Random US addresses with valid format
  • Faker-generated names
  • Valid US states and zip codes
  • Random phone numbers (10 digits)
  • Transaction IDs prefixed with “TEST-” for easy identification
  • PO numbers prefixed with “TEST”
  • Customer order numbers prefixed with “TESTCUST”
  • Unique IDs to prevent collisions
  • Standard ground shipping (UNSP_CG for Home Depot)
  • Ship dates set to tomorrow
  • Proper personPlace mappings in XML

After processing test orders, verify:

  • Order created successfully
  • Order has correct state (usually in_cr_hold)
  • Order has shipping method set
  • Delivery created (state: quoting)
  • Shipping costs calculated (check count > 0)
  • Line items created with correct prices
  • Payment created
  • No errors in logs
Terminal window
bundle exec rails runner '
ecl_id = ARGV[0] || EdiCommunicationLog.where("data LIKE ?", "%TEST%").where(state: "processed").last&.id
ecl = EdiCommunicationLog.find(ecl_id)
order = ecl.orders.first
delivery = order.deliveries.first
puts "\n=== Verification Report ==="
puts "ECL ##{ecl.id}: #{ecl.state}"
puts "Order ##{order.id}: #{order.reference_number} (#{order.state})"
puts "Shipping method: #{order.shipping_method}"
puts "Total: $#{order.total}"
puts "Delivery ##{delivery.id}: #{delivery.state}"
puts "Shipping costs: #{delivery.shipping_costs.count}"
puts "Top 3 costs:"
delivery.shipping_costs.limit(3).each do |sc|
puts " - #{sc.shipping_option.name}: $#{sc.cost}"
end
puts "✅ All checks passed!" if delivery.shipping_costs.any?
' 2898561

If test orders are created but have no deliveries:

  1. Check if order.retrieve_shipping_costs was called in the processor
  2. Verify the shipping address is valid
  3. Check logs for shipping cost calculation errors

If you get “Country must exist” or similar errors:

  • This indicates a mismatch in the XML personPlace references
  • The generator should handle this correctly, but if not, report it as a bug

If delivery exists but has no shipping costs:

  1. Check if the address is in a supported region
  2. Verify the item has valid dimensions/weight
  3. Check carrier service availability

⚠️ NEVER run test order generation in production!

Test orders are marked with TEST/FAKE identifiers, but they will still:

  • Create real order records
  • Reserve inventory
  • Send notifications
  • Potentially be processed for fulfillment

Always use test orders in development or staging environments only.

To add a new EDI partner to the generator:

  1. Add the partner to the PARTNERS hash in lib/tasks/edi_test_orders.rake
  2. Create a generate_PARTNER method
  3. Follow the existing pattern for data structure
  4. Test thoroughly before committing

The find_valid_catalog_item method selects random active items from the Home Depot USA catalog. To use different items:

  • Modify the catalog selection
  • Update product filtering criteria
  • Adjust quantity logic as needed
  • XML partners (CommerceHub): Use proper XML structure with personPlace mappings
  • JSON partners (All others): Use nested JSON structures matching their API specs
  • All partners should use realistic data that matches their actual message formats
  • EDI Integration Overview
  • Shipping Cost Calculation Fix
  • Database Schema

For issues with the test order generator:

  1. Check the rake task output for error messages
  2. Review the generated ECL data in the database
  3. Check application logs for processing errors
  4. Verify all EDI processors have the order.retrieve_shipping_costs fix applied
  • Initial release
  • Support for all 8 EDI partners
  • Faker-based data generation
  • Cleanup and processing tasks added