Introduced comprehensive test coverage for `socketapi` functions, including `handleEvent` and `handleReq` logic. Enhanced `publisher` and `handleEvent` to ensure better filter and event validation, and made minor bug fixes to public key matching logic.
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package socketapi
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"realy.lol/context"
|
|
"realy.lol/envelopes/eventenvelope"
|
|
"realy.lol/event"
|
|
"realy.lol/kind"
|
|
)
|
|
|
|
func TestA_HandleEvent_NoStorage(t *testing.T) {
|
|
mockServer := &MockServer{}
|
|
mockServer.On("Storage").Return(nil)
|
|
|
|
a := &A{Server: mockServer}
|
|
|
|
// Create a simple event envelope
|
|
env := eventenvelope.NewSubmission()
|
|
msg := env.Marshal(nil)
|
|
|
|
// This should panic because no storage is set
|
|
assert.Panics(t, func() {
|
|
a.HandleEvent(context.Bg(), msg, mockServer, "127.0.0.1")
|
|
})
|
|
|
|
mockServer.AssertExpectations(t)
|
|
}
|
|
|
|
func TestA_HandleRejectEvent_WithMute(t *testing.T) {
|
|
// Test that mute notices are handled correctly
|
|
// Test with mute notice
|
|
notice := "mute: user blocked"
|
|
assert.Contains(t, notice, "mute")
|
|
|
|
// Test without mute notice
|
|
notice2 := "invalid event"
|
|
assert.NotContains(t, notice2, "mute")
|
|
}
|
|
|
|
func TestA_ProcessDelete_TimestampComparison(t *testing.T) {
|
|
// Test timestamp comparison logic
|
|
target := event.New()
|
|
target.CreatedAtFromInt64(1000)
|
|
|
|
deleteEvent := event.New()
|
|
deleteEvent.CreatedAtFromInt64(500)
|
|
|
|
// Delete event is older, should skip
|
|
assert.True(t, target.CreatedAt.Int() > deleteEvent.CreatedAt.Int())
|
|
|
|
// Test with newer delete event
|
|
deleteEvent2 := event.New()
|
|
deleteEvent2.CreatedAtFromInt64(1500)
|
|
|
|
assert.True(t, deleteEvent2.CreatedAt.Int() > target.CreatedAt.Int())
|
|
}
|
|
|
|
func TestA_ProcessDelete_AuthorComparison(t *testing.T) {
|
|
// Test author comparison logic
|
|
target := event.New()
|
|
target.Pubkey = []byte("author1")
|
|
|
|
deleteEvent := event.New()
|
|
deleteEvent.Pubkey = []byte("author1")
|
|
|
|
// Same author
|
|
assert.Equal(t, target.Pubkey, deleteEvent.Pubkey)
|
|
|
|
// Different author
|
|
deleteEvent2 := event.New()
|
|
deleteEvent2.Pubkey = []byte("author2")
|
|
|
|
assert.NotEqual(t, target.Pubkey, deleteEvent2.Pubkey)
|
|
}
|
|
|
|
func TestKindDeletion(t *testing.T) {
|
|
// Test deletion kind
|
|
ev := event.New()
|
|
ev.Kind = kind.Deletion
|
|
|
|
assert.Equal(t, kind.Deletion, ev.Kind)
|
|
assert.True(t, ev.Kind.Equal(kind.Deletion))
|
|
}
|