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

Space id for wi, wit and tracker query #900

Merged
merged 36 commits into from Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a56bffa
Initial commit
hectorj2f Feb 22, 2017
e797767
Merge branch master into space_id_wilt
Feb 23, 2017
9797405
Added space creation in the existing wi tests
hectorj2f Feb 23, 2017
be6e2d5
Adapted migration to set the request context
hectorj2f Feb 23, 2017
a7f2263
Adapted to use DELETE CASCADE
hectorj2f Feb 23, 2017
fc3a9b0
Added space self URL
hectorj2f Feb 23, 2017
308b2db
Use secured service to create spaces
hectorj2f Feb 23, 2017
0969397
Filled description field for spaces
hectorj2f Feb 23, 2017
af5c1f5
Changed userSpaceID to uuid type and added tests to check include list
hectorj2f Feb 24, 2017
8f9e63d
Added test and fixed some types
hectorj2f Feb 24, 2017
7049998
Merge remote master branch into space_id_wilt
Feb 24, 2017
ca1038a
Re-organized my sql script to be in order
hectorj2f Feb 24, 2017
4510e7d
Merge remote master branch into space_id_wilt
hectorj2f Feb 27, 2017
fb6a810
Avoid referring to space by name. Use uuid identifier
hectorj2f Feb 27, 2017
cb9302c
Merge remote-tracking branch 'master' into space_id_wilt
Feb 27, 2017
d0a70d6
Merge remote-tracking branch 'master' into space_id_wilt
Feb 27, 2017
0e07c52
Merge remote-tracking branch 'master' into space_id_wilt
hectorj2f Feb 27, 2017
3239ea3
Merge remote-tracking branch 'master' into space_id_wilt
hectorj2f Feb 28, 2017
e915fd9
Add space_id to wi and wit
hectorj2f Feb 28, 2017
0a23ab2
Merge remote-tracking branch 'master' into space_id_wi_wit
hectorj2f Mar 3, 2017
fdf304a
Merge remote-tracking branch 'master' into space_id_wi_wit
hectorj2f Mar 3, 2017
93f332b
Merge remote-tracking branch 'master' into space_id_wi_wit
hectorj2f Mar 4, 2017
d9c9957
Fixed tests
hectorj2f Mar 5, 2017
d461d31
Removed unnecessary locks
hectorj2f Mar 5, 2017
9f72319
Merge branch 'master' into space_id_wi_wit
kwk Mar 6, 2017
d7908d0
Merge remote-tracking branch 'master' into space_id_wi_wit
hectorj2f Mar 6, 2017
413183e
Added a locker for the db population function and some code polishing
hectorj2f Mar 6, 2017
3ee44d9
Merge branch 'space_id_wi_wit' of hectorj2f into space_id_wi_wit
hectorj2f Mar 6, 2017
9a7de8d
Addressed minor comments
hectorj2f Mar 6, 2017
ab7b2ba
Merge remote-tracking branch 'master' into space_id_wi_wit
hectorj2f Mar 6, 2017
c8df855
Fixed wrong function name
hectorj2f Mar 6, 2017
271965b
Updated migration version to 40
hectorj2f Mar 6, 2017
5c9d2e9
Fixed error tracker.ID is a string object
hectorj2f Mar 6, 2017
4f3dc45
Merge remote-tracking branch 'master' into space_id_wi_wit
Mar 6, 2017
accbfef
Adapted new test
hectorj2f Mar 6, 2017
460ae4f
gofmt code
hectorj2f Mar 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions account/identity_blackbox_test.go
@@ -1,7 +1,6 @@
package account_test

