diff --git a/integration/config_test.go b/integration/config_test.go index d146aceb3..6b0a0ef9c 100644 --- a/integration/config_test.go +++ b/integration/config_test.go @@ -188,3 +188,63 @@ func Test_SetConfigAPI(t *testing.T) { }) } } + +func Test_ResetConfigAPI(t *testing.T) { + assert := assert.New(t) + + type args struct { + name string + } + tests := []struct { + name string + args args + expectedStatus int + expectedError error + }{ + { + name: "Reset Config - Valid", + args: args{ + name: "region", + }, + expectedStatus: 200, + expectedError: nil, + }, + { + name: "Reset Config - Invalid", + args: args{ + name: "regiontest", + }, + expectedStatus: 500, + expectedError: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + client := &http.Client{ + Timeout: 3 * time.Second, + } + + requestDataPolicy := map[string]interface{}{} + + requestDataJSON, _ := json.Marshal(requestDataPolicy) + requestDataBody := bytes.NewReader(requestDataJSON) + request, err := http.NewRequest( + "POST", fmt.Sprintf("http://localhost:9090/api/v1/configs/%s/reset", tt.args.name), requestDataBody) + if err != nil { + log.Println(err) + return + } + request.Header.Add("Cookie", fmt.Sprintf("token=%s", token)) + request.Header.Add("Content-Type", "application/json") + response, err := client.Do(request) + if err != nil { + log.Println(err) + return + } + if response != nil { + assert.Equal(tt.expectedStatus, response.StatusCode, tt.name+" Failed") + } + }) + } +} diff --git a/portal-ui/src/screens/Console/NotificationEndpoints/CustomForms/ResetConfigurationModal.tsx b/portal-ui/src/screens/Console/NotificationEndpoints/CustomForms/ResetConfigurationModal.tsx index 282994ce6..8bf334e0d 100644 --- a/portal-ui/src/screens/Console/NotificationEndpoints/CustomForms/ResetConfigurationModal.tsx +++ b/portal-ui/src/screens/Console/NotificationEndpoints/CustomForms/ResetConfigurationModal.tsx @@ -57,7 +57,7 @@ const ResetConfigurationModal = ({ useEffect(() => { if (resetLoading) { api - .invoke("GET", `/api/v1/configs/${configurationName}/reset`) + .invoke("POST", `/api/v1/configs/${configurationName}/reset`) .then((res) => { setResetLoading(false); closeResetModalAndRefresh(true); diff --git a/restapi/embedded_spec.go b/restapi/embedded_spec.go index 1f9cee40d..612539982 100644 --- a/restapi/embedded_spec.go +++ b/restapi/embedded_spec.go @@ -2587,7 +2587,7 @@ func init() { } }, "/configs/{name}/reset": { - "get": { + "post": { "tags": [ "Configuration" ], @@ -9535,7 +9535,7 @@ func init() { } }, "/configs/{name}/reset": { - "get": { + "post": { "tags": [ "Configuration" ], diff --git a/restapi/operations/configuration/reset_config.go b/restapi/operations/configuration/reset_config.go index 36d41d1a1..ed7db78a4 100644 --- a/restapi/operations/configuration/reset_config.go +++ b/restapi/operations/configuration/reset_config.go @@ -48,7 +48,7 @@ func NewResetConfig(ctx *middleware.Context, handler ResetConfigHandler) *ResetC return &ResetConfig{Context: ctx, Handler: handler} } -/* ResetConfig swagger:route GET /configs/{name}/reset Configuration resetConfig +/* ResetConfig swagger:route POST /configs/{name}/reset Configuration resetConfig Configuration reset diff --git a/restapi/operations/console_api.go b/restapi/operations/console_api.go index 5bd1025ea..1f2c78cbb 100644 --- a/restapi/operations/console_api.go +++ b/restapi/operations/console_api.go @@ -1692,10 +1692,10 @@ func (o *ConsoleAPI) initHandlerCache() { o.handlers["DELETE"] = make(map[string]http.Handler) } o.handlers["DELETE"]["/user"] = user.NewRemoveUser(o.context, o.UserRemoveUserHandler) - if o.handlers["GET"] == nil { - o.handlers["GET"] = make(map[string]http.Handler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) } - o.handlers["GET"]["/configs/{name}/reset"] = configuration.NewResetConfig(o.context, o.ConfigurationResetConfigHandler) + o.handlers["POST"]["/configs/{name}/reset"] = configuration.NewResetConfig(o.context, o.ConfigurationResetConfigHandler) if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) } diff --git a/swagger-console.yml b/swagger-console.yml index 138671ba1..570f593eb 100644 --- a/swagger-console.yml +++ b/swagger-console.yml @@ -2168,7 +2168,7 @@ paths: - Configuration /configs/{name}/reset: - get: + post: summary: Configuration reset operationId: ResetConfig parameters: