From 66ab8f7780fc0e07efd69cfd0d5c2323c1ac6cab Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Wed, 11 Dec 2024 09:48:28 +0000 Subject: [PATCH] mockapi: set the project organization when creating a subscription --- pkg/mockapi/api_server.go | 12 ++++++------ pkg/mockapi/orgs.go | 8 ++++---- pkg/mockapi/subscriptions.go | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/mockapi/api_server.go b/pkg/mockapi/api_server.go index 1e1f40e..0264327 100644 --- a/pkg/mockapi/api_server.go +++ b/pkg/mockapi/api_server.go @@ -46,22 +46,22 @@ func NewHandler(t *testing.T) *Handler { h.Mux.Get("/organizations", h.handleListOrgs) h.Mux.Post("/organizations", h.handleCreateOrg) - h.Mux.Get("/organizations/{id}", h.handleGetOrg) - h.Mux.Patch("/organizations/{id}", h.handlePatchOrg) + h.Mux.Get("/organizations/{organization_id}", h.handleGetOrg) + h.Mux.Patch("/organizations/{organization_id}", h.handlePatchOrg) h.Mux.Get("/users/{id}/organizations", h.handleListOrgs) h.Mux.Get("/ref/organizations", h.handleOrgRefs) - h.Mux.Post("/organizations/{id}/subscriptions", h.handleCreateSubscription) + h.Mux.Post("/organizations/{organization_id}/subscriptions", h.handleCreateSubscription) h.Mux.Get("/subscriptions/{id}", h.handleGetSubscription) - h.Mux.Get("/organizations/{id}/subscriptions/can-create", h.handleCanCreateSubscriptions) - h.Mux.Get("/organizations/{id}/setup/options", func(w http.ResponseWriter, _ *http.Request) { + 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 { Plans []string `json:"plans"` Regions []string `json:"regions"` } _ = json.NewEncoder(w).Encode(options{[]string{"development"}, []string{"test-region"}}) }) - h.Mux.Get("/organizations/{id}/subscriptions/estimate", func(w http.ResponseWriter, _ *http.Request) { + h.Mux.Get("/organizations/{organization_id}/subscriptions/estimate", func(w http.ResponseWriter, _ *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{"total": "$1,000 USD"}) }) diff --git a/pkg/mockapi/orgs.go b/pkg/mockapi/orgs.go index 98be492..a3077ad 100644 --- a/pkg/mockapi/orgs.go +++ b/pkg/mockapi/orgs.go @@ -56,7 +56,7 @@ func (h *Handler) handleGetOrg(w http.ResponseWriter, req *http.Request) { defer h.store.RUnlock() var org *Org - orgID := chi.URLParam(req, "id") + orgID := chi.URLParam(req, "organization_id") if strings.HasPrefix(orgID, "name%3D") { name := strings.TrimPrefix(orgID, "name%3D") for _, o := range h.store.orgs { @@ -103,8 +103,8 @@ func (h *Handler) handleCreateOrg(w http.ResponseWriter, req *http.Request) { func (h *Handler) handlePatchOrg(w http.ResponseWriter, req *http.Request) { h.store.Lock() defer h.store.Unlock() - projectID := chi.URLParam(req, "id") - p, ok := h.store.orgs[projectID] + orgID := chi.URLParam(req, "organization_id") + p, ok := h.store.orgs[orgID] if !ok { w.WriteHeader(http.StatusNotFound) return @@ -115,6 +115,6 @@ func (h *Handler) handlePatchOrg(w http.ResponseWriter, req *http.Request) { w.WriteHeader(http.StatusBadRequest) return } - h.store.orgs[projectID] = &patched + h.store.orgs[orgID] = &patched _ = json.NewEncoder(w).Encode(&patched) } diff --git a/pkg/mockapi/subscriptions.go b/pkg/mockapi/subscriptions.go index 894eb8e..dc868aa 100644 --- a/pkg/mockapi/subscriptions.go +++ b/pkg/mockapi/subscriptions.go @@ -42,6 +42,7 @@ 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"), } h.store.Unlock() @@ -74,7 +75,7 @@ func (h *Handler) handleGetSubscription(w http.ResponseWriter, req *http.Request func (h *Handler) handleCanCreateSubscriptions(w http.ResponseWriter, req *http.Request) { h.store.RLock() defer h.store.RUnlock() - id := chi.URLParam(req, "id") + id := chi.URLParam(req, "organization_id") cc := h.store.canCreate[id] if cc == nil { cc = &CanCreateResponse{CanCreate: true}