22
33class Apicast ::ProxyRulesSourceTest < ActiveSupport ::TestCase
44
5+ def setup
6+ @proxy = FactoryBot . create ( :proxy )
7+ backend_api_config = FactoryBot . create ( :backend_api_config , service : @proxy . service , path : '/test/path/' )
8+ @backend_api = backend_api_config . backend_api
9+ @metric = FactoryBot . create ( :metric , owner : backend_api , description : 'My awesome metric' , system_name : 'my-metric' )
10+ end
11+
12+ attr_reader :backend_api , :metric , :proxy
13+
514 def test_to_hash
6- proxy = FactoryBot . create ( :proxy )
715 rule_1 = FactoryBot . create ( :proxy_rule , proxy : proxy , last : true )
816 rule_2 = FactoryBot . create ( :proxy_rule , proxy : proxy )
917
10- backend_api_config = FactoryBot . create ( :backend_api_config , service : proxy . service , path : '/test/path/' )
11- backend_api = backend_api_config . backend_api
12- metric = FactoryBot . create ( :metric , owner : backend_api , description : 'My awesome metric' , system_name : 'my-metric' )
1318 rule_3 = FactoryBot . create ( :proxy_rule , owner : backend_api , pattern : '/create' )
1419 rule_4 = FactoryBot . create ( :proxy_rule , owner : backend_api , pattern : '/delete' , metric : metric )
1520 rule_5 = FactoryBot . create ( :proxy_rule , owner : backend_api , pattern : '/list?filter=a' , metric : metric )
@@ -33,6 +38,21 @@ def test_to_hash
3338 assert_equal [ 'username' ] , rule_hash_6 [ 'parameters' ]
3439 end
3540
41+ test 'backend api mapping rules are ordered by position' do
42+ proxy . proxy_rules . destroy_all
43+
44+ assert backend_api . proxy_rules . empty?
45+
46+ FactoryBot . create ( :proxy_rule , owner : backend_api , pattern : '/two' )
47+ rule_3 = FactoryBot . create ( :proxy_rule , owner : backend_api , pattern : '/three' )
48+ rule_1 = FactoryBot . create ( :proxy_rule , owner : backend_api , pattern : '/one' )
49+ rule_1 . move_to_top
50+ rule_3 . move_to_bottom
51+
52+ source = Apicast ::ProxyRulesSource . new ( proxy ) . to_hash
53+ assert_equal %w[ /test/path/one /test/path/two /test/path/three ] , source . map { |rule | rule [ 'pattern' ] }
54+ end
55+
3656 private
3757
3858 def find_by_id_in_hash ( id , hash )
0 commit comments