diff --git a/core/handlers/create_note_handler.go b/core/handlers/create_note_handler.go index 8a71ccb..92b8d66 100644 --- a/core/handlers/create_note_handler.go +++ b/core/handlers/create_note_handler.go @@ -20,7 +20,11 @@ type createNoteCommand struct { } type CreateNoteHandler struct { - uow repositories.UnitOfWork + uow *repositories.UnitOfWork +} + +func NewCreateNoteHandler(uow *repositories.UnitOfWork) *CreateNoteHandler { + return &CreateNoteHandler{uow: uow} } func (h CreateNoteHandler) Handle(ctx context.Context, params []byte) (*rpc.Response, *rpc.Error) { diff --git a/test/test_integration/create_note_handler_test.go b/test/test_integration/create_note_handler_test.go index 2e5e96b..55be5d7 100644 --- a/test/test_integration/create_note_handler_test.go +++ b/test/test_integration/create_note_handler_test.go @@ -1,7 +1,28 @@ package integration_test -import "testing" +import ( + "database/sql" + "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 + db, err := sql.Open("sqlite", test.NewTestVars().DbPath) + if err != nil { + t.Fatalf("failed to open database: %v", err) + } + defer db.Close() + uow := repositories.NewUnitOfWork(db) + + handler := handlers.NewCreateNoteHandler(uow) + + // Act + + // Assert } diff --git a/test/test_integration/main_test.go b/test/test_integration/main_test.go index 107c9af..13570a2 100644 --- a/test/test_integration/main_test.go +++ b/test/test_integration/main_test.go @@ -3,21 +3,23 @@ package integration_test import ( "os" "testing" + "github.com/KristianJBorgwarth/dendrite.daemon/persistence" + "github.com/KristianJBorgwarth/dendrite.daemon/test" ) func TestMain(m *testing.M) { - currentDir := os.TempDir() + "/dendrite_test_vault" + dbPath := test.NewTestVars().DbPath - err := persistence.InitializeIndex(currentDir) + err := persistence.InitializeIndex(dbPath) if err != nil { panic(err) } code := m.Run() - os.RemoveAll(currentDir) + os.RemoveAll(dbPath) os.Exit(code) } diff --git a/test/test_vars.go b/test/test_vars.go new file mode 100644 index 0000000..01305d3 --- /dev/null +++ b/test/test_vars.go @@ -0,0 +1,14 @@ +package test + +import "os" + +type TestVars struct { + DbPath string +} + +func NewTestVars() *TestVars { + return &TestVars{ + DbPath: os.TempDir() + "/dendrite_test_vault", + } +} +