MCPcopy Create free account
hub / github.com/asternic/wuzapi / TestChatSendText

Function TestChatSendText

stdio_test.go:245–285  ·  view source on GitHub ↗

Note: session.connect, session.disconnect, session.logout tests are skipped because they require full WhatsApp/whatsmeow initialization which is complex to set up in unit tests. The routing is tested via session.status. Manual/integration testing should be used for these methods.

(t *testing.T)

Source from the content-addressed store, hash-verified

243// Manual/integration testing should be used for these methods.
244
245func TestChatSendText(t *testing.T) {
246 s := makeTestServer(t)
247
248 // Create a user first
249 addRequest := newRequest("1", "admin.users.add", map[string]interface{}{
250 "adminToken": "test-admin-token",
251 "name": "MessageUser",
252 "token": "message-token",
253 }).toJSON(t)
254 executeRequest(t, s, addRequest)
255
256 // Try to send a message (will fail because no WhatsApp session, but tests routing)
257 sendRequest := newRequest("2", "chat.send.text", map[string]interface{}{
258 "token": "message-token",
259 "Phone": "1234567890",
260 "Body": "Hello, World!",
261 }).toJSON(t)
262 sendResponse := executeRequest(t, s, sendRequest)
263
264 // Should fail with "no session" error since we don't have WhatsApp initialized
265 expected := map[string]interface{}{
266 "jsonrpc": "2.0",
267 "id": "2",
268 }
269 if diff := compareJSON(expected, sendResponse); diff != "" {
270 t.Errorf("Response mismatch:\n%s", diff)
271 }
272
273 // Verify it's an error response
274 if sendResponse["error"] == nil {
275 t.Errorf("Expected error (no session), got success")
276 }
277 if sendResponse["result"] != nil {
278 t.Errorf("Expected no result on error, got: %v", sendResponse["result"])
279 }
280
281 errorObj := sendResponse["error"].(map[string]interface{})
282 if errorObj["code"].(float64) != 500 {
283 t.Errorf("Expected error code 500 (no session), got %v", errorObj["code"])
284 }
285}
286
287func TestChatHistory(t *testing.T) {
288 s := makeTestServer(t)

Callers

nothing calls this directly

Calls 5

makeTestServerFunction · 0.85
newRequestFunction · 0.85
executeRequestFunction · 0.85
compareJSONFunction · 0.85
toJSONMethod · 0.80

Tested by

no test coverage detected