ref(handler): fix return value from rpc.resp/error to rpc.resp
This commit is contained in:
parent
950f9098ab
commit
ed2ebff9d3
5 changed files with 36 additions and 32 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue