From e37d4112aeca0eaa1a2b32cabc6d8735094aefd5 Mon Sep 17 00:00:00 2001 From: elraphty Date: Thu, 28 Nov 2024 18:24:48 +0100 Subject: [PATCH] fixed merge conflicts --- db/interface.go | 1 + db/tickets.go | 19 ++++++++ db/tickets_test.go | 108 +++++++++++++++++++++++++++++++++++++++++++++ mocks/Database.go | 58 ++++++++++++++++++++++++ 4 files changed, 186 insertions(+) diff --git a/db/interface.go b/db/interface.go index 0e050fe12..df554abc7 100644 --- a/db/interface.go +++ b/db/interface.go @@ -199,4 +199,5 @@ type Database interface { UpdateTicket(ticket Tickets) (Tickets, error) DeleteTicket(uuid string) error GetTicketsByPhaseUUID(featureUUID string, phaseUUID string) ([]Tickets, error) + GetTicketsByPhase(phaseUUID string) ([]Tickets, error) } diff --git a/db/tickets.go b/db/tickets.go index 2d0375483..3b3181ba2 100644 --- a/db/tickets.go +++ b/db/tickets.go @@ -100,3 +100,22 @@ func (db database) DeleteTicket(uuid string) error { } return nil } + +func (db database) GetTicketsByPhase(phaseUUID string) ([]Tickets, error) { + var tickets []Tickets + + result := db.db.Where("phase_uuid = ?", phaseUUID). + Order("sequence ASC"). + Find(&tickets) + + if result.Error != nil { + return nil, fmt.Errorf("failed to fetch tickets for phase: %w", result.Error) + } + + // Return empty slice if no tickets found + if result.RowsAffected == 0 { + return []Tickets{}, nil + } + + return tickets, nil +} diff --git a/db/tickets_test.go b/db/tickets_test.go index 90e9aaa73..642090802 100644 --- a/db/tickets_test.go +++ b/db/tickets_test.go @@ -223,3 +223,111 @@ func TestGetTicket(t *testing.T) { } }) } + +func TestGetTicketsByPhase(t *testing.T) { // create person + InitTestDB() + + // create person + now := time.Now() + + person := Person{ + Uuid: uuid.New().String(), + OwnerPubKey: "testfeaturepubkey", + OwnerAlias: "testfeaturealias", + Description: "testfeaturedescription", + Created: &now, + Updated: &now, + Deleted: false, + } + + // create person + TestDB.CreateOrEditPerson(person) + + workspace := Workspace{ + Uuid: uuid.New().String(), + Name: "Test tickets space", + Created: &now, + Updated: &now, + } + + // create workspace + TestDB.CreateOrEditWorkspace(workspace) + + workspaceFeatures := WorkspaceFeatures{ + Uuid: uuid.New().String(), + WorkspaceUuid: workspace.Uuid, + Name: "test", + Brief: "test get brief", + Requirements: "Test get requirements", + Architecture: "Test get architecture", + Url: "Test get url", + Priority: 1, + Created: &now, + Updated: &now, + CreatedBy: "test", + UpdatedBy: "test", + } + + // create WorkspaceFeatures + TestDB.CreateOrEditFeature(workspaceFeatures) + + featurePhase := FeaturePhase{ + Uuid: uuid.New().String(), + FeatureUuid: workspaceFeatures.Uuid, + Name: "test get feature phase", + Priority: 1, + Created: &now, + Updated: &now, + } + + // create FeaturePhase + TestDB.CreateOrEditFeaturePhase(featurePhase) + + ticket := Tickets{ + UUID: uuid.New(), + FeatureUUID: workspaceFeatures.Uuid, + PhaseUUID: featurePhase.Uuid, + Name: "test get tickets 1", + CreatedAt: now, + UpdatedAt: now, + } + + // create ticket + TestDB.CreateOrEditTicket(&ticket) + + ticket2 := Tickets{ + UUID: uuid.New(), + FeatureUUID: workspaceFeatures.Uuid, + PhaseUUID: featurePhase.Uuid, + Name: "test get tickets 2", + CreatedAt: now, + UpdatedAt: now, + } + + // create ticket + TestDB.CreateOrEditTicket(&ticket2) + + // should return an empty slice if no tickets are found for the phase + t.Run("should return an empty slice if no tickets are found for the phase", func(t *testing.T) { + result, err := TestDB.GetTicketsByPhase(uuid.New().String()) + if err != nil { + t.Errorf("expected no error but got %v", err) + } + + if len(result) != 0 { + t.Errorf("expected an empty slice but got %v", result) + } + }) + + // should return a slice of tickets if the phase exists + t.Run("should return a slice of tickets if the phase exists", func(t *testing.T) { + result, err := TestDB.GetTicketsByPhase(featurePhase.Uuid) + if err != nil { + t.Errorf("expected no error but got %v", err) + } + + if len(result) != 2 { + t.Errorf("expected 2 tickets but got %v", len(result)) + } + }) +} diff --git a/mocks/Database.go b/mocks/Database.go index cc4a1c686..5b667abc3 100644 --- a/mocks/Database.go +++ b/mocks/Database.go @@ -5589,6 +5589,64 @@ func (_c *Database_GetTicket_Call) RunAndReturn(run func(string) (db.Tickets, er return _c } +// GetTicketsByPhase provides a mock function with given fields: phaseUUID +func (_m *Database) GetTicketsByPhase(phaseUUID string) ([]db.Tickets, error) { + ret := _m.Called(phaseUUID) + + if len(ret) == 0 { + panic("no return value specified for GetTicketsByPhase") + } + + var r0 []db.Tickets + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]db.Tickets, error)); ok { + return rf(phaseUUID) + } + if rf, ok := ret.Get(0).(func(string) []db.Tickets); ok { + r0 = rf(phaseUUID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]db.Tickets) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(phaseUUID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Database_GetTicketsByPhase_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTicketsByPhase' +type Database_GetTicketsByPhase_Call struct { + *mock.Call +} + +// GetTicketsByPhase is a helper method to define mock.On call +// - phaseUUID string +func (_e *Database_Expecter) GetTicketsByPhase(phaseUUID interface{}) *Database_GetTicketsByPhase_Call { + return &Database_GetTicketsByPhase_Call{Call: _e.mock.On("GetTicketsByPhase", phaseUUID)} +} + +func (_c *Database_GetTicketsByPhase_Call) Run(run func(phaseUUID string)) *Database_GetTicketsByPhase_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Database_GetTicketsByPhase_Call) Return(_a0 []db.Tickets, _a1 error) *Database_GetTicketsByPhase_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Database_GetTicketsByPhase_Call) RunAndReturn(run func(string) ([]db.Tickets, error)) *Database_GetTicketsByPhase_Call { + _c.Call.Return(run) + return _c +} + // GetTribe provides a mock function with given fields: uuid func (_m *Database) GetTribe(uuid string) db.Tribe { ret := _m.Called(uuid)