Skip to content

Commit 6bee5f7

Browse files
author
Ada
committed
fix: Update tests for compatibility with main branch
- Rebase onto main (includes cli_process.go, message_store.go, output_handler.go) - Fix setupPlugin to set configuration with BridgeServerURL (forces bridge mode) - Update test expectations to match new behavior: - Approval/rejection messages no longer include emoji - formatDuration now returns human-readable format instead of timestamp - Status command shows formatted output even with bridge failures - Default ClaudeCodePath is 'claude' not empty string - Plugin ID changed from com.appsome to co.appsome - Fix LogError mock to accept 5 arguments (key-value pairs) - Add time import to commands_test.go - All 44 tests passing, coverage 43.6%
1 parent 43114c3 commit 6bee5f7

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

server/actions_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func setupPlugin() *Plugin {
1818
p := &Plugin{
1919
botUserID: "bot_id",
2020
bridgeClient: NewBridgeClient("http://localhost:3001", nil),
21+
configuration: &configuration{
22+
BridgeServerURL: "http://localhost:3001",
23+
},
2124
}
2225
return p
2326
}
@@ -102,7 +105,7 @@ func TestHandleApprove_Success(t *testing.T) {
102105

103106
var response model.PostActionIntegrationResponse
104107
json.NewDecoder(w.Body).Decode(&response)
105-
assert.Contains(t, response.Update.Message, "Changes approved")
108+
assert.Contains(t, response.Update.Message, "Changes approved")
106109
}
107110

108111
func TestHandleApprove_InvalidRequest(t *testing.T) {
@@ -215,7 +218,7 @@ func TestHandleReject_Success(t *testing.T) {
215218

216219
var response model.PostActionIntegrationResponse
217220
json.NewDecoder(w.Body).Decode(&response)
218-
assert.Contains(t, response.Update.Message, "Changes rejected")
221+
assert.Contains(t, response.Update.Message, "Changes rejected")
219222
}
220223

221224
func TestHandleModify_Success(t *testing.T) {

server/commands_test.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"strings"
66
"testing"
7+
"time"
78

89
"github.com/mattermost/mattermost/server/public/model"
910
"github.com/mattermost/mattermost/server/public/plugin/plugintest"
@@ -198,18 +199,25 @@ func TestExecuteCommand_InvalidCommand(t *testing.T) {
198199
}
199200

200201
func TestFormatDuration(t *testing.T) {
201-
// Test with a specific timestamp
202-
timestamp := int64(1678901234)
203-
result := formatDuration(timestamp)
204-
assert.Equal(t, "<t:1678901234:R>", result)
205-
206-
// Test with zero timestamp
207-
result = formatDuration(0)
208-
assert.Equal(t, "<t:0:R>", result)
209-
210-
// Test with negative timestamp
211-
result = formatDuration(-1000)
212-
assert.Equal(t, "<t:-1000:R>", result)
202+
// Test with a recent timestamp (less than a minute ago)
203+
recentTimestamp := time.Now().Add(-30 * time.Second).Unix()
204+
result := formatDuration(recentTimestamp)
205+
assert.Contains(t, result, "seconds ago")
206+
207+
// Test with a timestamp from a few minutes ago
208+
minutesAgo := time.Now().Add(-5 * time.Minute).Unix()
209+
result = formatDuration(minutesAgo)
210+
assert.Contains(t, result, "minutes ago")
211+
212+
// Test with a timestamp from a few hours ago
213+
hoursAgo := time.Now().Add(-3 * time.Hour).Unix()
214+
result = formatDuration(hoursAgo)
215+
assert.Contains(t, result, "hours ago")
216+
217+
// Test with a timestamp from days ago
218+
daysAgo := time.Now().Add(-2 * 24 * time.Hour).Unix()
219+
result = formatDuration(daysAgo)
220+
assert.Contains(t, result, "days ago")
213221
}
214222

215223
func TestFormatPID(t *testing.T) {
@@ -286,8 +294,8 @@ func TestExecuteClaudeStatus_WithActiveSession(t *testing.T) {
286294
response, appErr := p.ExecuteCommand(nil, args)
287295
assert.Nil(t, appErr)
288296
assert.NotNil(t, response)
289-
// Without a working bridge, it should show an error
290-
assert.Contains(t, response.Text, "Failed to get session details")
297+
// Should show session status (even if bridge details fail)
298+
assert.Contains(t, response.Text, "Session Status")
291299
}
292300

293301
func TestExecuteClaudeThread_InvalidAction(t *testing.T) {

server/configuration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestGetConfiguration_Nil(t *testing.T) {
4040

4141
assert.NotNil(t, config)
4242
assert.Equal(t, "", config.BridgeServerURL)
43-
assert.Equal(t, "", config.ClaudeCodePath)
43+
assert.Equal(t, "claude", config.ClaudeCodePath)
4444
assert.Equal(t, false, config.EnableFileOperations)
4545
}
4646

server/post_utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,5 @@ func TestGetPluginURL(t *testing.T) {
144144
defer api.AssertExpectations(t)
145145

146146
url := p.getPluginURL()
147-
assert.Equal(t, "http://localhost:8065/plugins/com.appsome.claudecode", url)
147+
assert.Equal(t, "http://localhost:8065/plugins/co.appsome.claudecode", url)
148148
}

server/websocket_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func TestPostBotMessage_Error(t *testing.T) {
288288
message := "test message"
289289

290290
api.On("CreatePost", mock.Anything).Return(nil, model.NewAppError("CreatePost", "error", nil, "", 500))
291-
api.On("LogError", mock.Anything, mock.Anything, mock.Anything).Return()
291+
api.On("LogError", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
292292

293293
p.postBotMessage(channelID, message)
294294
}

0 commit comments

Comments
 (0)