Skip to content

Commit

Permalink
update static app formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaln7 committed Apr 13, 2021
1 parent 7f93c43 commit fd442d3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
21 changes: 17 additions & 4 deletions commands/displayers/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (r AppProposeResponse) Cols() []string {

cols = append(cols, []string{
"AppIsStatic",
"StaticSites",
"StaticApps",
"AppCost",
"AppTierUpgradeCost",
"AppTierDowngradeCost",
Expand All @@ -316,15 +316,28 @@ 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",
}
}

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"

Expand All @@ -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,
Expand Down
59 changes: 47 additions & 12 deletions integration/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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)))
})

Expand Down

0 comments on commit fd442d3

Please sign in to comment.