Socket spec tests

This commit is contained in:
Hein
2025-12-23 17:27:48 +02:00
parent 2dd404af96
commit 90df4a157c
4 changed files with 28 additions and 25 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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