Skip to content

Commit d2cf1f4

Browse files
committed
Fix final e2e review issues
1 parent a663379 commit d2cf1f4

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

e2e/cli_tests/crud_subresources_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,23 @@ func TestStepCRUD(t *testing.T) {
105105

106106
func TestReactionCRUD(t *testing.T) {
107107
h := newHarness(t)
108+
userID := currentUserID(t, h)
108109
cardStr := strconv.Itoa(fixture.CardNumber)
110+
cardReactionContent := "+1"
111+
commentReactionContent := "heart"
112+
109113
cardReactionsBefore := h.Run("reaction", "list", "--card", cardStr)
110114
assertOK(t, cardReactionsBefore)
111115
commentReactionsBefore := h.Run("reaction", "list", "--card", cardStr, "--comment", fixture.CommentID)
112116
assertOK(t, commentReactionsBefore)
113117

114-
cardReaction := h.Run("reaction", "create", "--card", cardStr, "--content", "+1")
118+
cardReaction := h.Run("reaction", "create", "--card", cardStr, "--content", cardReactionContent)
115119
assertOK(t, cardReaction)
116120
cardReactions := h.Run("reaction", "list", "--card", cardStr)
117121
assertOK(t, cardReactions)
118-
cardReactionID := listAddedID(cardReactionsBefore.GetDataArray(), cardReactions.GetDataArray())
122+
cardReactionID := addedReactionID(cardReactionsBefore.GetDataArray(), cardReactions.GetDataArray(), cardReactionContent, userID)
119123
if cardReactionID == "" {
120-
t.Fatal("expected created card reaction to appear in list")
124+
t.Fatal("expected exactly one created card reaction for the current user to appear in list")
121125
}
122126
t.Cleanup(func() {
123127
if cardReactionID != "" {
@@ -136,13 +140,13 @@ func TestReactionCRUD(t *testing.T) {
136140
t.Fatalf("expected deleted card reaction %q to be absent from list", deletedCardReactionID)
137141
}
138142

139-
commentReaction := h.Run("reaction", "create", "--card", cardStr, "--comment", fixture.CommentID, "--content", "heart")
143+
commentReaction := h.Run("reaction", "create", "--card", cardStr, "--comment", fixture.CommentID, "--content", commentReactionContent)
140144
assertOK(t, commentReaction)
141145
commentReactions := h.Run("reaction", "list", "--card", cardStr, "--comment", fixture.CommentID)
142146
assertOK(t, commentReactions)
143-
commentReactionID := listAddedID(commentReactionsBefore.GetDataArray(), commentReactions.GetDataArray())
147+
commentReactionID := addedReactionID(commentReactionsBefore.GetDataArray(), commentReactions.GetDataArray(), commentReactionContent, userID)
144148
if commentReactionID == "" {
145-
t.Fatal("expected created comment reaction to appear in list")
149+
t.Fatal("expected exactly one created comment reaction for the current user to appear in list")
146150
}
147151
t.Cleanup(func() {
148152
if commentReactionID != "" {

e2e/cli_tests/helpers_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,46 @@ func listAddedID(before, after []any) string {
216216
return ""
217217
}
218218

219+
func addedReactionID(before, after []any, content, userID string) string {
220+
seen := make(map[string]struct{}, len(before))
221+
for _, item := range before {
222+
m := asMap(item)
223+
if m == nil {
224+
continue
225+
}
226+
if id := mapValueString(m, "id"); id != "" {
227+
seen[id] = struct{}{}
228+
}
229+
}
230+
231+
matches := []string{}
232+
for _, item := range after {
233+
m := asMap(item)
234+
if m == nil {
235+
continue
236+
}
237+
id := mapValueString(m, "id")
238+
if id == "" {
239+
continue
240+
}
241+
if _, ok := seen[id]; ok {
242+
continue
243+
}
244+
if mapValueString(m, "content") != content {
245+
continue
246+
}
247+
reacter := asMap(m["reacter"])
248+
if userID != "" && mapValueString(reacter, "id") != userID {
249+
continue
250+
}
251+
matches = append(matches, id)
252+
}
253+
if len(matches) == 1 {
254+
return matches[0]
255+
}
256+
return ""
257+
}
258+
219259
func bodyPlainText(m map[string]any) string {
220260
if m == nil {
221261
return ""

e2e/harness/fixture.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func NewSharedFixture(cfg *Config) (*SharedFixture, error) {
4343
f := &SharedFixture{cfg: cfg, configHome: tmpDir}
4444
if err := f.setup(); err != nil {
4545
if teardownErr := f.Teardown(); teardownErr != nil {
46+
_ = os.RemoveAll(tmpDir)
4647
return nil, fmt.Errorf("%w\ncleanup: %v", err, teardownErr)
4748
}
4849
return nil, err

0 commit comments

Comments
 (0)