Skip to content

Commit 8832af4

Browse files
committed
Address PR review feedback from cubic
- Use cmd.Flags().Changed() instead of == 0 for usage-limit flag detection - Add length guards before accessing mock call slices in tests - Add missing "rejects pseudo columns" sub-test for TestColumnMoveRight
1 parent 5ace8d7 commit 8832af4

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

internal/commands/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ var accountJoinCodeUpdateCmd = &cobra.Command{
235235
return err
236236
}
237237

238-
if accountJoinCodeUpdateUsageLimit == 0 {
238+
if !cmd.Flags().Changed("usage-limit") {
239239
return newRequiredFlagError("usage-limit")
240240
}
241241

internal/commands/account_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,12 @@ func TestAccountJoinCodeUpdate(t *testing.T) {
263263
SetTestConfig("token", "account", "https://api.example.com")
264264
defer resetTest()
265265

266-
accountJoinCodeUpdateUsageLimit = 10
266+
accountJoinCodeUpdateCmd.Flags().Set("usage-limit", "10")
267+
defer func() {
268+
accountJoinCodeUpdateUsageLimit = 0
269+
accountJoinCodeUpdateCmd.Flags().Lookup("usage-limit").Changed = false
270+
}()
267271
err := accountJoinCodeUpdateCmd.RunE(accountJoinCodeUpdateCmd, []string{})
268-
accountJoinCodeUpdateUsageLimit = 0
269272

270273
assertExitCode(t, err, 0)
271274
if mock.PatchCalls[0].Path != "/account/join_code.json" {

internal/commands/card_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,9 @@ func TestCardPublish(t *testing.T) {
10701070
err := cardPublishCmd.RunE(cardPublishCmd, []string{"42"})
10711071
assertExitCode(t, err, 0)
10721072

1073+
if len(mock.PostCalls) != 1 {
1074+
t.Fatalf("expected 1 post call, got %d", len(mock.PostCalls))
1075+
}
10731076
if mock.PostCalls[0].Path != "/cards/42/publish.json" {
10741077
t.Errorf("expected path '/cards/42/publish.json', got '%s'", mock.PostCalls[0].Path)
10751078
}
@@ -1086,6 +1089,9 @@ func TestCardMarkRead(t *testing.T) {
10861089
err := cardMarkReadCmd.RunE(cardMarkReadCmd, []string{"42"})
10871090
assertExitCode(t, err, 0)
10881091

1092+
if len(mock.PostCalls) != 1 {
1093+
t.Fatalf("expected 1 post call, got %d", len(mock.PostCalls))
1094+
}
10891095
if mock.PostCalls[0].Path != "/cards/42/reading.json" {
10901096
t.Errorf("expected path '/cards/42/reading.json', got '%s'", mock.PostCalls[0].Path)
10911097
}
@@ -1102,6 +1108,9 @@ func TestCardMarkUnread(t *testing.T) {
11021108
err := cardMarkUnreadCmd.RunE(cardMarkUnreadCmd, []string{"42"})
11031109
assertExitCode(t, err, 0)
11041110

1111+
if len(mock.DeleteCalls) != 1 {
1112+
t.Fatalf("expected 1 delete call, got %d", len(mock.DeleteCalls))
1113+
}
11051114
if mock.DeleteCalls[0].Path != "/cards/42/reading.json" {
11061115
t.Errorf("expected path '/cards/42/reading.json', got '%s'", mock.DeleteCalls[0].Path)
11071116
}

internal/commands/column_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,14 @@ func TestColumnMoveRight(t *testing.T) {
373373
t.Errorf("expected path '/columns/col-1/right_position.json', got '%s'", mock.PostCalls[0].Path)
374374
}
375375
})
376+
377+
t.Run("rejects pseudo columns", func(t *testing.T) {
378+
mock := NewMockClient()
379+
SetTestModeWithSDK(mock)
380+
SetTestConfig("token", "account", "https://api.example.com")
381+
defer resetTest()
382+
383+
err := columnMoveRightCmd.RunE(columnMoveRightCmd, []string{"not-now"})
384+
assertExitCode(t, err, errors.ExitInvalidArgs)
385+
})
376386
}

0 commit comments

Comments
 (0)