Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Adds test to check work item link deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
DhritiShikhar committed Oct 10, 2018
1 parent 1b07bad commit 37e2d35
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
6 changes: 3 additions & 3 deletions controller/workitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ func (c *WorkitemController) Delete(ctx *app.DeleteWorkitemContext) error {
}

err = application.Transactional(c.db, func(appl application.Application) error {
if err := appl.WorkItems().Delete(ctx, ctx.WiID, *currentUserIdentityID); err != nil {
return errs.Wrapf(err, "error deleting work item %s", ctx.WiID)
}
if err := appl.WorkItemLinks().DeleteRelatedLinks(ctx, ctx.WiID, *currentUserIdentityID); err != nil {
return errs.Wrapf(err, "failed to delete work item links related to work item %s", ctx.WiID)
}
if err := appl.WorkItems().Delete(ctx, ctx.WiID, *currentUserIdentityID); err != nil {
return errs.Wrapf(err, "error deleting work item %s", ctx.WiID)
}
return nil
})
if err != nil {
Expand Down
50 changes: 33 additions & 17 deletions controller/workitem_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
tf "github.com/fabric8-services/fabric8-wit/test/testfixture"
"github.com/fabric8-services/fabric8-wit/test/token"
"github.com/fabric8-services/fabric8-wit/workitem"
"github.com/fabric8-services/fabric8-wit/workitem/link"
errs "github.com/pkg/errors"

"github.com/goadesign/goa"
Expand Down Expand Up @@ -3383,23 +3384,38 @@ func (s *WorkItem2Suite) TestCreateAndUpdateWorkItemForEveryWIT() {
}

func (s *WorkItem2Suite) TestDeleteWorkitem() {
s.T().Run("ok", func(t *testing.T) {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.WorkItems(1))
s.svc = testsupport.ServiceAsUser("TestUpdateWI2-Service", *fxt.Identities[0])
test.DeleteWorkitemOK(s.T(), s.svc.Context, s.svc, s.workitemCtrl, fxt.WorkItems[0].ID)
})
s.T().Run("unauthorized", func(t *testing.T) {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.WorkItems(1), tf.Identities(1))
svcNotAuthorized := goa.New("TestDeleteWI2-Service")
workitemCtrlNotAuthorized := NewWorkitemController(svcNotAuthorized, s.GormDB, s.Configuration)
test.DeleteWorkitemUnauthorized(s.T(), svcNotAuthorized.Context, svcNotAuthorized, workitemCtrlNotAuthorized, fxt.WorkItems[0].ID)
})
s.T().Run("forbidden", func(t *testing.T) {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.WorkItems(1), tf.Identities(2))
s.svc = testsupport.ServiceAsUser("TestUpdateWI2-Service", *fxt.Identities[1])
test.DeleteWorkitemForbidden(s.T(), s.svc.Context, s.svc, s.workitemCtrl, fxt.WorkItems[0].ID)
s.T().Run("Delete Workitem", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.WorkItems(1))
s.svc = testsupport.ServiceAsUser("TestUpdateWI2-Service", *fxt.Identities[0])
test.DeleteWorkitemOK(s.T(), s.svc.Context, s.svc, s.workitemCtrl, fxt.WorkItems[0].ID)
})
t.Run("unauthorized", func(t *testing.T) {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.WorkItems(1), tf.Identities(1))
svcNotAuthorized := goa.New("TestDeleteWI2-Service")
workitemCtrlNotAuthorized := NewWorkitemController(svcNotAuthorized, s.GormDB, s.Configuration)
test.DeleteWorkitemUnauthorized(s.T(), svcNotAuthorized.Context, svcNotAuthorized, workitemCtrlNotAuthorized, fxt.WorkItems[0].ID)
})
t.Run("forbidden", func(t *testing.T) {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.WorkItems(1), tf.Identities(2))
s.svc = testsupport.ServiceAsUser("TestUpdateWI2-Service", *fxt.Identities[1])
test.DeleteWorkitemForbidden(s.T(), s.svc.Context, s.svc, s.workitemCtrl, fxt.WorkItems[0].ID)
})
t.Run("workitem not found", func(t *testing.T) {
test.DeleteWorkitemNotFound(s.T(), s.svc.Context, s.svc, s.workitemCtrl, uuid.NewV4())
})
})
s.T().Run("workitem not found", func(t *testing.T) {
test.DeleteWorkitemNotFound(s.T(), s.svc.Context, s.svc, s.workitemCtrl, uuid.NewV4())
s.T().Run("Delete Workitem Links", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
fxt := tf.NewTestFixture(t, s.DB,
tf.CreateWorkItemEnvironment(),
tf.WorkItems(2, tf.SetWorkItemTitles("A", "B")),
tf.WorkItemLinkTypes(1, tf.SetTopologies(link.TopologyTree)),

This comment has been minimized.

Copy link
@kwk

kwk Oct 10, 2018

Collaborator

Why is the topology important?

tf.WorkItemLinksCustom(1, tf.BuildLinks(tf.LinkChain("A", "B")...)),
)
s.svc = testsupport.ServiceAsUser("TestUpdateWI2-Service", *fxt.Identities[0])
test.DeleteWorkitemOK(s.T(), s.svc.Context, s.svc, s.workitemCtrl, fxt.WorkItems[0].ID)
test.ShowWorkItemLinkNotFound(t, s.svc.Context, s.svc, s.linkCtrl, fxt.WorkItemLinks[0].ID, nil, nil)
})
})
}

0 comments on commit 37e2d35

Please sign in to comment.