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
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f0fc73c
Adds WIT to TQ payload
DhritiShikhar Dec 2, 2018
65b3643
Merge remote-tracking branch 'upstream/master' into tq-wit-1
DhritiShikhar Dec 2, 2018
e4f054c
adds check for WIT; adds tests
DhritiShikhar Dec 3, 2018
21ee0b5
adds require.NoError
DhritiShikhar Dec 3, 2018
bba6209
removes duplicate checks for TrackerQuery update action
DhritiShikhar Dec 3, 2018
0524fee
replaces `rest` with `s`
DhritiShikhar Dec 3, 2018
5c24211
uses app.NewSpaceRelation(....)
DhritiShikhar Dec 3, 2018
4e28161
changes `baseType` to `workItemType` in TrackerQuery payload
DhritiShikhar Dec 3, 2018
7eafcf3
removes unnecessary spacetemplate creation
DhritiShikhar Dec 3, 2018
936cfc9
uses app.NewSpaceRelation(....) for space
DhritiShikhar Dec 3, 2018
68498a6
Adds work_item_type_id to existing tracker_queries; Adds tests;
DhritiShikhar Dec 3, 2018
3646533
Merge remote-tracking branch 'upstream/master' into tq-wit-1
DhritiShikhar Dec 3, 2018
72bc5c5
Adds struct tags
DhritiShikhar Dec 3, 2018
6648376
changes name of a function
DhritiShikhar Dec 3, 2018
071fe92
removes t:=s.T() line controller level test
DhritiShikhar Dec 3, 2018
97f2247
deletes old data from tracker_queries; adds wit column in tracker_que…
DhritiShikhar Dec 4, 2018
6f48605
removes unnecessary code from migration black box tests
DhritiShikhar Dec 4, 2018
e358263
Merge branch 'master' into tq-wit-1
DhritiShikhar Dec 6, 2018
6ddb69d
renames function
DhritiShikhar Dec 10, 2018
92a0e2c
Merge remote-tracking branch 'origin/tq-wit-1' into tq-wit-1
DhritiShikhar Dec 10, 2018
f5c9755
Merge remote-tracking branch 'upstream/master' into tq-wit-1
DhritiShikhar Dec 10, 2018
fc1a8ba
Merge branch 'master' into tq-wit-1
DhritiShikhar Dec 10, 2018
1b36616
changes assert to require
DhritiShikhar Dec 17, 2018
09a0e75
adds return values for tests
DhritiShikhar Dec 17, 2018
a59a40b
puts tests under one function
DhritiShikhar Dec 17, 2018
9fd13d7
Merge remote-tracking branch 'upstream/master' into tq-wit-1
DhritiShikhar Dec 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions controller/trackerquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ func (c *TrackerqueryController) Create(ctx *app.CreateTrackerqueryContext) erro
}
err = application.Transactional(c.db, func(appl application.Application) error {
trackerQuery := remoteworkitem.TrackerQuery{
Query: ctx.Payload.Data.Attributes.Query,
Schedule: ctx.Payload.Data.Attributes.Schedule,
TrackerID: ctx.Payload.Data.Relationships.Tracker.Data.ID,
SpaceID: *ctx.Payload.Data.Relationships.Space.Data.ID,
Query: ctx.Payload.Data.Attributes.Query,
Schedule: ctx.Payload.Data.Attributes.Schedule,
TrackerID: ctx.Payload.Data.Relationships.Tracker.Data.ID,
SpaceID: *ctx.Payload.Data.Relationships.Space.Data.ID,
WorkItemTypeID: ctx.Payload.Data.Relationships.WorkItemType.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)

}
trackerQuery.ID = *ctx.Payload.Data.ID
tq, err := appl.TrackerQueries().Create(ctx.Context, trackerQuery)
if err != nil {
return errs.Wrapf(err, "failed to create tracker query %s", ctx.Payload.Data)
Expand Down Expand Up @@ -138,12 +141,7 @@ func (c *TrackerqueryController) Update(ctx *app.UpdateTrackerqueryContext) erro
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
}
err = validateUpdateTrackerQueryPayload(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
err = application.Transactional(c.db, func(appl application.Application) error {

tq, err := appl.TrackerQueries().Load(ctx.Context, *ctx.Payload.Data.ID)
if err != nil {
return errs.Wrapf(err, "failed to update tracker query %s", ctx.Payload.Data.ID)
Expand All @@ -157,6 +155,9 @@ func (c *TrackerqueryController) Update(ctx *app.UpdateTrackerqueryContext) erro
if &ctx.Payload.Data.Relationships.Tracker.Data.ID != nil {
tq.TrackerID = ctx.Payload.Data.Relationships.Tracker.Data.ID
}
if ctx.Payload.Data.Relationships.WorkItemType.Data.ID != uuid.Nil {
tq.WorkItemTypeID = ctx.Payload.Data.Relationships.WorkItemType.Data.ID
}
_, err = appl.TrackerQueries().Save(ctx.Context, *tq)
if err != nil {
return errs.Wrapf(err, "failed to update tracker query %s", ctx.Payload.Data.ID)
Expand Down Expand Up @@ -248,21 +249,8 @@ func validateCreateTrackerQueryPayload(ctx *app.CreateTrackerqueryContext) error
if *ctx.Payload.Data.Relationships.Space.Data.ID == uuid.Nil {
return errors.NewBadParameterError("SpaceID", nil).Expected("not nil")
}
return nil
}

func validateUpdateTrackerQueryPayload(ctx *app.UpdateTrackerqueryContext) error {
if ctx.Payload.Data.ID == nil {
return errors.NewBadParameterError("ID", nil).Expected("not nil")
}
if ctx.Payload.Data.Attributes.Query == "" {
return errors.NewBadParameterError("Query", "").Expected("not empty")
}
if ctx.Payload.Data.Attributes.Schedule == "" {
return errors.NewBadParameterError("Schedule", "").Expected("not empty")
}
if ctx.Payload.Data.Relationships.Tracker.Data.ID == uuid.Nil {
return errors.NewBadParameterError("TrackerID", nil).Expected("not nil")
if ctx.Payload.Data.Relationships.WorkItemType.Data.ID == uuid.Nil {
return errors.NewBadParameterError("Workitemtype_id", nil).Expected("not nil")
}
return nil
}
198 changes: 111 additions & 87 deletions controller/trackerquery_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
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.

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() {
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.

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

})
}

func newCreateTrackerQueryPayload(spaceID uuid.UUID, trackerID uuid.UUID, witID uuid.UUID) app.CreateTrackerqueryPayload {
trackerQueryID := uuid.NewV4()
return app.CreateTrackerqueryPayload{
Data: &app.TrackerQuery{
Expand All @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions design/tracker_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var trackerQueryAttributes = a.Type("TrackerQueryAttributes", func() {
var trackerQueryRelationships = a.Type("TrackerQueryRelations", func() {
a.Attribute("tracker", relationKindUUID, "This defines the related tracker")
a.Attribute("space", relationSpaces, "This defines the owning space")
a.Attribute("workItemType", relationBaseType, "Defines what work item type to use when instantiating work items using this tracker query.")
})

var trackerQueryList = JSONList(
Expand Down
2 changes: 2 additions & 0 deletions migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ func GetMigrations() Migrations {
// Version 110
m = append(m, steps{ExecuteSQLFile("110-trackerquery-to-use-uuid.sql")})

// Version 111
m = append(m, steps{ExecuteSQLFile("111-add-wit-to-trackerquery.sql")})
// Version N
//
// In order to add an upgrade, simply append an array of MigrationFunc to the
Expand Down
Loading