From fd442d37e2f2a5a2a30dfd585dc628d7f4f2ea40 Mon Sep 17 00:00:00 2001 From: Kamal Nasser Date: Tue, 13 Apr 2021 19:39:49 +0300 Subject: [PATCH] update static app formatting --- commands/displayers/apps.go | 21 ++++++++++--- integration/apps_test.go | 59 +++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/commands/displayers/apps.go b/commands/displayers/apps.go index bc3bd189f..a9854af14 100644 --- a/commands/displayers/apps.go +++ b/commands/displayers/apps.go @@ -302,7 +302,7 @@ func (r AppProposeResponse) Cols() []string { cols = append(cols, []string{ "AppIsStatic", - "StaticSites", + "StaticApps", "AppCost", "AppTierUpgradeCost", "AppTierDowngradeCost", @@ -316,7 +316,7 @@ func (r AppProposeResponse) ColMap() map[string]string { "AppNameAvailable": "App Name Available?", "AppNameSuggestion": "Suggested App Name", "AppIsStatic": "Is Static?", - "StaticSites": "Free Static Site Usage", + "StaticApps": "Static App Usage", "AppCost": "$/month", "AppTierUpgradeCost": "$/month on higher tier", "AppTierDowngradeCost": "$/month on lower tier", @@ -324,7 +324,20 @@ func (r AppProposeResponse) ColMap() map[string]string { } func (r AppProposeResponse) KV() []map[string]interface{} { - staticSites := fmt.Sprintf("%s of %s", r.Res.ExistingStaticApps, r.Res.MaxFreeStaticApps) + existingStatic, _ := strconv.ParseInt(r.Res.ExistingStaticApps, 10, 64) + maxFreeStatic, _ := strconv.ParseInt(r.Res.MaxFreeStaticApps, 10, 64) + var paidStatic int64 + freeStatic := existingStatic + if existingStatic > maxFreeStatic { + paidStatic = existingStatic - maxFreeStatic + freeStatic = maxFreeStatic + } + + staticApps := fmt.Sprintf("%d of %d free", freeStatic, maxFreeStatic) + if paidStatic > 0 { + staticApps = fmt.Sprintf("%s, %d paid", staticApps, paidStatic) + } + downgradeCost := "n/a" upgradeCost := "n/a" @@ -338,7 +351,7 @@ func (r AppProposeResponse) KV() []map[string]interface{} { out := map[string]interface{}{ "AppNameAvailable": boolToYesNo(r.Res.AppNameAvailable), "AppIsStatic": boolToYesNo(r.Res.AppIsStatic), - "StaticSites": staticSites, + "StaticApps": staticApps, "AppCost": fmt.Sprintf("%0.2f", r.Res.AppCost), "AppTierUpgradeCost": upgradeCost, "AppTierDowngradeCost": downgradeCost, diff --git a/integration/apps_test.go b/integration/apps_test.go index 131c4ac3e..80cec7e47 100644 --- a/integration/apps_test.go +++ b/integration/apps_test.go @@ -827,6 +827,8 @@ var _ = suite("apps/propose", func(t *testing.T, when spec.G, it spec.S) { server *httptest.Server ) + testAppUUID2 := "93a37175-f520-0000-0000-26e63491dbf4" + it.Before(func() { expect = require.New(t) @@ -852,18 +854,30 @@ var _ = suite("apps/propose", func(t *testing.T, when spec.G, it spec.S) { w.WriteHeader(http.StatusBadRequest) return } - assert.Equal(t, testAppUUID, r.AppID) assert.Equal(t, &testAppSpec, r.Spec) - json.NewEncoder(w).Encode(&godo.AppProposeResponse{ - AppIsStatic: true, - AppNameAvailable: false, - AppNameSuggestion: "new-name", - AppCost: 5, - AppTierUpgradeCost: 10, - ExistingStaticApps: "2", - MaxFreeStaticApps: "3", - }) + switch r.AppID { + case testAppUUID: + json.NewEncoder(w).Encode(&godo.AppProposeResponse{ + AppIsStatic: true, + AppNameAvailable: false, + AppNameSuggestion: "new-name", + AppCost: 5, + AppTierUpgradeCost: 10, + MaxFreeStaticApps: "3", + }) + case testAppUUID2: + json.NewEncoder(w).Encode(&godo.AppProposeResponse{ + AppIsStatic: true, + AppNameAvailable: true, + AppCost: 20, + AppTierDowngradeCost: 15, + ExistingStaticApps: "5", + MaxFreeStaticApps: "3", + }) + default: + t.Errorf("unexpected app uuid %s", r.AppID) + } default: dump, err := httputil.DumpRequest(req, true) if err != nil { @@ -891,8 +905,29 @@ var _ = suite("apps/propose", func(t *testing.T, when spec.G, it spec.S) { output, err := cmd.CombinedOutput() expect.NoError(err) - expectedOutput := `App Name Available? Suggested App Name Is Static? Free Static Site Usage $/month $/month on higher tier $/month on lower tier -no new-name yes 2 of 3 5.00 10.00 n/a` + expectedOutput := `App Name Available? Suggested App Name Is Static? Static App Usage $/month $/month on higher tier $/month on lower tier +no new-name yes 0 of 3 free 5.00 10.00 n/a` + expect.Equal(expectedOutput, strings.TrimSpace(string(output))) + }) + + it("prints info about the proposed app with paid static apps", func() { + cmd := exec.Command(builtBinaryPath, + "-t", "some-magic-token", + "-u", server.URL, + "apps", "propose", + "--spec", "-", + "--app", testAppUUID2, + ) + byt, err := json.Marshal(testAppSpec) + expect.NoError(err) + + cmd.Stdin = bytes.NewReader(byt) + + output, err := cmd.CombinedOutput() + expect.NoError(err) + + expectedOutput := `App Name Available? Is Static? Static App Usage $/month $/month on higher tier $/month on lower tier +yes yes 3 of 3 free, 2 paid 20.00 n/a 15.00` expect.Equal(expectedOutput, strings.TrimSpace(string(output))) })