@@ -1184,3 +1184,87 @@ func TestCardUngolden(t *testing.T) {
11841184 }
11851185 })
11861186}
1187+
1188+ func TestCardMove (t * testing.T ) {
1189+ t .Run ("moves card to different board" , func (t * testing.T ) {
1190+ mock := NewMockClient ()
1191+ mock .PatchResponse = & client.APIResponse {
1192+ StatusCode : 204 ,
1193+ Data : nil ,
1194+ }
1195+ mock .GetResponse = & client.APIResponse {
1196+ StatusCode : 200 ,
1197+ Data : map [string ]interface {}{
1198+ "id" : "abc" ,
1199+ "number" : float64 (42 ),
1200+ "title" : "Test Card" ,
1201+ "board_id" : "board-456" ,
1202+ },
1203+ }
1204+
1205+ result := SetTestMode (mock )
1206+ SetTestConfig ("token" , "account" , "https://api.example.com" )
1207+ defer ResetTestMode ()
1208+
1209+ cardMoveBoard = "board-456"
1210+ RunTestCommand (func () {
1211+ cardMoveCmd .Run (cardMoveCmd , []string {"42" })
1212+ })
1213+ cardMoveBoard = ""
1214+
1215+ if result .ExitCode != 0 {
1216+ t .Errorf ("expected exit code 0, got %d" , result .ExitCode )
1217+ }
1218+ if len (mock .PatchCalls ) != 1 {
1219+ t .Errorf ("expected 1 patch call, got %d" , len (mock .PatchCalls ))
1220+ }
1221+ if mock .PatchCalls [0 ].Path != "/cards/42/board.json" {
1222+ t .Errorf ("expected path '/cards/42/board.json', got '%s'" , mock .PatchCalls [0 ].Path )
1223+ }
1224+
1225+ body := mock .PatchCalls [0 ].Body .(map [string ]interface {})
1226+ if body ["board_id" ] != "board-456" {
1227+ t .Errorf ("expected board_id 'board-456', got '%v'" , body ["board_id" ])
1228+ }
1229+
1230+ // Verify it fetched the card after moving
1231+ if len (mock .GetCalls ) != 1 || mock .GetCalls [0 ].Path != "/cards/42.json" {
1232+ t .Errorf ("expected get call to '/cards/42.json', got %+v" , mock .GetCalls )
1233+ }
1234+ })
1235+
1236+ t .Run ("requires --to flag" , func (t * testing.T ) {
1237+ mock := NewMockClient ()
1238+ result := SetTestMode (mock )
1239+ SetTestConfig ("token" , "account" , "https://api.example.com" )
1240+ defer ResetTestMode ()
1241+
1242+ cardMoveBoard = ""
1243+ RunTestCommand (func () {
1244+ cardMoveCmd .Run (cardMoveCmd , []string {"42" })
1245+ })
1246+
1247+ if result .ExitCode != errors .ExitInvalidArgs {
1248+ t .Errorf ("expected exit code %d, got %d" , errors .ExitInvalidArgs , result .ExitCode )
1249+ }
1250+ })
1251+
1252+ t .Run ("handles not found error" , func (t * testing.T ) {
1253+ mock := NewMockClient ()
1254+ mock .PatchError = errors .NewNotFoundError ("Card not found" )
1255+
1256+ result := SetTestMode (mock )
1257+ SetTestConfig ("token" , "account" , "https://api.example.com" )
1258+ defer ResetTestMode ()
1259+
1260+ cardMoveBoard = "board-456"
1261+ RunTestCommand (func () {
1262+ cardMoveCmd .Run (cardMoveCmd , []string {"999" })
1263+ })
1264+ cardMoveBoard = ""
1265+
1266+ if result .ExitCode != errors .ExitNotFound {
1267+ t .Errorf ("expected exit code %d, got %d" , errors .ExitNotFound , result .ExitCode )
1268+ }
1269+ })
1270+ }
0 commit comments