From 90df4a157ce6fb067cf2c715c130ed2eb1feca16 Mon Sep 17 00:00:00 2001 From: Hein Date: Tue, 23 Dec 2025 17:27:48 +0200 Subject: [PATCH] Socket spec tests --- pkg/websocketspec/connection.go | 3 ++- pkg/websocketspec/handler.go | 7 +++--- pkg/websocketspec/message.go | 38 +++++++++++++++--------------- pkg/websocketspec/websocketspec.go | 5 ++-- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/pkg/websocketspec/connection.go b/pkg/websocketspec/connection.go index 05b5bee..b26d858 100644 --- a/pkg/websocketspec/connection.go +++ b/pkg/websocketspec/connection.go @@ -7,8 +7,9 @@ import ( "sync" "time" - "github.com/bitechdev/ResolveSpec/pkg/logger" "github.com/gorilla/websocket" + + "github.com/bitechdev/ResolveSpec/pkg/logger" ) // Connection rvepresents a WebSocket connection with its state diff --git a/pkg/websocketspec/handler.go b/pkg/websocketspec/handler.go index b61a5e1..757401d 100644 --- a/pkg/websocketspec/handler.go +++ b/pkg/websocketspec/handler.go @@ -9,11 +9,12 @@ import ( "strconv" "time" + "github.com/google/uuid" + "github.com/gorilla/websocket" + "github.com/bitechdev/ResolveSpec/pkg/common" "github.com/bitechdev/ResolveSpec/pkg/logger" "github.com/bitechdev/ResolveSpec/pkg/reflection" - "github.com/google/uuid" - "github.com/gorilla/websocket" ) // Handler handles WebSocket connections and messages @@ -467,7 +468,7 @@ func (h *Handler) handleUnsubscribe(conn *Connection, msg *Message) { // Send response resp := NewResponseMessage(msg.ID, true, map[string]interface{}{ - "unsubscribed": true, + "unsubscribed": true, "subscription_id": subID, }) conn.SendJSON(resp) diff --git a/pkg/websocketspec/message.go b/pkg/websocketspec/message.go index 6e009d9..6280c7b 100644 --- a/pkg/websocketspec/message.go +++ b/pkg/websocketspec/message.go @@ -103,14 +103,14 @@ type ErrorInfo struct { // RequestMessage represents a client request type RequestMessage struct { - ID string `json:"id"` - Type MessageType `json:"type"` - Operation OperationType `json:"operation"` - Schema string `json:"schema,omitempty"` - Entity string `json:"entity"` - RecordID string `json:"record_id,omitempty"` - Data interface{} `json:"data,omitempty"` - Options *common.RequestOptions `json:"options,omitempty"` + ID string `json:"id"` + Type MessageType `json:"type"` + Operation OperationType `json:"operation"` + Schema string `json:"schema,omitempty"` + Entity string `json:"entity"` + RecordID string `json:"record_id,omitempty"` + Data interface{} `json:"data,omitempty"` + Options *common.RequestOptions `json:"options,omitempty"` } // ResponseMessage represents a server response @@ -126,24 +126,24 @@ type ResponseMessage struct { // NotificationMessage represents a server-initiated notification type NotificationMessage struct { - Type MessageType `json:"type"` - Operation OperationType `json:"operation"` - SubscriptionID string `json:"subscription_id"` - Schema string `json:"schema"` - Entity string `json:"entity"` - Data interface{} `json:"data"` - Timestamp time.Time `json:"timestamp"` + Type MessageType `json:"type"` + Operation OperationType `json:"operation"` + SubscriptionID string `json:"subscription_id"` + Schema string `json:"schema"` + Entity string `json:"entity"` + Data interface{} `json:"data"` + Timestamp time.Time `json:"timestamp"` } // SubscriptionMessage represents a subscription control message type SubscriptionMessage struct { - ID string `json:"id"` - Type MessageType `json:"type"` + ID string `json:"id"` + Type MessageType `json:"type"` Operation OperationType `json:"operation"` // subscribe or unsubscribe Schema string `json:"schema,omitempty"` Entity string `json:"entity"` - Options *common.RequestOptions `json:"options,omitempty"` // Filters for subscription - SubscriptionID string `json:"subscription_id,omitempty"` // For unsubscribe + Options *common.RequestOptions `json:"options,omitempty"` // Filters for subscription + SubscriptionID string `json:"subscription_id,omitempty"` // For unsubscribe } // NewRequestMessage creates a new request message diff --git a/pkg/websocketspec/websocketspec.go b/pkg/websocketspec/websocketspec.go index b1522ef..5830dde 100644 --- a/pkg/websocketspec/websocketspec.go +++ b/pkg/websocketspec/websocketspec.go @@ -75,11 +75,12 @@ package websocketspec import ( + "github.com/uptrace/bun" + "gorm.io/gorm" + "github.com/bitechdev/ResolveSpec/pkg/common" "github.com/bitechdev/ResolveSpec/pkg/common/adapters/database" "github.com/bitechdev/ResolveSpec/pkg/modelregistry" - "github.com/uptrace/bun" - "gorm.io/gorm" ) // NewHandlerWithGORM creates a new Handler with GORM adapter