fix: reconcile shared-channel receipts and protocol logs
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package inbound
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSubmitResponseProtocolLoggerEmitsActualPacketDirection(t *testing.T) {
|
||||
events := make(chan protocolLogEvent, 1)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/gateway/events/protocol-log" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
var event protocolLogEvent
|
||||
if err := json.NewDecoder(r.Body).Decode(&event); err != nil {
|
||||
t.Fatalf("decode event: %v", err)
|
||||
}
|
||||
events <- event
|
||||
_ = json.NewEncoder(w).Encode(map[string]bool{"accepted": true})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
gateway := Server{APIBaseURL: server.URL + "/api", HTTPClient: server.Client()}
|
||||
gateway.submitResponseProtocolLogger(
|
||||
"607532",
|
||||
"cmpp20",
|
||||
141,
|
||||
"13127620092",
|
||||
"MSG-LONG-1",
|
||||
736070227905294338,
|
||||
0,
|
||||
)(nil)
|
||||
|
||||
select {
|
||||
case event := <-events:
|
||||
if event.Protocol != "cmpp" || event.Direction != "platform_to_client" || event.EventType != "submit_resp" {
|
||||
t.Fatalf("unexpected protocol event: %+v", event)
|
||||
}
|
||||
if event.Account != "607532" || event.MessageID != "MSG-LONG-1" || event.ResultCode != "0" {
|
||||
t.Fatalf("unexpected identifiers: %+v", event)
|
||||
}
|
||||
if event.Detail["sequenceId"] != float64(141) && event.Detail["sequenceId"] != uint32(141) {
|
||||
t.Fatalf("sequenceId = %#v", event.Detail["sequenceId"])
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("timed out waiting for protocol event")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user