fix(test): new di setup for integration tests

This commit is contained in:
Kristian Borgwarth 2026-04-12 02:54:17 +02:00
parent 7127168006
commit 9781268485

View file

@ -7,13 +7,22 @@ import (
"testing"
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/note"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func newCreateNoteHandler() *note.CreateNoteHandler {
return note.NewCreateNoteHandler(
repositories.NewUnitOfWork(),
repositories.NewTagRepository(),
repositories.NewNoteRepository(),
)
}
func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T) {
// Arrange
handler := note.NewCreateNoteHandler()
handler := newCreateNoteHandler()
vaultPath := Fixture.VaultStore.Config.VaultPath()
notePath := filepath.Join(vaultPath, "my-note.md")
@ -40,7 +49,7 @@ func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T
func TestCreateNoteHandler_WithTemplate_CreatesNoteFileWithTagsAndReturnsPath(t *testing.T) {
// Arrange
handler := note.NewCreateNoteHandler()
handler := newCreateNoteHandler()
vaultPath := Fixture.VaultStore.Config.VaultPath()
templateDir := Fixture.VaultStore.Config.TemplateDirectory()
@ -89,7 +98,7 @@ func TestCreateNoteHandler_WithTemplate_CreatesNoteFileWithTagsAndReturnsPath(t
func TestCreateNoteHandler_DuplicateSlug_Upserts(t *testing.T) {
// Arrange
handler := note.NewCreateNoteHandler()
handler := newCreateNoteHandler()
vaultPath := Fixture.VaultStore.Config.VaultPath()
subDir := "dup-dir"
@ -123,7 +132,7 @@ func TestCreateNoteHandler_DuplicateSlug_Upserts(t *testing.T) {
func TestCreateNoteHandler_InvalidJSON_ReturnsError(t *testing.T) {
// Arrange
handler := note.NewCreateNoteHandler()
handler := newCreateNoteHandler()
// Act
_, err := handler.Handle(Fixture.TestContext, json.RawMessage(`{invalid json}`))
@ -134,7 +143,7 @@ func TestCreateNoteHandler_InvalidJSON_ReturnsError(t *testing.T) {
func TestCreateNoteHandler_NonExistentTemplateName_ReturnsError(t *testing.T) {
// Arrange
handler := note.NewCreateNoteHandler()
handler := newCreateNoteHandler()
params, _ := json.Marshal(map[string]any{
"title": "Ghost Note",