@@ -106,53 +106,59 @@ func TestStepCRUD(t *testing.T) {
106106func TestReactionCRUD (t * testing.T ) {
107107 h := newHarness (t )
108108 cardStr := strconv .Itoa (fixture .CardNumber )
109- assertOK (t , h .Run ("reaction" , "list" , "--card" , cardStr ))
110- assertOK (t , h .Run ("reaction" , "list" , "--card" , cardStr , "--comment" , fixture .CommentID ))
109+ cardReactionsBefore := h .Run ("reaction" , "list" , "--card" , cardStr )
110+ assertOK (t , cardReactionsBefore )
111+ commentReactionsBefore := h .Run ("reaction" , "list" , "--card" , cardStr , "--comment" , fixture .CommentID )
112+ assertOK (t , commentReactionsBefore )
111113
112114 cardReaction := h .Run ("reaction" , "create" , "--card" , cardStr , "--content" , "+1" )
113115 assertOK (t , cardReaction )
114- cardReactionID := cardReaction .GetIDFromLocation ()
115- if cardReactionID == "" {
116- cardReactionID = cardReaction .GetDataString ("id" )
117- }
118- if cardReactionID == "" {
119- t .Fatal ("no reaction ID in create response" )
120- }
121- t .Cleanup (func () { newHarness (t ).Run ("reaction" , "delete" , cardReactionID , "--card" , cardStr ) })
122116 cardReactions := h .Run ("reaction" , "list" , "--card" , cardStr )
123117 assertOK (t , cardReactions )
118+ cardReactionID := listAddedID (cardReactionsBefore .GetDataArray (), cardReactions .GetDataArray ())
119+ if cardReactionID == "" {
120+ t .Fatal ("expected created card reaction to appear in list" )
121+ }
122+ t .Cleanup (func () {
123+ if cardReactionID != "" {
124+ newHarness (t ).Run ("reaction" , "delete" , cardReactionID , "--card" , cardStr )
125+ }
126+ })
124127 if listMapByID (cardReactions .GetDataArray (), cardReactionID ) == nil {
125128 t .Fatalf ("expected card reaction list to include %q" , cardReactionID )
126129 }
130+ deletedCardReactionID := cardReactionID
127131 assertOK (t , h .Run ("reaction" , "delete" , cardReactionID , "--card" , cardStr ))
132+ cardReactionID = ""
128133 cardReactions = h .Run ("reaction" , "list" , "--card" , cardStr )
129134 assertOK (t , cardReactions )
130- if listMapByID (cardReactions .GetDataArray (), cardReactionID ) != nil {
131- t .Fatalf ("expected deleted card reaction %q to be absent from list" , cardReactionID )
135+ if listMapByID (cardReactions .GetDataArray (), deletedCardReactionID ) != nil {
136+ t .Fatalf ("expected deleted card reaction %q to be absent from list" , deletedCardReactionID )
132137 }
133138
134139 commentReaction := h .Run ("reaction" , "create" , "--card" , cardStr , "--comment" , fixture .CommentID , "--content" , "heart" )
135140 assertOK (t , commentReaction )
136- commentReactionID := commentReaction .GetIDFromLocation ()
137- if commentReactionID == "" {
138- commentReactionID = commentReaction .GetDataString ("id" )
139- }
141+ commentReactions := h .Run ("reaction" , "list" , "--card" , cardStr , "--comment" , fixture .CommentID )
142+ assertOK (t , commentReactions )
143+ commentReactionID := listAddedID (commentReactionsBefore .GetDataArray (), commentReactions .GetDataArray ())
140144 if commentReactionID == "" {
141- t .Fatal ("no comment reaction ID in create response " )
145+ t .Fatal ("expected created comment reaction to appear in list " )
142146 }
143147 t .Cleanup (func () {
144- newHarness (t ).Run ("reaction" , "delete" , commentReactionID , "--card" , cardStr , "--comment" , fixture .CommentID )
148+ if commentReactionID != "" {
149+ newHarness (t ).Run ("reaction" , "delete" , commentReactionID , "--card" , cardStr , "--comment" , fixture .CommentID )
150+ }
145151 })
146- commentReactions := h .Run ("reaction" , "list" , "--card" , cardStr , "--comment" , fixture .CommentID )
147- assertOK (t , commentReactions )
148152 if listMapByID (commentReactions .GetDataArray (), commentReactionID ) == nil {
149153 t .Fatalf ("expected comment reaction list to include %q" , commentReactionID )
150154 }
155+ deletedCommentReactionID := commentReactionID
151156 assertOK (t , h .Run ("reaction" , "delete" , commentReactionID , "--card" , cardStr , "--comment" , fixture .CommentID ))
157+ commentReactionID = ""
152158 commentReactions = h .Run ("reaction" , "list" , "--card" , cardStr , "--comment" , fixture .CommentID )
153159 assertOK (t , commentReactions )
154- if listMapByID (commentReactions .GetDataArray (), commentReactionID ) != nil {
155- t .Fatalf ("expected deleted comment reaction %q to be absent from list" , commentReactionID )
160+ if listMapByID (commentReactions .GetDataArray (), deletedCommentReactionID ) != nil {
161+ t .Fatalf ("expected deleted comment reaction %q to be absent from list" , deletedCommentReactionID )
156162 }
157163}
158164
0 commit comments