-
Notifications
You must be signed in to change notification settings - Fork 86
Restrict iterating over every workitem field for reorder #2261
Changes from 9 commits
4eb8e89
3ba0022
cac3e02
5fde63f
5a14ac8
e6c9abd
2242279
adccee4
7e9b1ad
ef2d346
a37aad6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -559,6 +559,36 @@ func (s *WorkItemSuite) TestUpdateWorkitemWithoutReorder() { | |
assert.Equal(s.T(), wi.Data.Attributes[workitem.SystemOrder], updated.Data.Attributes[workitem.SystemOrder]) | ||
} | ||
|
||
// TestReorderDoesNotUpdateAnyOtherWIFields tests that no other workitem fields are updated while reorder | ||
func (s *WorkItemSuite) TestReorderDoesNotUpdateOtherWIFields() { | ||
fxt := tf.NewTestFixture(s.T(), s.DB, tf.CreateWorkItemEnvironment()) | ||
|
||
// create workitems | ||
payload := minimumRequiredCreateWithTypeAndSpace(fxt.WorkItemTypes[0].ID, fxt.Spaces[0].ID) | ||
originalTitle := "Original Title" | ||
payload.Data.Attributes[workitem.SystemTitle] = originalTitle | ||
payload.Data.Attributes[workitem.SystemState] = workitem.SystemStateClosed | ||
_, workitem1 := test.CreateWorkitemsCreated(s.T(), s.svc.Context, s.svc, s.workitemsCtrl, *payload.Data.Relationships.Space.Data.ID, &payload) | ||
_, workitem2 := test.CreateWorkitemsCreated(s.T(), s.svc.Context, s.svc, s.workitemsCtrl, *payload.Data.Relationships.Space.Data.ID, &payload) | ||
|
||
titleNotUpdated := "This Title Should Not Be Updated" | ||
workitem1.Data.Attributes[workitem.SystemTitle] = titleNotUpdated | ||
|
||
payload2 := minimumRequiredReorderPayload() | ||
|
||
var dataArray []*app.WorkItem // dataArray contains the workitem(s) that have to be reordered | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also be removed when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jarifibrahim The test fixture gives me a workitem of workitem.Workitem type but I need app.WorkItem to create reorder payload. |
||
dataArray = append(dataArray, workitem1.Data) | ||
payload2.Data = dataArray | ||
payload2.Position.ID = workitem2.Data.ID // Position.ID specifies the workitem ID above or below which the workitem(s) should be placed | ||
payload2.Position.Direction = string(workitem.DirectionAbove) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but
|
||
_, reorderedList := test.ReorderWorkitemsOK(s.T(), s.svc.Context, s.svc, s.workitemsCtrl, fxt.Spaces[0].ID, &payload2) // Returns the workitems which are reordered | ||
|
||
require.Len(s.T(), reorderedList.Data, 1) | ||
assert.Equal(s.T(), workitem1.Data.Attributes["version"].(int)+1, reorderedList.Data[0].Attributes["version"]) | ||
assert.Equal(s.T(), *workitem1.Data.ID, *reorderedList.Data[0].ID) | ||
assert.Equal(s.T(), originalTitle, reorderedList.Data[0].Attributes[workitem.SystemTitle]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need both, this and https://github.com/fabric8-services/fabric8-wit/pull/2261/files#diff-98914f859911696f3cdd98dd289d00faR589 . One of them should be sufficient. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed here adccee4 |
||
} | ||
|
||
func (s *WorkItemSuite) TestCreateWorkItemWithoutContext() { | ||
// given | ||
s.svc = goa.New("TestCreateWorkItemWithoutContext-Service") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -544,24 +544,11 @@ func (r *GormWorkItemRepository) Reorder(ctx context.Context, spaceID uuid.UUID, | |
default: | ||
return &wi, nil | ||
} | ||
res.Version = res.Version + 1 | ||
res.Type = wi.Type | ||
res.Fields = Fields{} | ||
|
||
res.ExecutionOrder = order | ||
|
||
for fieldName, fieldDef := range wiType.Fields { | ||
if fieldDef.ReadOnly { | ||
continue | ||
} | ||
fieldValue := wi.Fields[fieldName] | ||
var err error | ||
res.Fields[fieldName], err = fieldDef.ConvertToModel(fieldName, fieldValue) | ||
if err != nil { | ||
return nil, errors.NewBadParameterError(fieldName, fieldValue) | ||
} | ||
} | ||
tx = tx.Where("Version = ?", wi.Version).Save(&res) | ||
tx = tx.Model(&res).Select("execution_order", "version").Updates(WorkItemStorage{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why doesn't this have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because I pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DhritiShikhar can you please show the |
||
ExecutionOrder: order, | ||
Version: res.Version + 1, | ||
}) | ||
if err := tx.Error; err != nil { | ||
return nil, errors.NewInternalError(ctx, err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use test fixture to create the initial work item. That would remove all the code from line 566 to 576
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jarifibrahim The test fixture gives me a workitem of
workitem.Workitem
type but I needapp.WorkItem
to create reorder payload.