diff --git a/db/bolt/view_test.go b/db/bolt/view_test.go index edb5dd67..180b9b88 100644 --- a/db/bolt/view_test.go +++ b/db/bolt/view_test.go @@ -1,10 +1,11 @@ package bolt import ( - "github.com/semaphoreui/semaphore/db" "sort" "testing" "time" + + "github.com/semaphoreui/semaphore/db" ) func TestGetViews(t *testing.T) { @@ -127,3 +128,143 @@ func TestSetViewPositions(t *testing.T) { t.Fatal() } } +func TestGetView(t *testing.T) { + store := CreateTestStore() + + proj1, err := store.CreateProject(db.Project{ + Created: time.Now(), + Name: "Test1", + }) + + if err != nil { + t.Fatal(err.Error()) + } + + view, err := store.CreateView(db.View{ + ProjectID: proj1.ID, + Title: "Test", + Position: 1, + }) + + if err != nil { + t.Fatal(err.Error()) + } + + found, err := store.GetView(proj1.ID, view.ID) + + if err != nil { + t.Fatal(err.Error()) + } + + if found.ID != view.ID || found.Title != view.Title || found.Position != view.Position { + t.Fatal() + } +} + +func TestUpdateView(t *testing.T) { + store := CreateTestStore() + + proj1, err := store.CreateProject(db.Project{ + Created: time.Now(), + Name: "Test1", + }) + + if err != nil { + t.Fatal(err.Error()) + } + + view, err := store.CreateView(db.View{ + ProjectID: proj1.ID, + Title: "Test", + Position: 1, + }) + + if err != nil { + t.Fatal(err.Error()) + } + + view.Title = "Updated Test" + err = store.UpdateView(view) + + if err != nil { + t.Fatal(err.Error()) + } + + updatedView, err := store.GetView(proj1.ID, view.ID) + + if err != nil { + t.Fatal(err.Error()) + } + + if updatedView.Title != "Updated Test" { + t.Fatal() + } +} + +func TestCreateView(t *testing.T) { + store := CreateTestStore() + + proj1, err := store.CreateProject(db.Project{ + Created: time.Now(), + Name: "Test1", + }) + + if err != nil { + t.Fatal(err.Error()) + } + + view, err := store.CreateView(db.View{ + ProjectID: proj1.ID, + Title: "Test", + Position: 1, + }) + + if err != nil { + t.Fatal(err.Error()) + } + + found, err := store.GetView(proj1.ID, view.ID) + + if err != nil { + t.Fatal(err.Error()) + } + + if found.ID != view.ID || found.Title != view.Title || found.Position != view.Position { + t.Fatal() + } +} + +func TestDeleteView(t *testing.T) { + store := CreateTestStore() + + proj1, err := store.CreateProject(db.Project{ + Created: time.Now(), + Name: "Test1", + }) + + if err != nil { + t.Fatal(err.Error()) + } + + view, err := store.CreateView(db.View{ + ProjectID: proj1.ID, + Title: "Test", + Position: 1, + }) + + if err != nil { + t.Fatal(err.Error()) + } + + err = store.DeleteView(proj1.ID, view.ID) + + if err != nil { + t.Fatal(err.Error()) + } + + _, err = store.GetView(proj1.ID, view.ID) + + if err == nil { + t.Fatal("Expected error, got nil") + } +}