-
Notifications
You must be signed in to change notification settings - Fork 86
Adds WIT parameter in TrackerQuery payload #2360
Adds WIT parameter in TrackerQuery payload #2360
Conversation
c1513f2
to
02dca24
Compare
02dca24
to
e4f054c
Compare
WorkItemTypeID: ctx.Payload.Data.Relationships.BaseType.Data.ID, | ||
} | ||
if ctx.Payload.Data.ID != nil { | ||
trackerQuery.ID = *ctx.Payload.Data.ID |
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.
I wonder whether the UUID should be validated.
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.
@baijum are you talking about a check if the id
contains string or uuid?
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.
Check whether the value of *ctx.Payload.Data.ID
is real UUID (It's not a string type)
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.
I mean what if the value is some random string. It will reach the database layer and fail. How about failing early?
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.
@baijum At design level itself its specified that the value should be a UUID (https://github.com/fabric8-services/fabric8-wit/blob/master/design/tracker_queries.go#L13)
Codecov Report
@@ Coverage Diff @@
## master #2360 +/- ##
==========================================
+ Coverage 67.65% 67.75% +0.09%
==========================================
Files 182 182
Lines 17908 17922 +14
==========================================
+ Hits 12116 12143 +27
+ Misses 4622 4610 -12
+ Partials 1170 1169 -1
Continue to review full report at Codecov.
|
controller/trackerquery.go
Outdated
@@ -248,6 +254,9 @@ func validateCreateTrackerQueryPayload(ctx *app.CreateTrackerqueryContext) error | |||
if *ctx.Payload.Data.Relationships.Space.Data.ID == uuid.Nil { | |||
return errors.NewBadParameterError("SpaceID", nil).Expected("not nil") | |||
} | |||
if ctx.Payload.Data.Relationships.BaseType.Data.ID == uuid.Nil { |
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 hat the same check on line 163, no?
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.
if err != nil { | ||
return nil, ConversionError{simpleError{message: fmt.Sprintf("Error mapping to local work item: %s", err.Error())}} | ||
} | ||
workItem, err := lookupIdentities(ctx, db, remoteWorkItem, providerType, spaceID) | ||
workItem, err := lookupIdentities(ctx, db, remoteWorkItem, tq) | ||
if err != nil { | ||
return nil, InternalError{simpleError{message: fmt.Sprintf("Error bind assignees: %s", err.Error())}} | ||
} | ||
return upsert(ctx, db, *workItem) | ||
} | ||
|
||
// lookupIdentities looks up creator and assignee remote identities to local identities (already existing or to be created) |
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.
Please create a better documentation line. It makes no sense to me :)
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.
The function did much more than lookupIdentities
. Changed the function name here - 6648376
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.
@DhritiShikhar // setLocalWorkItemFields sets fields of local workitem
isn't really a good explanation either.
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.
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.
LGTM
assert.Equal(t, "is:open", updated.Data.Attributes.Query) | ||
assert.Equal(t, "* * * * * *", updated.Data.Attributes.Schedule) | ||
_, updated := test.UpdateTrackerqueryOK(s.T(), svc.Context, svc, trackerQueryCtrl, tqr.Data.ID.String(), &payload2) | ||
assert.NotNil(s.T(), tqr) |
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.
This needs to be a require.NotNil
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.
svc, _, trackerQueryCtrl := s.SecuredController() | ||
|
||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
test.CreateTrackerqueryBadRequest(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) |
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.
Don't these test methods have return values that you can check?
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.
invalidID := uuid.Nil | ||
tqpayload.Data.ID = &invalidID | ||
test.CreateTrackerqueryBadRequest(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
}) | ||
} | ||
|
||
func newCreateTrackerQueryPayload(spaceID uuid.UUID, trackerID uuid.UUID) app.CreateTrackerqueryPayload { | ||
func (s *TestTrackerQueryREST) TestInvalidWITinTrackerQuery() { |
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.
Why not have one func (s *TestTrackerQuerySuite) TestCreate()
and then test for all cases in there?
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.
@@ -77,7 +77,7 @@ func lookupIdentities(ctx context.Context, db *gorm.DB, remoteWorkItem RemoteWor | |||
} | |||
creatorLogin := fieldValue.(string) | |||
creatorProfileURL := remoteWorkItem.Fields[remoteCreatorProfileURL].(string) | |||
identity, err := identityRepository.Lookup(context.Background(), creatorLogin, creatorProfileURL, providerType) | |||
identity, err := identityRepository.Lookup(context.Background(), creatorLogin, creatorProfileURL, tq.TrackerType) |
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.
I'm a bit sceptical for why and how the tracker type corresponds to the provider type in the identity repo. Can you please explain what both are and if it is only by accident that you can use the tracker type for it?
@@ -22,40 +23,44 @@ func (test *TestTrackerItemRepository) TestUpload() { | |||
resource.Require(t, resource.Database) | |||
|
|||
test.DB.Exec(`DELETE FROM "tracker_items"`) |
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.
This seems a bit drastic. Why do you need to delete all tracker items? And why can't you use the db test suite to delete all that it has created after a test?
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.
This is an old piece of code. remoteworkitem
package needs a lot of refactoring.
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.
LGTM
This PR needs to be merged for further work on remoteworkitems. I will address other remarks in another PR.
[1] Adds WIT parameter in TrackerQuery Payload
Task -> #2361