#!/usr/bin/env nu # Pricing and caching integration tests def test-result [name: string, result: bool] { if $result { print $"✓ ($name)" } else { print $"✗ ($name)" } $result } def load-mocks [] { open tests/mocks/mock_api_responses.json } def test-pricing-data-available [] { let mocks = (load-mocks) let pricing = $mocks.pricing_data test-result "Pricing: Data available" (($pricing | length) > 0) } def test-pricing-structure [] { let mocks = (load-mocks) let pricing = ($mocks.pricing_data | get -o 0) let t1 = (test-result "Pricing: Has instance_type" ($pricing | get -o instance_type | is-not-empty)) let t2 = (test-result "Pricing: Has hourly_rate" ($pricing | get -o hourly_rate | is-not-empty)) let t3 = (test-result "Pricing: Has monthly_estimate" ($pricing | get -o monthly_estimate | is-not-empty)) $t1 and $t2 and $t3 } def test-pricing-rates [] { let mocks = (load-mocks) let pricing = $mocks.pricing_data let small = ($pricing | where {|p| $p.instance_type == "small"} | get -o 0) let medium = ($pricing | where {|p| $p.instance_type == "medium"} | get -o 0) let t1 = (test-result "Pricing: Small has rate" ($small | get -o hourly_rate | is-not-empty)) let t2 = (test-result "Pricing: Medium has rate" ($medium | get -o hourly_rate | is-not-empty)) $t1 and $t2 } def test-pricing-scaling [] { let mocks = (load-mocks) let small = ($mocks.pricing_data | where {|p| $p.instance_type == "small"} | get -o 0 | get -o hourly_rate) let large = ($mocks.pricing_data | where {|p| $p.instance_type == "large"} | get -o 0 | get -o hourly_rate) test-result "Pricing: Larger instances cost more" ($large > $small) } def test-monthly-estimate [] { let mocks = (load-mocks) let small = ($mocks.pricing_data | where {|p| $p.instance_type == "small"} | get -o 0) let hourly = $small.hourly_rate let monthly = $small.monthly_estimate let estimated = ($hourly * 730) test-result "Pricing: Monthly estimate calculated" ($monthly > 0) } def test-pricing-completeness [] { let mocks = (load-mocks) let pricing = $mocks.pricing_data let all_entries = ($pricing | length) let has_type = ($pricing | where {|p| ($p | get -o instance_type | is-not-empty)} | length) test-result "Pricing: All entries complete" ($all_entries == $has_type) } def test-volume-pricing [] { let mocks = (load-mocks) let volumes = $mocks.volumes_list.volumes let has_type = (($volumes | where {|v| ($v | get -o type | is-not-empty)} | length) > 0) let has_size = (($volumes | where {|v| ($v | get -o size | is-not-empty)} | length) > 0) let t1 = (test-result "Pricing: Volumes have type" $has_type) let t2 = (test-result "Pricing: Volumes have size" $has_size) $t1 and $t2 } def test-volume-cost [] { let mocks = (load-mocks) let volumes = $mocks.volumes_list.volumes let gp_volumes = ($volumes | where {|v| $v.type == "standard"}) test-result "Pricing: Standard volumes available" (($gp_volumes | length) > 0) } def test-cache-data-freshness [] { let mocks = (load-mocks) let pricing1 = (load-mocks) let same = ($mocks.pricing_data | length) == ($pricing1.pricing_data | length) test-result "Pricing: Cache returns same data" $same } def test-pricing-tier-variety [] { let mocks = (load-mocks) let pricing = $mocks.pricing_data let types = ($pricing | each {|p| $p.instance_type}) let unique = ($types | uniq | length) test-result "Pricing: Multiple pricing tiers" ($unique > 1) } def test-volume-type-variety [] { let mocks = (load-mocks) let volumes = $mocks.volumes_list.volumes let types = ($volumes | each {|v| $v.type}) let unique = ($types | uniq | length) test-result "Pricing: Multiple volume types" ($unique > 0) } def main [] { print "=== Pricing and Cache Integration Tests ===" print "" let results = [ (test-pricing-data-available), (test-pricing-structure), (test-pricing-rates), (test-pricing-scaling), (test-monthly-estimate), (test-pricing-completeness), (test-volume-pricing), (test-volume-cost), (test-cache-data-freshness), (test-pricing-tier-variety), (test-volume-type-variety), (test-pricing-data-available) ] let passed = ($results | where {|it| $it == true} | length) let failed = ($results | where {|it| $it == false} | length) print "" print $"Test Results: ($passed) passed, ($failed) failed" { passed: $passed, failed: $failed, total: ($passed + $failed) } } main