import { expect } from "chai" ; import { roleMatchesRole , RoleName } from "../../../src/entities/Role" ; describe ( "Role entity function roleMatchesRole" , ( ) => { describe ( "matches an input role to a target role" , ( ) => { const testCases = [ [ "root" , [ RoleName . Root ] , true ] , [ "app-manager:appName" , [ RoleName . AppManager , "appName" ] , true ] , [ "app-manager:*" , [ RoleName . AppManager , "appName" ] , true ] , [ "app-manager:app*" , [ RoleName . AppManager , "appName" ] , true ] , [ "app-manager:*Name" , [ RoleName . AppManager , "appName" ] , true ] , [ "app-manager:different-appName" , [ RoleName . AppManager , "appName" ] , false , ] , [ "entrypoint-manager:example.com/" , [ RoleName . EntrypointManager , "example.com/" ] , true , ] , [ "entrypoint-manager:sub.example.com/" , [ RoleName . EntrypointManager , "example.com/" ] , false , ] , [ "bundle-manager:bundleName" , [ RoleName . BundleManager , "bundleName" ] , true , ] , [ "bundle-manager:*" , [ RoleName . BundleManager , "bundleName" ] , true ] , [ "bundle-manager:bundle*" , [ RoleName . BundleManager , "bundleName" ] , true , ] , [ "bundle-manager:*Name" , [ RoleName . BundleManager , "bundleName" ] , true , ] , [ "bundle-manager:different-bundleName" , [ RoleName . BundleManager , "bundleName" ] , false , ] , ] ; testCases . forEach ( ( [ inputRole , targetRole , expectedResult ] ) => { const matchesOrNot = expectedResult ? "matches" : "doesn't match" ; it ( `case: ${ inputRole } ${ matchesOrNot } ${ targetRole }` , ( ) => { expect ( roleMatchesRole ( inputRole , targetRole ) ) . to . equal ( expectedResult ) ; } ) ; } ) ; } ) ; } ) ;