-
Notifications
You must be signed in to change notification settings - Fork 86
Adds WIT parameter in TrackerQuery payload #2360
Changes from 22 commits
f0fc73c
65b3643
e4f054c
21ee0b5
bba6209
0524fee
5c24211
4e28161
7eafcf3
936cfc9
68498a6
3646533
72bc5c5
6648376
071fe92
97f2247
6f48605
e358263
6ddb69d
92a0e2c
f5c9755
fc1a8ba
1b36616
09a0e75
a59a40b
9fd13d7
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 |
---|---|---|
|
@@ -14,7 +14,6 @@ import ( | |
"github.com/fabric8-services/fabric8-wit/jsonapi" | ||
"github.com/fabric8-services/fabric8-wit/remoteworkitem" | ||
"github.com/fabric8-services/fabric8-wit/resource" | ||
"github.com/fabric8-services/fabric8-wit/space" | ||
testsupport "github.com/fabric8-services/fabric8-wit/test" | ||
tf "github.com/fabric8-services/fabric8-wit/test/testfixture" | ||
testtoken "github.com/fabric8-services/fabric8-wit/test/token" | ||
|
@@ -36,20 +35,20 @@ func TestRunTrackerQueryREST(t *testing.T) { | |
suite.Run(t, &TestTrackerQueryREST{DBTestSuite: gormtestsupport.NewDBTestSuite()}) | ||
} | ||
|
||
func (rest *TestTrackerQueryREST) SetupTest() { | ||
rest.DBTestSuite.SetupTest() | ||
rest.RwiScheduler = remoteworkitem.NewScheduler(rest.DB) | ||
rest.db = gormapplication.NewGormDB(rest.DB) | ||
func (s *TestTrackerQueryREST) SetupTest() { | ||
s.DBTestSuite.SetupTest() | ||
s.RwiScheduler = remoteworkitem.NewScheduler(s.DB) | ||
s.db = gormapplication.NewGormDB(s.DB) | ||
} | ||
|
||
func (rest *TestTrackerQueryREST) SecuredController() (*goa.Service, *TrackerController, *TrackerqueryController) { | ||
func (s *TestTrackerQueryREST) SecuredController() (*goa.Service, *TrackerController, *TrackerqueryController) { | ||
svc := testsupport.ServiceAsUser("TrackerQuery-Service", testsupport.TestIdentity) | ||
return svc, NewTrackerController(svc, rest.db, rest.RwiScheduler, rest.Configuration), NewTrackerqueryController(svc, rest.db, rest.RwiScheduler, rest.Configuration) | ||
return svc, NewTrackerController(svc, s.db, s.RwiScheduler, s.Configuration), NewTrackerqueryController(svc, s.db, s.RwiScheduler, s.Configuration) | ||
} | ||
|
||
func (rest *TestTrackerQueryREST) UnSecuredController() (*goa.Service, *TrackerController, *TrackerqueryController) { | ||
func (s *TestTrackerQueryREST) UnSecuredController() (*goa.Service, *TrackerController, *TrackerqueryController) { | ||
svc := goa.New("TrackerQuery-Service") | ||
return svc, NewTrackerController(svc, rest.db, rest.RwiScheduler, rest.Configuration), NewTrackerqueryController(svc, rest.db, rest.RwiScheduler, rest.Configuration) | ||
return svc, NewTrackerController(svc, s.db, s.RwiScheduler, s.Configuration), NewTrackerqueryController(svc, s.db, s.RwiScheduler, s.Configuration) | ||
} | ||
|
||
func getTrackerQueryTestData(t *testing.T) []testSecureAPI { | ||
|
@@ -164,65 +163,58 @@ func getTrackerQueryTestData(t *testing.T) []testSecureAPI { | |
} | ||
|
||
// This test case will check authorized access to Create/Update/Delete APIs | ||
func (rest *TestTrackerQueryREST) TestUnauthorizeTrackerQueryCUD() { | ||
UnauthorizeCreateUpdateDeleteTest(rest.T(), getTrackerQueryTestData, func() *goa.Service { | ||
func (s *TestTrackerQueryREST) TestUnauthorizeTrackerQueryCUD() { | ||
UnauthorizeCreateUpdateDeleteTest(s.T(), getTrackerQueryTestData, func() *goa.Service { | ||
return goa.New("TestUnauthorizedTrackerQuery-Service") | ||
}, func(service *goa.Service) error { | ||
controller := NewTrackerqueryController(service, rest.GormDB, rest.RwiScheduler, rest.Configuration) | ||
controller := NewTrackerqueryController(service, s.GormDB, s.RwiScheduler, s.Configuration) | ||
app.MountTrackerqueryController(service, controller) | ||
return nil | ||
}) | ||
} | ||
|
||
func (rest *TestTrackerQueryREST) TestCreateTrackerQuery() { | ||
t := rest.T() | ||
resource.Require(t, resource.Database) | ||
func (s *TestTrackerQueryREST) TestCreateTrackerQuery() { | ||
resource.Require(s.T(), resource.Database) | ||
|
||
svc, _, trackerQueryCtrl := rest.SecuredController() | ||
fxt := tf.NewTestFixture(t, rest.DB, tf.Spaces(1), tf.Trackers(1)) | ||
assert.NotNil(t, fxt.Spaces[0], fxt.Trackers[0]) | ||
svc, _, trackerQueryCtrl := s.SecuredController() | ||
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Spaces(1), tf.Trackers(1), tf.WorkItemTypes(1)) | ||
assert.NotNil(s.T(), fxt.Spaces[0], fxt.Trackers[0]) | ||
|
||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID) | ||
|
||
_, tqresult := test.CreateTrackerqueryCreated(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
assert.NotNil(t, tqresult) | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
_, tqresult := test.CreateTrackerqueryCreated(s.T(), svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
assert.NotNil(s.T(), tqresult) | ||
} | ||
|
||
func (rest *TestTrackerQueryREST) TestShowTrackerQuery() { | ||
t := rest.T() | ||
resource.Require(t, resource.Database) | ||
|
||
svc, _, trackerQueryCtrl := rest.SecuredController() | ||
fxt := tf.NewTestFixture(t, rest.DB, tf.Spaces(1), tf.Trackers(1)) | ||
assert.NotNil(t, fxt.Spaces[0], fxt.Trackers[0]) | ||
func (s *TestTrackerQueryREST) TestShowTrackerQuery() { | ||
resource.Require(s.T(), resource.Database) | ||
|
||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID) | ||
svc, _, trackerQueryCtrl := s.SecuredController() | ||
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Spaces(1), tf.Trackers(1), tf.WorkItemTypes(1)) | ||
assert.NotNil(s.T(), fxt.Spaces[0], fxt.Trackers[0]) | ||
|
||
_, tqresult := test.CreateTrackerqueryCreated(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
|
||
_, tqr := test.ShowTrackerqueryOK(t, svc.Context, svc, trackerQueryCtrl, *tqresult.Data.ID) | ||
assert.NotNil(t, tqr) | ||
assert.Equal(t, tqresult.Data.ID, tqr.Data.ID) | ||
_, tqresult := test.CreateTrackerqueryCreated(s.T(), svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
_, tqr := test.ShowTrackerqueryOK(s.T(), svc.Context, svc, trackerQueryCtrl, *tqresult.Data.ID) | ||
assert.NotNil(s.T(), tqr) | ||
assert.Equal(s.T(), tqresult.Data.ID, tqr.Data.ID) | ||
} | ||
|
||
func (rest *TestTrackerQueryREST) TestUpdateTrackerQuery() { | ||
t := rest.T() | ||
resource.Require(t, resource.Database) | ||
func (s *TestTrackerQueryREST) TestUpdateTrackerQuery() { | ||
resource.Require(s.T(), resource.Database) | ||
|
||
svc, _, trackerQueryCtrl := rest.SecuredController() | ||
fxt := tf.NewTestFixture(t, rest.DB, tf.Spaces(1), tf.Trackers(1)) | ||
assert.NotNil(t, fxt.Spaces[0], fxt.Trackers[0]) | ||
svc, _, trackerQueryCtrl := s.SecuredController() | ||
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Spaces(1), tf.Trackers(1), tf.WorkItemTypes(1)) | ||
assert.NotNil(s.T(), fxt.Spaces[0], fxt.Trackers[0]) | ||
|
||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID) | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
|
||
_, tqresult := test.CreateTrackerqueryCreated(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
_, tqresult := test.CreateTrackerqueryCreated(s.T(), svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
|
||
_, tqr := test.ShowTrackerqueryOK(t, svc.Context, svc, trackerQueryCtrl, *tqresult.Data.ID) | ||
assert.NotNil(t, tqr) | ||
assert.Equal(t, tqresult.Data.ID, tqr.Data.ID) | ||
_, tqr := test.ShowTrackerqueryOK(s.T(), svc.Context, svc, trackerQueryCtrl, *tqresult.Data.ID) | ||
assert.NotNil(s.T(), tqr) | ||
assert.Equal(s.T(), tqresult.Data.ID, tqr.Data.ID) | ||
|
||
spaceID := space.SystemSpace | ||
trackerID := fxt.Trackers[0].ID | ||
payload2 := app.UpdateTrackerqueryPayload{ | ||
Data: &app.TrackerQuery{ | ||
ID: tqr.Data.ID, | ||
|
@@ -231,77 +223,107 @@ func (rest *TestTrackerQueryREST) TestUpdateTrackerQuery() { | |
Schedule: "* * * * * *", | ||
}, | ||
Relationships: &app.TrackerQueryRelations{ | ||
Space: &app.RelationSpaces{ | ||
Data: &app.RelationSpacesData{ | ||
ID: &spaceID, | ||
}, | ||
}, | ||
Space: app.NewSpaceRelation(fxt.Spaces[0].ID, ""), | ||
Tracker: &app.RelationKindUUID{ | ||
Data: &app.DataKindUUID{ | ||
ID: trackerID, | ||
ID: fxt.Trackers[0].ID, | ||
Type: remoteworkitem.APIStringTypeTrackers, | ||
}, | ||
}, | ||
WorkItemType: &app.RelationBaseType{ | ||
Data: &app.BaseTypeData{ | ||
ID: fxt.WorkItemTypes[0].ID, | ||
Type: APIStringTypeWorkItemType, | ||
}, | ||
}, | ||
}, | ||
Type: remoteworkitem.APIStringTypeTrackerQuery, | ||
}, | ||
} | ||
|
||
_, updated := test.UpdateTrackerqueryOK(t, svc.Context, svc, trackerQueryCtrl, tqr.Data.ID.String(), &payload2) | ||
assert.NotNil(t, tqr) | ||
assert.Equal(t, tqr.Data.ID, updated.Data.ID) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be 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. |
||
assert.Equal(s.T(), tqr.Data.ID, updated.Data.ID) | ||
assert.Equal(s.T(), "is:open", updated.Data.Attributes.Query) | ||
assert.Equal(s.T(), "* * * * * *", updated.Data.Attributes.Schedule) | ||
} | ||
|
||
// This test ensures that List does not return NIL items. | ||
func (rest *TestTrackerQueryREST) TestTrackerQueryListItemsNotNil() { | ||
t := rest.T() | ||
resource.Require(t, resource.Database) | ||
func (s *TestTrackerQueryREST) TestTrackerQueryListItemsNotNil() { | ||
resource.Require(s.T(), resource.Database) | ||
|
||
svc, _, trackerQueryCtrl := rest.SecuredController() | ||
fxt := tf.NewTestFixture(t, rest.DB, tf.Spaces(1), tf.Trackers(1)) | ||
assert.NotNil(t, fxt.Spaces[0], fxt.Trackers[0]) | ||
svc, _, trackerQueryCtrl := s.SecuredController() | ||
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Spaces(1), tf.Trackers(1), tf.WorkItemTypes(1)) | ||
assert.NotNil(s.T(), fxt.Spaces[0], fxt.Trackers[0]) | ||
|
||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID) | ||
_, tq1 := test.CreateTrackerqueryCreated(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
assert.NotNil(t, tq1) | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
_, tq1 := test.CreateTrackerqueryCreated(s.T(), svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
assert.NotNil(s.T(), tq1) | ||
|
||
tqpayload2 := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID) | ||
_, tq2 := test.CreateTrackerqueryCreated(t, svc.Context, svc, trackerQueryCtrl, &tqpayload2) | ||
assert.NotNil(t, tq2) | ||
tqpayload2 := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
_, tq2 := test.CreateTrackerqueryCreated(s.T(), svc.Context, svc, trackerQueryCtrl, &tqpayload2) | ||
assert.NotNil(s.T(), tq2) | ||
|
||
_, list := test.ListTrackerqueryOK(t, svc.Context, svc, trackerQueryCtrl, nil, nil) | ||
assert.NotNil(t, list.Data) | ||
_, list := test.ListTrackerqueryOK(s.T(), svc.Context, svc, trackerQueryCtrl, nil, nil) | ||
assert.NotNil(s.T(), list.Data) | ||
} | ||
|
||
// This test ensures that ID returned by Show is valid. | ||
// refer : https://github.com/fabric8-services/fabric8-wit/issues/189 | ||
func (rest *TestTrackerQueryREST) TestCreateTrackerQueryID() { | ||
t := rest.T() | ||
resource.Require(t, resource.Database) | ||
func (s *TestTrackerQueryREST) TestCreateTrackerQueryID() { | ||
resource.Require(s.T(), resource.Database) | ||
|
||
svc, _, trackerQueryCtrl := rest.SecuredController() | ||
fxt := tf.NewTestFixture(t, rest.DB, tf.Spaces(1), tf.Trackers(1)) | ||
svc, _, trackerQueryCtrl := s.SecuredController() | ||
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Spaces(1), tf.Trackers(1), tf.WorkItemTypes(1)) | ||
|
||
rest.T().Run("valid - success", func(t *testing.T) { | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID) | ||
s.T().Run("valid - success", func(t *testing.T) { | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
_, trackerquery := test.CreateTrackerqueryCreated(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
require.NotNil(t, trackerquery) | ||
|
||
_, result := test.ShowTrackerqueryOK(t, svc.Context, svc, trackerQueryCtrl, *trackerquery.Data.ID) | ||
require.NotNil(t, result) | ||
assert.Equal(t, trackerquery.Data.ID, result.Data.ID) | ||
}) | ||
rest.T().Run("invalid - fail", func(t *testing.T) { | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID) | ||
s.T().Run("invalid - fail", func(t *testing.T) { | ||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, fxt.WorkItemTypes[0].ID) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Why not have one 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. |
||
resource.Require(s.T(), resource.Database) | ||
s.T().Run("nil WIT in trackerquery payload", func(t *testing.T) { | ||
fxt := tf.NewTestFixture(t, s.DB, | ||
tf.Spaces(1), | ||
tf.Trackers(1), | ||
) | ||
svc, _, trackerQueryCtrl := s.SecuredController() | ||
|
||
tqpayload := newCreateTrackerQueryPayload(fxt.Spaces[0].ID, fxt.Trackers[0].ID, uuid.Nil) | ||
test.CreateTrackerqueryBadRequest(t, svc.Context, svc, trackerQueryCtrl, &tqpayload) | ||
}) | ||
|
||
s.T().Run("disallow creation if WIT belongs to different spacetemplate", func(t *testing.T) { | ||
fxt := tf.NewTestFixture(t, s.DB, | ||
tf.SpaceTemplates(2), | ||
tf.Spaces(1), | ||
tf.WorkItemTypes(1, func(fxt *tf.TestFixture, idx int) error { | ||
fxt.WorkItemTypes[idx].SpaceTemplateID = fxt.SpaceTemplates[1].ID | ||
return nil | ||
}), | ||
tf.Trackers(1), | ||
) | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}) | ||
} | ||
|
||
func newCreateTrackerQueryPayload(spaceID uuid.UUID, trackerID uuid.UUID, witID uuid.UUID) app.CreateTrackerqueryPayload { | ||
trackerQueryID := uuid.NewV4() | ||
return app.CreateTrackerqueryPayload{ | ||
Data: &app.TrackerQuery{ | ||
|
@@ -311,17 +333,19 @@ func newCreateTrackerQueryPayload(spaceID uuid.UUID, trackerID uuid.UUID) app.Cr | |
Schedule: "15 * * * * *", | ||
}, | ||
Relationships: &app.TrackerQueryRelations{ | ||
Space: &app.RelationSpaces{ | ||
Data: &app.RelationSpacesData{ | ||
ID: &spaceID, | ||
}, | ||
}, | ||
Space: app.NewSpaceRelation(spaceID, ""), | ||
Tracker: &app.RelationKindUUID{ | ||
Data: &app.DataKindUUID{ | ||
ID: trackerID, | ||
Type: remoteworkitem.APIStringTypeTrackers, | ||
}, | ||
}, | ||
WorkItemType: &app.RelationBaseType{ | ||
Data: &app.BaseTypeData{ | ||
ID: witID, | ||
Type: APIStringTypeWorkItemType, | ||
}, | ||
}, | ||
}, | ||
Type: remoteworkitem.APIStringTypeTrackerQuery, | ||
}, | ||
|
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)