Skip to content

Commit 93f3041

Browse files
committed
Address second-pass PR review feedback
- activity.go: URL-encode flag values when building the query string so a board/creator ID containing & or = can't inject phantom params. - board_test.go: guard mock.GetCalls[0] indexing with a length check in the new board accesses tests so a missing call surfaces as a clear assertion instead of an array-bounds panic. - e2e activity_test.go: keep retrying until the just-created card appears in the activity feed, then fail hard if it doesn't. The previous soft Logf masked regressions where cards drop out of the activity stream.
1 parent 51ce8e6 commit 93f3041

3 files changed

Lines changed: 29 additions & 24 deletions

File tree

e2e/cli_tests/activity_test.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,37 @@ func TestActivityList(t *testing.T) {
1414
cardNum := createCard(t, h, boardID)
1515
creatorID := currentUserID(t, h)
1616

17+
cardNumStr := strconv.Itoa(cardNum)
1718
var result *harness.Result
19+
foundCard := false
1820
for attempt := 0; attempt < 10; attempt++ {
1921
r := h.Run("activity", "list", "--board", boardID)
20-
if r.ExitCode == harness.ExitSuccess && len(r.GetDataArray()) > 0 {
22+
if r.ExitCode == harness.ExitSuccess {
2123
result = r
22-
break
24+
for _, item := range r.GetDataArray() {
25+
m := asMap(item)
26+
if m == nil {
27+
continue
28+
}
29+
if eventable := asMap(m["eventable"]); eventable != nil {
30+
if mapValueString(eventable, "number") == cardNumStr {
31+
foundCard = true
32+
break
33+
}
34+
}
35+
}
36+
if foundCard {
37+
break
38+
}
2339
}
2440
time.Sleep(200 * time.Millisecond)
2541
}
2642
if result == nil {
27-
t.Fatal("expected at least one activity for throwaway board")
43+
t.Fatal("expected at least one successful activity list call")
2844
}
29-
3045
assertOK(t, result)
31-
if len(result.GetDataArray()) == 0 {
32-
t.Fatal("expected activity list to return at least one item")
33-
}
34-
35-
foundCard := false
36-
for _, item := range result.GetDataArray() {
37-
m := asMap(item)
38-
if m == nil {
39-
continue
40-
}
41-
if eventable := asMap(m["eventable"]); eventable != nil {
42-
if got := mapValueString(eventable, "number"); got == strconv.Itoa(cardNum) {
43-
foundCard = true
44-
break
45-
}
46-
}
47-
}
4846
if !foundCard {
49-
t.Logf("activity list did not expose created card number %d; continuing because board activity was non-empty", cardNum)
47+
t.Fatalf("activity list did not expose created card number %d after retries", cardNum)
5048
}
5149

5250
creatorResult := h.Run("activity", "list", "--board", boardID, "--creator", creatorID)

internal/commands/activity.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"fmt"
5+
"net/url"
56
"strconv"
67
"strings"
78

@@ -36,10 +37,10 @@ var activityListCmd = &cobra.Command{
3637

3738
var params []string
3839
if activityListBoard != "" {
39-
params = append(params, "board_ids[]="+activityListBoard)
40+
params = append(params, "board_ids[]="+url.QueryEscape(activityListBoard))
4041
}
4142
if activityListCreator != "" {
42-
params = append(params, "creator_ids[]="+activityListCreator)
43+
params = append(params, "creator_ids[]="+url.QueryEscape(activityListCreator))
4344
}
4445
if activityListPage > 0 {
4546
params = append(params, "page="+strconv.Itoa(activityListPage))

internal/commands/board_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ func TestBoardAccesses(t *testing.T) {
688688
boardAccessesPage = 0
689689

690690
assertExitCode(t, err, 0)
691+
if len(mock.GetCalls) != 1 {
692+
t.Fatalf("expected 1 GET call, got %d", len(mock.GetCalls))
693+
}
691694
if mock.GetCalls[0].Path != "/boards/123/accesses.json" {
692695
t.Errorf("expected path '/boards/123/accesses.json', got '%s'", mock.GetCalls[0].Path)
693696
}
@@ -711,6 +714,9 @@ func TestBoardAccesses(t *testing.T) {
711714
boardAccessesPage = 0
712715

713716
assertExitCode(t, err, 0)
717+
if len(mock.GetCalls) != 1 {
718+
t.Fatalf("expected 1 GET call, got %d", len(mock.GetCalls))
719+
}
714720
if mock.GetCalls[0].Path != "/boards/123/accesses.json?page=2" {
715721
t.Errorf("expected path '/boards/123/accesses.json?page=2', got '%s'", mock.GetCalls[0].Path)
716722
}

0 commit comments

Comments
 (0)