import (
"context"
"os"
"testing"

Expand All @@ -12,17 +11,20 @@ import (
"github.com/almighty/almighty-core/models"
"github.com/almighty/almighty-core/resource"
"github.com/almighty/almighty-core/workitem"

"github.com/jinzhu/gorm"
"github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"golang.org/x/net/context"
)

type identityBlackBoxTest struct {
gormsupport.DBTestSuite
repo account.IdentityRepository
clean func()
ctx context.Context
}

func TestRunIdentityBlackBoxTest(t *testing.T) {
Expand All @@ -38,7 +40,8 @@ func (s *identityBlackBoxTest) SetupSuite() {
// Make sure the database is populated with the correct types (e.g. bug etc.)
if _, c := os.LookupEnv(resource.Database); c != false {
if err := models.Transactional(s.DB, func(tx *gorm.DB) error {
return migration.PopulateCommonTypes(context.Background(), tx, workitem.NewWorkItemTypeRepository(tx))
s.ctx = migration.NewMigrationContext(context.Background())
return migration.PopulateCommonTypes(s.ctx, tx, workitem.NewWorkItemTypeRepository(tx))
}); err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -66,15 +69,15 @@ func (s *identityBlackBoxTest) TestOKToDelete() {
Username: "onemoreuserTestIdentity",
ProviderType: account.KeycloakIDP}

err := s.repo.Create(context.Background(), identity)
err := s.repo.Create(s.ctx, identity)
require.Nil(s.T(), err, "Could not create identity")
err = s.repo.Create(context.Background(), identity2)
err = s.repo.Create(s.ctx, identity2)
require.Nil(s.T(), err, "Could not create identity")
// when
err = s.repo.Delete(context.Background(), identity.ID)
err = s.repo.Delete(s.ctx, identity.ID)
// then
assert.Nil(s.T(), err)
identities, err := s.repo.List(context.Background())
identities, err := s.repo.List(s.ctx)
require.Nil(s.T(), err, "Could not list identities")
require.True(s.T(), len(identities.Data) > 0)
for _, data := range identities.Data {
Expand All @@ -91,7 +94,7 @@ func (s *identityBlackBoxTest) TestOKToSave() {
identity := createAndLoad(s)
// when
identity.Username = "newusernameTestIdentity"
err := s.repo.Save(context.Background(), identity)
err := s.repo.Save(s.ctx, identity)
// then
require.Nil(s.T(), err, "Could not update identity")
}
Expand All @@ -102,10 +105,10 @@ func createAndLoad(s *identityBlackBoxTest) *account.Identity {
Username: "someuserTestIdentity2",
ProviderType: account.KeycloakIDP}

err := s.repo.Create(context.Background(), identity)
err := s.repo.Create(s.ctx, identity)
require.Nil(s.T(), err, "Could not create identity")
// when
idnt, err := s.repo.Load(context.Background(), identity.ID)
idnt, err := s.repo.Load(s.ctx, identity.ID)
// then
require.Nil(s.T(), err, "Could not load identity")
require.Equal(s.T(), "someuserTestIdentity2", idnt.Username)
Expand Down
4 changes: 3 additions & 1 deletion application/repositories.go
Expand Up @@ -3,6 +3,8 @@ package application
import (
"github.com/almighty/almighty-core/app"
"github.com/almighty/almighty-core/criteria"

uuid "github.com/satori/go.uuid"
"golang.org/x/net/context"
)

Expand All @@ -17,7 +19,7 @@ type TrackerRepository interface {

// TrackerQueryRepository encapsulate storage & retrieval of tracker queries
type TrackerQueryRepository interface {
Create(ctx context.Context, query string, schedule string, tracker string) (*app.TrackerQuery, error)
Create(ctx context.Context, query string, schedule string, tracker string, spaceID uuid.UUID) (*app.TrackerQuery, error)
Save(ctx context.Context, tq app.TrackerQuery) (*app.TrackerQuery, error)
Load(ctx context.Context, ID string) (*app.TrackerQuery, error)
Delete(ctx context.Context, ID string) error
Expand Down
32 changes: 17 additions & 15 deletions comment/comment_repository_blackbox_test.go
Expand Up @@ -29,6 +29,7 @@ type TestCommentRepository struct {
clean func()
testIdentity account.Identity
repo comment.Repository
ctx context.Context
}

func TestRunCommentRepository(t *testing.T) {
Expand All @@ -44,7 +45,8 @@ func (s *TestCommentRepository) SetupSuite() {
// Make sure the database is populated with the correct types (e.g. bug etc.)
if _, c := os.LookupEnv(resource.Database); c != false {
if err := models.Transactional(s.DB, func(tx *gorm.DB) error {
return migration.PopulateCommonTypes(context.Background(), tx, workitem.NewWorkItemTypeRepository(tx))
s.ctx = migration.NewMigrationContext(s.ctx)
return migration.PopulateCommonTypes(s.ctx, tx, workitem.NewWorkItemTypeRepository(tx))
}); err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -73,7 +75,7 @@ func newComment(parentID, body, markup string) *comment.Comment {
}

func (s *TestCommentRepository) createComment(c *comment.Comment, creator uuid.UUID) {
err := s.repo.Create(context.Background(), c, creator)
err := s.repo.Create(s.ctx, c, creator)
require.Nil(s.T(), err)
}

Expand All @@ -87,7 +89,7 @@ func (s *TestCommentRepository) TestCreateCommentWithMarkup() {
// given
comment := newComment("A", "Test A", rendering.SystemMarkupMarkdown)
// when
s.repo.Create(context.Background(), comment, s.testIdentity.ID)
s.repo.Create(s.ctx, comment, s.testIdentity.ID)
// then
assert.NotNil(s.T(), comment.ID, "Comment was not created, ID nil")
require.NotNil(s.T(), comment.CreatedAt, "Comment was not created?")
Expand All @@ -98,7 +100,7 @@ func (s *TestCommentRepository) TestCreateCommentWithoutMarkup() {
// given
comment := newComment("A", "Test A", "")
// when
s.repo.Create(context.Background(), comment, s.testIdentity.ID)
s.repo.Create(s.ctx, comment, s.testIdentity.ID)
// then
assert.NotNil(s.T(), comment.ID, "Comment was not created, ID nil")
require.NotNil(s.T(), comment.CreatedAt, "Comment was not created?")
Expand All @@ -114,10 +116,10 @@ func (s *TestCommentRepository) TestSaveCommentWithMarkup() {
// when
comment.Body = "Test AB"
comment.Markup = rendering.SystemMarkupMarkdown
s.repo.Save(context.Background(), comment, s.testIdentity.ID)
s.repo.Save(s.ctx, comment, s.testIdentity.ID)
offset := 0
limit := 1
comments, _, err := s.repo.List(context.Background(), comment.ParentID, &offset, &limit)
comments, _, err := s.repo.List(s.ctx, comment.ParentID, &offset, &limit)
// then
require.Nil(s.T(), err)
require.Equal(s.T(), 1, len(comments), "List returned more then expected based on parentID")
Expand All @@ -133,10 +135,10 @@ func (s *TestCommentRepository) TestSaveCommentWithoutMarkup() {
// when
comment.Body = "Test AB"
comment.Markup = ""
s.repo.Save(context.Background(), comment, s.testIdentity.ID)
s.repo.Save(s.ctx, comment, s.testIdentity.ID)
offset := 0
limit := 1
comments, _, err := s.repo.List(context.Background(), comment.ParentID, &offset, &limit)
comments, _, err := s.repo.List(s.ctx, comment.ParentID, &offset, &limit)
// then
require.Nil(s.T(), err)
require.Equal(s.T(), 1, len(comments), "List returned more then expected based on parentID")
Expand All @@ -153,10 +155,10 @@ func (s *TestCommentRepository) TestDeleteComment() {
CreatedBy: uuid.NewV4(),
ID: uuid.NewV4(),
}
s.repo.Create(context.Background(), c, s.testIdentity.ID)
s.repo.Create(s.ctx, c, s.testIdentity.ID)
require.NotEqual(s.T(), uuid.Nil, c.ID)
// when
err := s.repo.Delete(context.Background(), c.ID, s.testIdentity.ID)
err := s.repo.Delete(s.ctx, c.ID, s.testIdentity.ID)
// then
assert.Nil(s.T(), err)
}
Expand All @@ -169,7 +171,7 @@ func (s *TestCommentRepository) TestCountComments() {
comments := []*comment.Comment{comment1, comment2}
s.createComments(comments, s.testIdentity.ID)
// when
count, err := s.repo.Count(context.Background(), parentID)
count, err := s.repo.Count(s.ctx, parentID)
// then
require.Nil(s.T(), err)
assert.Equal(s.T(), 1, count)
Expand All @@ -184,7 +186,7 @@ func (s *TestCommentRepository) TestListComments() {
// when
offset := 0
limit := 1
comments, _, err := s.repo.List(context.Background(), comment1.ParentID, &offset, &limit)
comments, _, err := s.repo.List(s.ctx, comment1.ParentID, &offset, &limit)
// then
require.Nil(s.T(), err)
require.Equal(s.T(), 1, len(comments))
Expand All @@ -200,7 +202,7 @@ func (s *TestCommentRepository) TestListCommentsWrongOffset() {
// when
offset := -1
limit := 1
_, _, err := s.repo.List(context.Background(), comment1.ParentID, &offset, &limit)
_, _, err := s.repo.List(s.ctx, comment1.ParentID, &offset, &limit)
// then
assert.NotNil(s.T(), err)
}
Expand All @@ -214,7 +216,7 @@ func (s *TestCommentRepository) TestListCommentsWrongLimit() {
// when
offset := 0
limit := -1
_, _, err := s.repo.List(context.Background(), comment1.ParentID, &offset, &limit)
_, _, err := s.repo.List(s.ctx, comment1.ParentID, &offset, &limit)
// then
assert.NotNil(s.T(), err)
}
Expand All @@ -224,7 +226,7 @@ func (s *TestCommentRepository) TestLoadComment() {
comment := newComment("A", "Test A", rendering.SystemMarkupMarkdown)
s.createComment(comment, s.testIdentity.ID)
// when
loadedComment, err := s.repo.Load(context.Background(), comment.ID)
loadedComment, err := s.repo.Load(s.ctx, comment.ID)
// then
require.Nil(s.T(), err)
assert.Equal(s.T(), comment.ID, loadedComment.ID)
Expand Down
7 changes: 3 additions & 4 deletions controller/area.go
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/almighty/almighty-core/login"
"github.com/almighty/almighty-core/path"
"github.com/almighty/almighty-core/rest"
"github.com/almighty/almighty-core/space"

"github.com/goadesign/goa"
uuid "github.com/satori/go.uuid"
)
Expand Down Expand Up @@ -168,10 +170,7 @@ func ConvertAreas(appl application.Application, request *goa.RequestData, areas
// ConvertArea converts between internal and external REST representation
func ConvertArea(appl application.Application, request *goa.RequestData, ar *area.Area, additional ...AreaConvertFunc) *app.Area {
areaType := area.APIStringTypeAreas
spaceType := "spaces"

spaceID := ar.SpaceID.String()

selfURL := rest.AbsoluteURL(request, app.AreaHref(ar.ID))
childURL := rest.AbsoluteURL(request, app.AreaHref(ar.ID)+"/children")
spaceSelfURL := rest.AbsoluteURL(request, app.SpaceHref(spaceID))
Expand All @@ -188,7 +187,7 @@ func ConvertArea(appl application.Application, request *goa.RequestData, ar *are
Relationships: &app.AreaRelations{
Space: &app.RelationGeneric{
Data: &app.GenericData{
Type: &spaceType,
Type: &space.SpaceType,
ID: &spaceID,
},
Links: &app.GenericLinks{
Expand Down
7 changes: 7 additions & 0 deletions controller/comments_blackbox_test.go
Expand Up @@ -3,6 +3,7 @@ package controller_test
import (
"fmt"
"html"
"net/http"
"testing"

"github.com/almighty/almighty-core/account"
Expand All @@ -14,6 +15,8 @@ import (
"github.com/almighty/almighty-core/gormsupport/cleaner"
"github.com/almighty/almighty-core/rendering"
"github.com/almighty/almighty-core/resource"
"github.com/almighty/almighty-core/rest"
"github.com/almighty/almighty-core/space"
testsupport "github.com/almighty/almighty-core/test"
almtoken "github.com/almighty/almighty-core/token"
"github.com/almighty/almighty-core/workitem"
Expand Down Expand Up @@ -78,6 +81,9 @@ func (s *CommentsSuite) securedControllers(identity account.Identity) (*goa.Serv

// createWorkItem creates a workitem that will be used to perform the comment operations during the tests.
func (s *CommentsSuite) createWorkItem(identity account.Identity) string {
spaceSelfURL := rest.AbsoluteURL(&goa.RequestData{
Request: &http.Request{Host: "api.service.domain.org"},
}, app.SpaceHref(space.SystemSpace.String()))
createWorkitemPayload := app.CreateWorkitemPayload{
Data: &app.WorkItem2{
Type: APIStringTypeWorkItem,
Expand All @@ -91,6 +97,7 @@ func (s *CommentsSuite) createWorkItem(identity account.Identity) string {
ID: workitem.SystemBug,
},
},
Space: space.NewSpaceRelation(space.SystemSpace, spaceSelfURL),
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions controller/iteration.go
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/almighty/almighty-core/jsonapi"
"github.com/almighty/almighty-core/login"
"github.com/almighty/almighty-core/rest"
"github.com/almighty/almighty-core/space"
"github.com/almighty/almighty-core/workitem"

"github.com/goadesign/goa"
uuid "github.com/satori/go.uuid"
)
Expand Down Expand Up @@ -192,10 +194,8 @@ func ConvertIterations(request *goa.RequestData, Iterations []*iteration.Iterati
// ConvertIteration converts between internal and external REST representation
func ConvertIteration(request *goa.RequestData, itr *iteration.Iteration, additional ...IterationConvertFunc) *app.Iteration {
iterationType := iteration.APIStringTypeIteration
spaceType := "spaces"

spaceID := itr.SpaceID.String()

selfURL := rest.AbsoluteURL(request, app.IterationHref(itr.ID))
spaceSelfURL := rest.AbsoluteURL(request, app.SpaceHref(spaceID))
workitemsRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref("?filter[iteration]="+itr.ID.String()))
Expand All @@ -215,7 +215,7 @@ func ConvertIteration(request *goa.RequestData, itr *iteration.Iteration, additi
Relationships: &app.IterationRelations{
Space: &app.RelationGeneric{
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 use NewSpaceRelation here as well?

Copy link
Author

Choose a reason for hiding this comment

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

Because we have two type of objects for the relation, relationSpace and relationGeneric. I could unify this in a different PR.

Data: &app.GenericData{
Type: &spaceType,
Type: &space.SpaceType,
ID: &spaceID,
},
Links: &app.GenericLinks{
Expand Down
11 changes: 9 additions & 2 deletions controller/iteration_test.go
Expand Up @@ -2,6 +2,8 @@ package controller_test

import (
"fmt"
"net/http"
"net/url"
"strings"
"testing"
"time"
Expand All @@ -19,6 +21,7 @@ import (
testsupport "github.com/almighty/almighty-core/test"
almtoken "github.com/almighty/almighty-core/token"
"github.com/almighty/almighty-core/workitem"

"github.com/goadesign/goa"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -187,9 +190,13 @@ func (rest *TestIterationREST) TestSuccessUpdateIterationWithWICounts() {
testIdentity, err := testsupport.CreateTestIdentity(rest.DB, "test user", "test provider")
require.Nil(rest.T(), err)
wirepo := workitem.NewWorkItemRepository(rest.DB)
req := &http.Request{Host: "localhost"}
params := url.Values{}
ctx := goa.NewContext(context.Background(), nil, req, params)

for i := 0; i < 4; i++ {
wi, err := wirepo.Create(
context.Background(), workitem.SystemBug,
ctx, itr.SpaceID, workitem.SystemBug,
map[string]interface{}{
workitem.SystemTitle: fmt.Sprintf("New issue #%d", i),
workitem.SystemState: workitem.SystemStateNew,
Expand All @@ -201,7 +208,7 @@ func (rest *TestIterationREST) TestSuccessUpdateIterationWithWICounts() {
}
for i := 0; i < 5; i++ {
wi, err := wirepo.Create(
context.Background(), workitem.SystemBug,
ctx, itr.SpaceID, workitem.SystemBug,
map[string]interface{}{
workitem.SystemTitle: fmt.Sprintf("Closed issue #%d", i),
workitem.SystemState: workitem.SystemStateClosed,
Expand Down