diff --git a/pkg/mockapi/api_server.go b/pkg/mockapi/api_server.go index 5af5ad8a..4bc66c14 100644 --- a/pkg/mockapi/api_server.go +++ b/pkg/mockapi/api_server.go @@ -53,6 +53,7 @@ func NewHandler(t *testing.T) *Handler { h.Mux.Post("/organizations/{organization_id}/subscriptions", h.handleCreateSubscription) h.Mux.Get("/subscriptions/{subscription_id}", h.handleGetSubscription) + h.Mux.Get("/organizations/{organization_id}/subscriptions/{subscription_id}", h.handleGetSubscription) h.Mux.Get("/organizations/{organization_id}/subscriptions/can-create", h.handleCanCreateSubscriptions) h.Mux.Get("/organizations/{organization_id}/setup/options", func(w http.ResponseWriter, _ *http.Request) { type options struct { diff --git a/pkg/mockapi/model.go b/pkg/mockapi/model.go index a1e7e0a4..27331ea5 100644 --- a/pkg/mockapi/model.go +++ b/pkg/mockapi/model.go @@ -61,9 +61,26 @@ type Project struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` + Subscription ProjectSubscriptionInfo `json:"subscription,omitempty"` + SubscriptionID string `json:"-"` } +type ProjectSubscriptionInfo struct { + LicenseURI string `json:"license_uri,omitempty"` + + Plan string `json:"plan,omitempty"` + Environments int `json:"environments,omitempty"` + Storage int `json:"storage,omitempty"` + IncludedUsers int `json:"included_users,omitempty"` + UserLicenses int `json:"user_licenses,omitempty"` + + ManagementURI string `json:"subscription_management_uri,omitempty"` + + Restricted bool `json:"restricted,omitempty"` + Suspended bool `json:"suspended,omitempty"` +} + func (p *Project) AsRef() *ProjectRef { return &ProjectRef{ ID: p.ID, diff --git a/pkg/mockapi/subscriptions.go b/pkg/mockapi/subscriptions.go index ed6e254d..ab701d28 100644 --- a/pkg/mockapi/subscriptions.go +++ b/pkg/mockapi/subscriptions.go @@ -2,6 +2,7 @@ package mockapi import ( "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -17,11 +18,14 @@ func (h *Handler) handleCreateSubscription(w http.ResponseWriter, req *http.Requ }{} err := json.NewDecoder(req.Body).Decode(&createOptions) require.NoError(h.t, err) + orgID := chi.URLParam(req, "organization_id") id := NumericID() projectID := ProjectID() sub := Subscription{ - ID: id, - Links: MakeHALLinks("self=" + "/subscriptions/" + url.PathEscape(id)), + ID: id, + Links: MakeHALLinks( + "self=" + "/organizations/" + url.PathEscape(orgID) + "/subscriptions/" + url.PathEscape(id), + ), ProjectRegion: createOptions.Region, ProjectTitle: createOptions.Title, Status: "provisioning", @@ -40,7 +44,10 @@ func (h *Handler) handleCreateSubscription(w http.ResponseWriter, req *http.Requ Links: MakeHALLinks("self=/projects/" + projectID), Repository: ProjectRepository{URL: projectID + "@git.example.com:" + projectID + ".git"}, SubscriptionID: sub.ID, - Organization: chi.URLParam(req, "organization_id"), + Subscription: ProjectSubscriptionInfo{ + LicenseURI: fmt.Sprintf("/licenses/%s", url.PathEscape(sub.ID)), + }, + Organization: chi.URLParam(req, "organization_id"), } h.store.Unlock()