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

Adds WIT parameter in TrackerQuery payload #2360

Merged
merged 26 commits into from
Dec 21, 2018

Conversation

DhritiShikhar
Copy link
Contributor

@DhritiShikhar DhritiShikhar commented Dec 3, 2018

[1] Adds WIT parameter in TrackerQuery Payload

Task -> #2361

@DhritiShikhar DhritiShikhar requested review from baijum and kwk December 3, 2018 07:03
WorkItemTypeID: ctx.Payload.Data.Relationships.BaseType.Data.ID,
}
if ctx.Payload.Data.ID != nil {
trackerQuery.ID = *ctx.Payload.Data.ID
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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)

design/tracker_queries.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Dec 3, 2018

Codecov Report

Merging #2360 into master will increase coverage by 0.09%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
remoteworkitem/remoteworkitem.go 78.87% <ø> (ø) ⬆️
remoteworkitem/trackerquery.go 100% <ø> (ø) ⬆️
migration/migration.go 77.93% <100%> (+0.07%) ⬆️
controller/trackerquery.go 61.47% <100%> (+3.97%) ⬆️
remoteworkitem/scheduler.go 60.97% <80%> (+7.31%) ⬆️
remoteworkitem/trackerquery_repository.go 66.15% <83.33%> (+3.19%) ⬆️
remoteworkitem/trackeritem_repository.go 74% <91.66%> (ø) ⬆️
remoteworkitem/github.go 100% <0%> (+22.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c95c04...9fd13d7. Read the comment docs.

@@ -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 {
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwk the check here is for validating create action. The check on line 163 is for validating update action.

However, there are some duplicate checks for update action. Made changes here bba6209

controller/trackerquery_blackbox_test.go Outdated Show resolved Hide resolved
controller/trackerquery_blackbox_test.go Outdated Show resolved Hide resolved
controller/trackerquery_blackbox_test.go Outdated Show resolved Hide resolved
design/tracker_queries.go Outdated Show resolved Hide resolved
remoteworkitem/scheduler.go Show resolved Hide resolved
remoteworkitem/scheduler.go Outdated Show resolved Hide resolved
migration/sql-files/111-add-wit-to-trackerquery.sql Outdated Show resolved Hide resolved
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)
Copy link
Collaborator

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 :)

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwk renamed here
6ddb69d

remoteworkitem/trackerquery.go Outdated Show resolved Hide resolved
Copy link
Contributor

@baijum baijum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

kwk
kwk previously requested changes Dec 11, 2018
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)
Copy link
Collaborator

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

Copy link
Contributor Author

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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() {
Copy link
Collaborator

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?

Copy link
Contributor Author

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)
Copy link
Collaborator

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"`)
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@baijum baijum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DhritiShikhar DhritiShikhar dismissed kwk’s stale review December 21, 2018 08:57

This PR needs to be merged for further work on remoteworkitems. I will address other remarks in another PR.

@DhritiShikhar DhritiShikhar merged commit ac1460f into fabric8-services:master Dec 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants