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
1 change: 1 addition & 0 deletions pkg/mockapi/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions pkg/mockapi/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions pkg/mockapi/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mockapi

import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"time"
Expand All @@ -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",
Expand All @@ -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()

Expand Down
Loading