From ed2ebff9d377572664496fa5a347bd20229e150d Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Mon, 30 Mar 2026 21:08:01 +0200 Subject: [PATCH] ref(handler): fix return value from rpc.resp/error to rpc.resp --- core/handlers/create_note_handler.go | 2 +- core/handlers/handler.go | 2 +- .../create_note_handler_test.go | 26 ++++++++++++------- test/test_integration/main_test.go | 22 ++++++++++++---- test/test_vars.go | 16 ------------ 5 files changed, 36 insertions(+), 32 deletions(-) delete mode 100644 test/test_vars.go diff --git a/core/handlers/create_note_handler.go b/core/handlers/create_note_handler.go index 92b8d66..841a8ec 100644 --- a/core/handlers/create_note_handler.go +++ b/core/handlers/create_note_handler.go @@ -27,7 +27,7 @@ func NewCreateNoteHandler(uow *repositories.UnitOfWork) *CreateNoteHandler { return &CreateNoteHandler{uow: uow} } -func (h CreateNoteHandler) Handle(ctx context.Context, params []byte) (*rpc.Response, *rpc.Error) { +func (h CreateNoteHandler) Handle(ctx context.Context, params []byte) (*rpc.Response) { var cmd createNoteCommand if err := json.Unmarshal(params, &cmd); err != nil { diff --git a/core/handlers/handler.go b/core/handlers/handler.go index 6ba51a2..cde1d26 100644 --- a/core/handlers/handler.go +++ b/core/handlers/handler.go @@ -8,5 +8,5 @@ import ( ) type Handler interface { - Handle(ctx context.Context, raw json.RawMessage) (any, *rpc.Error) + Handle(ctx context.Context, raw json.RawMessage) (*rpc.Response) } diff --git a/test/test_integration/create_note_handler_test.go b/test/test_integration/create_note_handler_test.go index 15c67d9..dd4ae2f 100644 --- a/test/test_integration/create_note_handler_test.go +++ b/test/test_integration/create_note_handler_test.go @@ -2,19 +2,17 @@ package integration_test import ( "database/sql" + "encoding/json" "testing" "github.com/KristianJBorgwarth/dendrite.daemon/core/handlers" "github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories" - "github.com/KristianJBorgwarth/dendrite.daemon/test" ) - func TestCreateNoteHandlerOnSucess(t *testing.T) { - // Arrange // TODO: move to test vars and main_test.go - db, err := sql.Open("sqlite", test.NewTestVars().DbPath) + db, err := sql.Open("sqlite", DbPath) if err != nil { t.Fatalf("failed to open database: %v", err) } @@ -24,11 +22,21 @@ func TestCreateNoteHandlerOnSucess(t *testing.T) { handler := handlers.NewCreateNoteHandler(uow) - // TODO: add to test vars and move to main_test.go - ctx := test.Context() + requestParams := struct { + Title string `json:"title"` + Content string `json:"content"` + }{ + Title: "Test Note", + Content: "This is a test note.", + } + + requestParamsBytes, err := json.Marshal(requestParams) + if err != nil { + t.Fatalf("failed to marshal request params: %v", err) + } + + request := CreateTestRequest("createNote", 1, requestParamsBytes) // Act - - - // Assert + response, rpcError = handler.Handle(TestContext, request.Params) } diff --git a/test/test_integration/main_test.go b/test/test_integration/main_test.go index 13570a2..9b8515e 100644 --- a/test/test_integration/main_test.go +++ b/test/test_integration/main_test.go @@ -1,25 +1,37 @@ package integration_test import ( + "context" + "encoding/json" "os" "testing" + "github.com/KristianJBorgwarth/dendrite.daemon/core/rpc" "github.com/KristianJBorgwarth/dendrite.daemon/persistence" - "github.com/KristianJBorgwarth/dendrite.daemon/test" ) +var DbPath string = os.TempDir() + "/dendrite_test_vault" +var TestContext = context.Background() + func TestMain(m *testing.M) { - dbPath := test.NewTestVars().DbPath - - err := persistence.InitializeIndex(dbPath) + err := persistence.InitializeIndex(DbPath) if err != nil { panic(err) } code := m.Run() - os.RemoveAll(dbPath) + os.RemoveAll(DbPath) os.Exit(code) } + +func CreateTestRequest(method string, ID int, params json.RawMessage) *rpc.Request { + return &rpc.Request{ + Jsonrpc: "2.0", + ID: &ID, + Method: method, + Params: params, + } +} diff --git a/test/test_vars.go b/test/test_vars.go deleted file mode 100644 index 1ad4977..0000000 --- a/test/test_vars.go +++ /dev/null @@ -1,16 +0,0 @@ -package test - -import "os" - -// todo: move into main_test.go and add utility functions in there -type TestVars struct { - DbPath string -} - -func NewTestVars() *TestVars { - return &TestVars{ - DbPath: os.TempDir() + "/dendrite_test_vault", - } -} - -