Private
Public Access
1
0

Update SendMessage for new protocol

This commit is contained in:
2024-01-03 23:46:10 -08:00
parent d8ca07f92a
commit a8043e53b3
3 changed files with 7 additions and 16 deletions

View File

@@ -1,5 +1 @@
package web package web
type SendMessageResponse struct {
Guid string `json:"guid"`
}

View File

@@ -248,13 +248,8 @@ func (m *MockHTTPServer) handleSendMessage(w http.ResponseWriter, r *http.Reques
// Send message // Send message
m.Server.SendMessage(conversation, message) m.Server.SendMessage(conversation, message)
// Formulate response
sendMessageResp := SendMessageResponse{
Guid: message.Guid,
}
// Encode response as JSON // Encode response as JSON
jsonData, err := json.Marshal(sendMessageResp) jsonData, err := json.Marshal(message)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error marshalling response") log.Error().Err(err).Msg("Error marshalling response")
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)

View File

@@ -118,7 +118,7 @@ func TestMessages(t *testing.T) {
server.Server.AppendMessageToConversation(&conversation, message) server.Server.AppendMessageToConversation(&conversation, message)
resp, err := http.Get(httpServer.URL + "/messages?guid=" + *&conversation.Guid) resp, err := http.Get(httpServer.URL + "/messages?guid=" + conversation.Guid)
if err != nil { if err != nil {
t.Fatalf("TestMessages error: %s", err) t.Fatalf("TestMessages error: %s", err)
} }
@@ -237,7 +237,7 @@ func TestAuthentication(t *testing.T) {
} }
func TestUpdates(t *testing.T) { func TestUpdates(t *testing.T) {
s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: true}) s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: false})
httpServer := httptest.NewServer(s) httpServer := httptest.NewServer(s)
messageSeq := 0 messageSeq := 0
@@ -396,7 +396,7 @@ func TestUpdatesWebsocket(t *testing.T) {
} }
func TestMarkConversation(t *testing.T) { func TestMarkConversation(t *testing.T) {
s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: true}) s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: false})
httpServer := httptest.NewServer(s) httpServer := httptest.NewServer(s)
// Mock conversation // Mock conversation
@@ -439,7 +439,7 @@ func TestMarkConversation(t *testing.T) {
} }
func TestMessageQueries(t *testing.T) { func TestMessageQueries(t *testing.T) {
s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: true}) s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: false})
httpServer := httptest.NewServer(s) httpServer := httptest.NewServer(s)
// Mock conversation // Mock conversation
@@ -536,7 +536,7 @@ func TestMessageQueries(t *testing.T) {
} }
func TestSendMessage(t *testing.T) { func TestSendMessage(t *testing.T) {
s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: true}) s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: false})
httpServer := httptest.NewServer(s) httpServer := httptest.NewServer(s)
// Mock conversation // Mock conversation
@@ -578,7 +578,7 @@ func TestSendMessage(t *testing.T) {
t.Fatalf("Error decoding body: %s", body) t.Fatalf("Error decoding body: %s", body)
} }
var response web.SendMessageResponse var response model.Message
err = json.Unmarshal(body, &response) err = json.Unmarshal(body, &response)
if err != nil { if err != nil {
t.Fatalf("Error unmarshalling JSON: %s", err) t.Fatalf("Error unmarshalling JSON: %s", err)