@@ -1114,3 +1114,100 @@ func TestGetVirtualHostWithoutCluster_Success(t *testing.T) {
11141114
11151115 assert .Equal (t , expected , actual )
11161116}
1117+
1118+ func TestListLocationsLicenses (t * testing.T ) {
1119+ testCases := []struct {
1120+ name string
1121+ config config.Configuration
1122+ user model.User
1123+ buildStubs func (db * MockMongoDatabaseInterface )
1124+ checkResponse func (t * testing.T , res []string , err error )
1125+ }{
1126+ {
1127+ name : "Ok user" ,
1128+ config : config.Configuration {
1129+ APIService : config.APIService {
1130+ ScopeAsLocation : "loc1,loc2,loc3" ,
1131+ },
1132+ },
1133+ user : model.User {
1134+ Username : "user01" ,
1135+ },
1136+ buildStubs : func (db * MockMongoDatabaseInterface ) {
1137+ db .EXPECT ().GetUserLocations ("user01" ).
1138+ Return ([]string {"loc1" , "loc2" , "loc3" , "loc4" }, nil )
1139+ },
1140+
1141+ checkResponse : func (t * testing.T , res []string , err error ) {
1142+ assert .NoError (t , err )
1143+ assert .NotEmpty (t , res )
1144+ expectedResult := []string {"loc1,loc2,loc3" , "loc4" }
1145+ assert .Equal (t , expectedResult , res )
1146+ },
1147+ },
1148+ {
1149+ name : "Ok Admin" ,
1150+ config : config.Configuration {
1151+ APIService : config.APIService {
1152+ ScopeAsLocation : "loc1,loc2,loc3" ,
1153+ },
1154+ },
1155+ user : model.User {
1156+ Username : "user01" ,
1157+ Groups : []string {"admin" },
1158+ },
1159+ buildStubs : func (db * MockMongoDatabaseInterface ) {
1160+ db .EXPECT ().ListAllLocations ("" , "" , utils .MAX_TIME ).
1161+ Return ([]string {"loc1" , "loc2" , "loc3" , "loc4" }, nil )
1162+ },
1163+
1164+ checkResponse : func (t * testing.T , res []string , err error ) {
1165+ assert .NoError (t , err )
1166+ assert .NotEmpty (t , res )
1167+ expectedResult := []string {"loc1,loc2,loc3" , "loc4" }
1168+ assert .Equal (t , expectedResult , res )
1169+ },
1170+ },
1171+ {
1172+ name : "ScopeAsLocation empty" ,
1173+ config : config.Configuration {
1174+ APIService : config.APIService {
1175+ ScopeAsLocation : "" ,
1176+ },
1177+ },
1178+ user : model.User {
1179+ Username : "user01" ,
1180+ },
1181+ buildStubs : func (db * MockMongoDatabaseInterface ) {
1182+ db .EXPECT ().GetUserLocations ("user01" ).
1183+ Return ([]string {"loc1" , "loc2" , "loc3" , "loc4" }, nil )
1184+ },
1185+
1186+ checkResponse : func (t * testing.T , res []string , err error ) {
1187+ assert .NoError (t , err )
1188+ assert .NotEmpty (t , res )
1189+ expectedResult := []string {"loc1" , "loc2" , "loc3" , "loc4" }
1190+ assert .Equal (t , expectedResult , res )
1191+ },
1192+ },
1193+ }
1194+ for _ , tc := range testCases {
1195+ t .Run (tc .name , func (t * testing.T ) {
1196+
1197+ mockCtrl := gomock .NewController (t )
1198+ defer mockCtrl .Finish ()
1199+ db := NewMockMongoDatabaseInterface (mockCtrl )
1200+
1201+ as := APIService {
1202+ Database : db ,
1203+ Config : tc .config ,
1204+ }
1205+
1206+ tc .buildStubs (db )
1207+
1208+ res , err := as .ListLocationsLicenses (tc .user )
1209+
1210+ tc .checkResponse (t , res , err )
1211+ })
1212+ }
1213+ }
0 commit comments