Integration tests to SchedulerHandler.AddRooms
@@ -320,3 +320,61 @@ func TestCreateScheduler(t *testing.T) {
require.Equal(t, "error creating scheduler scheduler: name already exists", body["message"])
})
}
+
+
+func TestAddRooms(t *testing.T) {
+ t.Run("with success", func(t *testing.T) {
+
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ schedulerStorage := schedulerStorageMock.NewMockSchedulerStorage(mockCtrl)
+ operationFlow := opflow.NewMockOperationFlow(mockCtrl)
+ operationStorage := opstorage.NewMockOperationStorage(mockCtrl)
+ operationManager := operation_manager.New(operationFlow, operationStorage, operations.NewDefinitionConstructors())
+ schedulerManager := scheduler_manager.NewSchedulerManager(schedulerStorage, operationManager)
+
+ operationStorage.EXPECT().CreateOperation(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
+ operationFlow.EXPECT().InsertOperationID(gomock.Any(), "scheduler-name-1", gomock.Any()).Return(nil)
+ schedulerStorage.EXPECT().GetScheduler(gomock.Any(), "scheduler-name-1").Return(nil, nil)
+
+ mux := runtime.NewServeMux()
+ err := api.RegisterSchedulersServiceHandlerServer(context.Background(), mux, ProvideSchedulersHandler(schedulerManager))
+ require.NoError(t, err)
+
+ req, err := http.NewRequest(http.MethodPost, "/schedulers/scheduler-name-1/add-rooms", bytes.NewReader([]byte("{\"amount\": 10}")))
+ require.NoError(t, err)
+
+ rr := httptest.NewRecorder()
+ mux.ServeHTTP(rr, req)
+
+ require.Equal(t, 200, rr.Code)
+ bodyString := rr.Body.String()
+ var body map[string]interface{}
+ err = json.Unmarshal([]byte(bodyString), &body)
+ require.NoError(t, err)
+
+ require.NotEmpty(t, body["operationId"])
+ })
+
+ t.Run("fails when scheduler does not exists", func(t *testing.T) {
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ schedulerStorage := schedulerStorageMock.NewMockSchedulerStorage(mockCtrl)
+ schedulerManager := scheduler_manager.NewSchedulerManager(schedulerStorage, nil)
+
+ schedulerStorage.EXPECT().GetScheduler(gomock.Any(), "scheduler-name-1").Return(nil, errors.NewErrNotFound("err"))
+
+ mux := runtime.NewServeMux()
+ err := api.RegisterSchedulersServiceHandlerServer(context.Background(), mux, ProvideSchedulersHandler(schedulerManager))
+ require.NoError(t, err)
+
+ req, err := http.NewRequest(http.MethodPost, "/schedulers/scheduler-name-1/add-rooms", bytes.NewReader([]byte("{\"amount\": 10}")))
+ require.NoError(t, err)
+
+ rr := httptest.NewRecorder()
+ mux.ServeHTTP(rr, req)
+
+ require.Equal(t, 404, rr.Code)
+ require.Contains(t, rr.Body.String(), "No scheduler found to add rooms on it: err")
+ })
+}
