@@ -529,3 +529,59 @@ func (suite *TestSuiteStandard) TestMatchRulesV3Delete() {
529529 })
530530 }
531531}
532+
533+ // TestMatchRulesV3GetSorted verifies that Match Rules are sorted as expected.
534+ func (suite * TestSuiteStandard ) TestMatchRulesV3GetSorted () {
535+ b := suite .createTestBudget (models.BudgetCreate {})
536+ a := suite .createTestAccount (models.AccountCreate {BudgetID : b .Data .ID , Name : "TestMatchRulesV3GetFilter 1" })
537+
538+ m1 := suite .createTestMatchRuleV3 (suite .T (), models.MatchRuleCreate {
539+ Priority : 1 ,
540+ Match : "Testing A Match*" ,
541+ AccountID : a .Data .ID ,
542+ })
543+
544+ m2 := suite .createTestMatchRuleV3 (suite .T (), models.MatchRuleCreate {
545+ Priority : 2 ,
546+ Match : "*Match the Second Account" ,
547+ AccountID : a .Data .ID ,
548+ })
549+
550+ m3 := suite .createTestMatchRuleV3 (suite .T (), models.MatchRuleCreate {
551+ Priority : 1 ,
552+ Match : "Exact match" ,
553+ AccountID : a .Data .ID ,
554+ })
555+
556+ m4 := suite .createTestMatchRuleV3 (suite .T (), models.MatchRuleCreate {
557+ Priority : 3 ,
558+ Match : "Coffee Shop*" ,
559+ AccountID : a .Data .ID ,
560+ })
561+
562+ m5 := suite .createTestMatchRuleV3 (suite .T (), models.MatchRuleCreate {
563+ Priority : 3 ,
564+ Match : "Coffee Shop" ,
565+ AccountID : a .Data .ID ,
566+ })
567+
568+ var re controllers.MatchRuleListResponseV3
569+ r := test .Request (suite .controller , suite .T (), http .MethodGet , "/v3/match-rules" , "" )
570+ assertHTTPStatus (suite .T (), & r , http .StatusOK )
571+ suite .decodeResponse (& r , & re )
572+
573+ // Lowest priority, alphabetically first
574+ assert .Equal (suite .T (), * m3 .Data , re .Data [0 ])
575+
576+ // Lowest priority, alphabetically second
577+ assert .Equal (suite .T (), * m1 .Data , re .Data [1 ])
578+
579+ // Higher priority
580+ assert .Equal (suite .T (), * m2 .Data , re .Data [2 ])
581+
582+ // Highest priority, alphabetically first
583+ assert .Equal (suite .T (), * m5 .Data , re .Data [3 ])
584+
585+ // Highest priority, alphabetically second
586+ assert .Equal (suite .T (), * m4 .Data , re .Data [4 ])
587+ }
0 commit comments