Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cli/cmd/enterpriseportal_status_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func (r *runners) InitEnterprisePortalStatusUpdateCmd(parent *cobra.Command) *co
Long: `Update the current status of the Enterprise Portal for the specified application.

This command allows you to change the status of the Enterprise Portal associated
with the current application. You can use this to activate, deactivate, or set
any other valid status for the Enterprise Portal.
with the current application. Valid statuses are: active, inactive, pending.

If no application is specified, the command will use the default application
set in your configuration.
Expand All @@ -44,7 +43,7 @@ replicated enterprise-portal status update --status active --output table`,
SilenceUsage: true,
}
parent.AddCommand(cmd)
cmd.Flags().StringVar(&opts.status, "status", "", "The status to set for the enterprise portal")
cmd.Flags().StringVar(&opts.status, "status", "", "The status to set for the enterprise portal (active|inactive|pending)")
cmd.Flags().StringVarP(&outputFormat, "output", "o", "table", "The output format to use. One of: json|table")

cmd.MarkFlagRequired("status")
Expand Down
10 changes: 9 additions & 1 deletion pkg/kotsclient/enterprise-portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ func (c *VendorV3Client) GetEnterprisePortalStatus(appID string) (string, error)
return response.Status, nil
}

type UpdateEnterprisePortalStatusRequest struct {
Status string `json:"status"`
}

func (c *VendorV3Client) UpdateEnterprisePortalStatus(appID string, status string) (string, error) {
var response = GetEnterprisePortalStatusResponse{}

err := c.DoJSON(context.TODO(), "PUT", fmt.Sprintf("/v3/app/%s/enterprise-portal/status", appID), http.StatusOK, status, &response)
req := UpdateEnterprisePortalStatusRequest{
Status: status,
}

err := c.DoJSON(context.TODO(), "PUT", fmt.Sprintf("/v3/app/%s/enterprise-portal/status", appID), http.StatusOK, req, &response)
if err != nil {
return "", errors.Wrap(err, "update enterprise portal status")
}
Expand Down
76 changes: 76 additions & 0 deletions pkg/kotsclient/enterprise-portal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package kotsclient

import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"github.com/replicatedhq/replicated/pkg/platformclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestEnterprisePortalClient(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "test-token", r.Header.Get("Authorization"))

switch {
case r.Method == http.MethodGet && r.URL.Path == "/v3/app/test-app/enterprise-portal/status":
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"status": "active",
})
case r.Method == http.MethodPut && r.URL.Path == "/v3/app/test-app/enterprise-portal/status":
var body UpdateEnterprisePortalStatusRequest
assert.NoError(t, json.NewDecoder(r.Body).Decode(&body))
assert.Equal(t, "inactive", body.Status)
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"status": "inactive",
})
case r.Method == http.MethodPost && r.URL.Path == "/v3/app/test-app/enterprise-portal/customer-user":
var body InviteEnterprisePortalRequest
assert.NoError(t, json.NewDecoder(r.Body).Decode(&body))
assert.Equal(t, "cus-123", body.CustomerID)
assert.Equal(t, "user@example.com", body.EmailAddress)
w.WriteHeader(http.StatusCreated)
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"url": "https://enterprise.example.com/invite/abc123",
})
case r.Method == http.MethodGet && r.URL.Path == "/v3/app/test-app/enterprise-portal/customer-users":
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"users": []map[string]interface{}{
{"email": "user1@example.com"},
{"email": "user2@example.com"},
},
})
default:
http.NotFound(w, r)
}
}))
Comment thread
cursor[bot] marked this conversation as resolved.
defer server.Close()

api := platformclient.NewHTTPClient(server.URL, "test-token")
client := VendorV3Client{HTTPClient: *api}

// Test GetEnterprisePortalStatus
status, err := client.GetEnterprisePortalStatus("test-app")
require.NoError(t, err)
require.Equal(t, "active", status)

// Test UpdateEnterprisePortalStatus
updatedStatus, err := client.UpdateEnterprisePortalStatus("test-app", "inactive")
require.NoError(t, err)
require.Equal(t, "inactive", updatedStatus)

// Test SendEnterprisePortalInvite
inviteURL, err := client.SendEnterprisePortalInvite("test-app", "cus-123", "user@example.com")
require.NoError(t, err)
require.Equal(t, "https://enterprise.example.com/invite/abc123", inviteURL)

// Test ListEnterprisePortalUsers
users, err := client.ListEnterprisePortalUsers("test-app", false)
require.NoError(t, err)
require.Len(t, users, 2)
require.Equal(t, "user1@example.com", users[0].Email)
require.Equal(t, "user2@example.com", users[1].Email)
}
Loading