Skip to content

Commit 65c85d8

Browse files
srtaalejClaude
andcommitted
fix: add deprecation comment and unit tests for updateIcon routing
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 1527e03 commit 65c85d8

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

internal/pkg/apps/install.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ func updateIcon(ctx context.Context, clients *shared.ClientFactory, iconPath, ap
659659
if clients.Config.WithExperimentOn(experiment.SetIcon) {
660660
_, err = clients.API().IconSet(ctx, clients.Fs, token, appID, iconPath)
661661
} else if isHosted {
662+
// DEPRECATED: Prefer IconSet once the SetIcon experiment concludes
662663
_, err = clients.API().Icon(ctx, clients.Fs, token, appID, iconPath)
663664
} else {
664665
return nil

internal/pkg/apps/install_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ package apps
1616

1717
import (
1818
"bytes"
19+
"context"
20+
"fmt"
1921
"testing"
2022

2123
"github.com/slackapi/slack-cli/internal/api"
2224
"github.com/slackapi/slack-cli/internal/app"
2325
"github.com/slackapi/slack-cli/internal/cache"
2426
"github.com/slackapi/slack-cli/internal/config"
27+
"github.com/slackapi/slack-cli/internal/experiment"
2528
"github.com/slackapi/slack-cli/internal/shared"
2629
"github.com/slackapi/slack-cli/internal/shared/types"
2730
"github.com/slackapi/slack-cli/internal/slackcontext"
@@ -1724,3 +1727,87 @@ func TestContinueDespiteWarning(t *testing.T) {
17241727
})
17251728
}
17261729
}
1730+
1731+
func Test_updateIcon(t *testing.T) {
1732+
tests := map[string]struct {
1733+
isHosted bool
1734+
experimentOn bool
1735+
expectIconSet bool
1736+
expectIcon bool
1737+
expectSkip bool
1738+
mockError error
1739+
expectedError bool
1740+
}{
1741+
"experiment on + hosted app uses IconSet": {
1742+
isHosted: true,
1743+
experimentOn: true,
1744+
expectIconSet: true,
1745+
},
1746+
"experiment on + non-hosted app uses IconSet": {
1747+
isHosted: false,
1748+
experimentOn: true,
1749+
expectIconSet: true,
1750+
},
1751+
"experiment off + hosted app uses Icon": {
1752+
isHosted: true,
1753+
experimentOn: false,
1754+
expectIcon: true,
1755+
},
1756+
"experiment off + non-hosted app skips upload": {
1757+
isHosted: false,
1758+
experimentOn: false,
1759+
expectSkip: true,
1760+
},
1761+
"returns error from IconSet": {
1762+
isHosted: false,
1763+
experimentOn: true,
1764+
expectIconSet: true,
1765+
mockError: fmt.Errorf("api error"),
1766+
expectedError: true,
1767+
},
1768+
"returns error from Icon": {
1769+
isHosted: true,
1770+
experimentOn: false,
1771+
expectIcon: true,
1772+
mockError: fmt.Errorf("api error"),
1773+
expectedError: true,
1774+
},
1775+
}
1776+
for name, tc := range tests {
1777+
t.Run(name, func(t *testing.T) {
1778+
ctx := slackcontext.MockContext(t.Context())
1779+
clientsMock := shared.NewClientsMock()
1780+
clientsMock.AddDefaultMocks()
1781+
1782+
if tc.experimentOn {
1783+
clientsMock.Config.ExperimentsFlag = []string{string(experiment.SetIcon)}
1784+
clientsMock.Config.LoadExperiments(ctx, func(_ context.Context, _ string, _ ...interface{}) {})
1785+
}
1786+
1787+
clientsMock.API.On("IconSet", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1788+
Return(api.IconResult{}, tc.mockError)
1789+
clientsMock.API.On("Icon", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1790+
Return(api.IconResult{}, tc.mockError)
1791+
1792+
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
1793+
err := updateIcon(ctx, clients, "icon.png", "A001", "xoxe-token", tc.isHosted)
1794+
1795+
if tc.expectedError {
1796+
require.Error(t, err)
1797+
} else {
1798+
require.NoError(t, err)
1799+
}
1800+
1801+
if tc.expectIconSet {
1802+
clientsMock.API.AssertCalled(t, "IconSet", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything)
1803+
clientsMock.API.AssertNotCalled(t, "Icon")
1804+
} else if tc.expectIcon {
1805+
clientsMock.API.AssertCalled(t, "Icon", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything)
1806+
clientsMock.API.AssertNotCalled(t, "IconSet")
1807+
} else if tc.expectSkip {
1808+
clientsMock.API.AssertNotCalled(t, "Icon")
1809+
clientsMock.API.AssertNotCalled(t, "IconSet")
1810+
}
1811+
})
1812+
}
1813+
}

0 commit comments

Comments
 (0)