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" "sync"
"time" "time"
"github.com/bitechdev/ResolveSpec/pkg/logger"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/bitechdev/ResolveSpec/pkg/logger"
) )
// Connection rvepresents a WebSocket connection with its state // Connection rvepresents a WebSocket connection with its state

View File

@@ -9,11 +9,12 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/google/uuid"
"github.com/gorilla/websocket"
"github.com/bitechdev/ResolveSpec/pkg/common" "github.com/bitechdev/ResolveSpec/pkg/common"
"github.com/bitechdev/ResolveSpec/pkg/logger" "github.com/bitechdev/ResolveSpec/pkg/logger"
"github.com/bitechdev/ResolveSpec/pkg/reflection" "github.com/bitechdev/ResolveSpec/pkg/reflection"
"github.com/google/uuid"
"github.com/gorilla/websocket"
) )
// Handler handles WebSocket connections and messages // Handler handles WebSocket connections and messages
@@ -467,7 +468,7 @@ func (h *Handler) handleUnsubscribe(conn *Connection, msg *Message) {
// Send response // Send response
resp := NewResponseMessage(msg.ID, true, map[string]interface{}{ resp := NewResponseMessage(msg.ID, true, map[string]interface{}{
"unsubscribed": true, "unsubscribed": true,
"subscription_id": subID, "subscription_id": subID,
}) })
conn.SendJSON(resp) conn.SendJSON(resp)

View File

@@ -103,14 +103,14 @@ type ErrorInfo struct {
// RequestMessage represents a client request // RequestMessage represents a client request
type RequestMessage struct { type RequestMessage struct {
ID string `json:"id"` ID string `json:"id"`
Type MessageType `json:"type"` Type MessageType `json:"type"`
Operation OperationType `json:"operation"` Operation OperationType `json:"operation"`
Schema string `json:"schema,omitempty"` Schema string `json:"schema,omitempty"`
Entity string `json:"entity"` Entity string `json:"entity"`
RecordID string `json:"record_id,omitempty"` RecordID string `json:"record_id,omitempty"`
Data interface{} `json:"data,omitempty"` Data interface{} `json:"data,omitempty"`
Options *common.RequestOptions `json:"options,omitempty"` Options *common.RequestOptions `json:"options,omitempty"`
} }
// ResponseMessage represents a server response // ResponseMessage represents a server response
@@ -126,24 +126,24 @@ type ResponseMessage struct {
// NotificationMessage represents a server-initiated notification // NotificationMessage represents a server-initiated notification
type NotificationMessage struct { type NotificationMessage struct {
Type MessageType `json:"type"` Type MessageType `json:"type"`
Operation OperationType `json:"operation"` Operation OperationType `json:"operation"`
SubscriptionID string `json:"subscription_id"` SubscriptionID string `json:"subscription_id"`
Schema string `json:"schema"` Schema string `json:"schema"`
Entity string `json:"entity"` Entity string `json:"entity"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
Timestamp time.Time `json:"timestamp"` Timestamp time.Time `json:"timestamp"`
} }
// SubscriptionMessage represents a subscription control message // SubscriptionMessage represents a subscription control message
type SubscriptionMessage struct { type SubscriptionMessage struct {
ID string `json:"id"` ID string `json:"id"`
Type MessageType `json:"type"` Type MessageType `json:"type"`
Operation OperationType `json:"operation"` // subscribe or unsubscribe Operation OperationType `json:"operation"` // subscribe or unsubscribe
Schema string `json:"schema,omitempty"` Schema string `json:"schema,omitempty"`
Entity string `json:"entity"` Entity string `json:"entity"`
Options *common.RequestOptions `json:"options,omitempty"` // Filters for subscription Options *common.RequestOptions `json:"options,omitempty"` // Filters for subscription
SubscriptionID string `json:"subscription_id,omitempty"` // For unsubscribe SubscriptionID string `json:"subscription_id,omitempty"` // For unsubscribe
} }
// NewRequestMessage creates a new request message // NewRequestMessage creates a new request message

View File

@@ -75,11 +75,12 @@
package websocketspec package websocketspec
import ( import (
"github.com/uptrace/bun"
"gorm.io/gorm"
"github.com/bitechdev/ResolveSpec/pkg/common" "github.com/bitechdev/ResolveSpec/pkg/common"
"github.com/bitechdev/ResolveSpec/pkg/common/adapters/database" "github.com/bitechdev/ResolveSpec/pkg/common/adapters/database"
"github.com/bitechdev/ResolveSpec/pkg/modelregistry" "github.com/bitechdev/ResolveSpec/pkg/modelregistry"
"github.com/uptrace/bun"
"gorm.io/gorm"
) )
// NewHandlerWithGORM creates a new Handler with GORM adapter // NewHandlerWithGORM creates a new Handler with GORM adapter