|
1 | 1 | package commands |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
| 5 | + "errors" |
4 | 6 | "testing" |
5 | 7 |
|
6 | 8 | "github.com/stretchr/testify/assert" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | + |
| 11 | + "github.com/basecamp/basecamp-cli/internal/output" |
7 | 12 | ) |
8 | 13 |
|
9 | 14 | func TestIsNumeric(t *testing.T) { |
@@ -36,3 +41,68 @@ func TestIsNumeric(t *testing.T) { |
36 | 41 | }) |
37 | 42 | } |
38 | 43 | } |
| 44 | + |
| 45 | +func TestApplySubscribeFlags_MutualExclusion(t *testing.T) { |
| 46 | + ctx := context.Background() |
| 47 | + // subscribeChanged=true, noSubscribe=true |
| 48 | + _, err := applySubscribeFlags(ctx, nil, "someone", true, true) |
| 49 | + |
| 50 | + require.Error(t, err) |
| 51 | + var e *output.Error |
| 52 | + require.True(t, errors.As(err, &e), "expected *output.Error, got %T", err) |
| 53 | + assert.Contains(t, e.Message, "mutually exclusive") |
| 54 | +} |
| 55 | + |
| 56 | +func TestApplySubscribeFlags_NoSubscribe(t *testing.T) { |
| 57 | + ctx := context.Background() |
| 58 | + // subscribeChanged=false, noSubscribe=true |
| 59 | + result, err := applySubscribeFlags(ctx, nil, "", false, true) |
| 60 | + |
| 61 | + require.NoError(t, err) |
| 62 | + require.NotNil(t, result, "expected non-nil pointer for --no-subscribe") |
| 63 | + assert.Empty(t, *result, "expected empty slice for --no-subscribe") |
| 64 | +} |
| 65 | + |
| 66 | +func TestApplySubscribeFlags_Neither(t *testing.T) { |
| 67 | + ctx := context.Background() |
| 68 | + // subscribeChanged=false, noSubscribe=false |
| 69 | + result, err := applySubscribeFlags(ctx, nil, "", false, false) |
| 70 | + |
| 71 | + require.NoError(t, err) |
| 72 | + assert.Nil(t, result, "expected nil when neither flag is set") |
| 73 | +} |
| 74 | + |
| 75 | +func TestApplySubscribeFlags_ExplicitEmptyString(t *testing.T) { |
| 76 | + // --subscribe "" (explicitly set but empty value) should be a hard error |
| 77 | + ctx := context.Background() |
| 78 | + // subscribeChanged=true (flag was explicitly passed), value="" |
| 79 | + _, err := applySubscribeFlags(ctx, nil, "", true, false) |
| 80 | + |
| 81 | + require.Error(t, err) |
| 82 | + var e *output.Error |
| 83 | + require.True(t, errors.As(err, &e), "expected *output.Error, got %T", err) |
| 84 | + assert.Contains(t, e.Message, "at least one person") |
| 85 | +} |
| 86 | + |
| 87 | +func TestApplySubscribeFlags_WhitespaceOnlyRequiresAtLeastOne(t *testing.T) { |
| 88 | + ctx := context.Background() |
| 89 | + // subscribeChanged=true, value=" " |
| 90 | + _, err := applySubscribeFlags(ctx, nil, " ", true, false) |
| 91 | + |
| 92 | + require.Error(t, err) |
| 93 | + var e *output.Error |
| 94 | + require.True(t, errors.As(err, &e), "expected *output.Error, got %T", err) |
| 95 | + assert.Contains(t, e.Message, "at least one person") |
| 96 | +} |
| 97 | + |
| 98 | +func TestApplySubscribeFlags_CommaOnlyRequiresAtLeastOne(t *testing.T) { |
| 99 | + // --subscribe ",,," should fail: only delimiters, no actual tokens |
| 100 | + ctx := context.Background() |
| 101 | + // subscribeChanged=true, value=",,," |
| 102 | + _, err := applySubscribeFlags(ctx, nil, ",,,", true, false) |
| 103 | + |
| 104 | + require.Error(t, err) |
| 105 | + var e *output.Error |
| 106 | + require.True(t, errors.As(err, &e), "expected *output.Error, got %T", err) |
| 107 | + assert.Contains(t, e.Message, "at least one person") |
| 108 | +} |
0 commit comments