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

Commit

Permalink
Don't have a zero-parent relationship for root iteration/area (#2283)
Browse files Browse the repository at this point in the history
Before a root iteration/area had a parent iteration with a zeroed UUID:

```yaml
"relationships": {
      "parent": {
        "data": {
          "id": "00000000-0000-0000-0000-000000000000",
          "type": "iterations"
        },
```

That is removed now.

This adds a test that shows how a root and a child iteration/area are represented on JSONAPI level.

Added `testfixture.SetAreaNames()` and `testfixture.AreaByName()` functions as well.

This fixes the root cause for openshiftio/openshift.io#4309 . The UI fix in Raunak1203/fabric8-planner@e7c34a2 only fixes a symptom by implementing a work around.
  • Loading branch information
kwk authored Sep 17, 2018
1 parent d6a192d commit f276f3a
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 67 deletions.
2 changes: 1 addition & 1 deletion controller/area.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func ConvertArea(db application.DB, request *http.Request, ar area.Area, options

// Now check the path, if the path is empty, then this is the topmost area
// in a specific space.
if ar.Path.ParentPath().IsEmpty() == false {
if !ar.Path.ParentPath().IsEmpty() {
parent := ar.Path.ParentID().String()
i.Relationships.Parent = &app.RelationGeneric{
Data: &app.GenericData{
Expand Down
14 changes: 9 additions & 5 deletions controller/area_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,22 @@ func (rest *TestAreaREST) TestCreateChildArea() {
})
}

func (rest *TestAreaREST) TestShowArea() {
func (rest *TestAreaREST) TestShow() {
rest.T().Run("Success", func(t *testing.T) {
// Setup
a := tf.NewTestFixture(t, rest.DB, tf.Areas(1)).Areas[0]
fxt := tf.NewTestFixture(t, rest.DB,
tf.CreateWorkItemEnvironment(),
tf.Areas(1, tf.SetAreaNames("root")),
)
a := fxt.AreaByName("root")
svc, ctrl := rest.SecuredController()
t.Run("OK", func(t *testing.T) {
t.Run("root", func(t *testing.T) {
// when
res, area := test.ShowAreaOK(t, svc.Context, svc, ctrl, a.ID.String(), nil, nil)
safeOverriteHeader(t, res, app.ETag, "0icd7ov5CqwDXN6Fx9z18g==")
//then
compareWithGoldenAgnostic(t, filepath.Join(rest.testDir, "show", "ok.res.payload.golden.json"), area)
compareWithGoldenAgnostic(t, filepath.Join(rest.testDir, "show", "ok.res.headers.golden.json"), res.Header())
compareWithGoldenAgnostic(t, filepath.Join(rest.testDir, "show", "ok-root-area.res.payload.golden.json"), area)
compareWithGoldenAgnostic(t, filepath.Join(rest.testDir, "show", "ok-root-area.headers.golden.json"), res.Header())
})

t.Run("Using ExpiredIfModifedSince Header", func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions controller/iteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package controller
import (
"context"
"fmt"
"net/http"

"github.com/fabric8-services/fabric8-wit/app"
"github.com/fabric8-services/fabric8-wit/application"
"github.com/fabric8-services/fabric8-wit/errors"
Expand All @@ -14,7 +16,6 @@ import (
"github.com/fabric8-services/fabric8-wit/space"
"github.com/fabric8-services/fabric8-wit/space/authz"
"github.com/fabric8-services/fabric8-wit/workitem"
"net/http"

"github.com/goadesign/goa"
uuid "github.com/satori/go.uuid"
Expand Down Expand Up @@ -497,7 +498,7 @@ func ConvertIteration(request *http.Request, itr iteration.Iteration, additional
Related: &relatedURL,
},
}
if itr.Path.IsEmpty() == false {
if !itr.Path.ParentPath().IsEmpty() {
parentID := itr.Path.ParentID().String()
parentRelatedURL := rest.AbsoluteURL(request, app.IterationHref(parentID))
i.Relationships.Parent = &app.RelationGeneric{
Expand Down
64 changes: 46 additions & 18 deletions controller/iteration_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ package controller_test
import (
"context"
"fmt"
"net/http"
"net/url"
"path/filepath"
"strings"
"testing"
"time"

token "github.com/dgrijalva/jwt-go"
"github.com/fabric8-services/fabric8-wit/account"
"github.com/fabric8-services/fabric8-wit/app"
Expand All @@ -24,12 +31,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"net/http"
"net/url"
"path/filepath"
"strings"
"testing"
"time"
)

type TestIterationREST struct {
Expand Down Expand Up @@ -265,20 +266,47 @@ func (rest *TestIterationREST) TestFailValidationIterationNameStartWith() {
assert.Contains(rest.T(), err.Error(), "type.name must match the regexp")
}

func (rest *TestIterationREST) TestShowIterationOK() {

func (rest *TestIterationREST) TestShow() {
// given
fxt := tf.NewTestFixture(rest.T(), rest.DB, createSpaceAndRootAreaAndIterations()...)
itr := *fxt.Iterations[1]
fxt := tf.NewTestFixture(rest.T(), rest.DB,
tf.CreateWorkItemEnvironment(),
tf.Iterations(2,
tf.SetIterationNames("root", "child"),
func(fxt *tf.TestFixture, idx int) error {
switch idx {
case 1:
start, err := time.Parse(time.RFC822, "02 Jan 06 15:04 MST")
if err != nil {
return err
}
fxt.Iterations[idx].StartAt = &start
fxt.Iterations[idx].EndAt = ptr.Time(start.Add(time.Hour * 24 * 365 * 100))
}
return nil
}),
tf.Areas(2),
)
svc, ctrl := rest.SecuredController()
// when
_, created := test.ShowIterationOK(rest.T(), svc.Context, svc, ctrl, itr.ID.String(), nil, nil)
// then
assertIterationLinking(rest.T(), created.Data)
require.NotNil(rest.T(), created.Data.Relationships.Workitems.Meta)
assert.Equal(rest.T(), 0, created.Data.Relationships.Workitems.Meta[KeyTotalWorkItems])
assert.Equal(rest.T(), 0, created.Data.Relationships.Workitems.Meta[KeyClosedWorkItems])
compareWithGoldenAgnostic(rest.T(), filepath.Join(rest.testDir, "show", "ok.res.iteration.golden.json"), created)
rest.T().Run("root iteration", func(t *testing.T) {
// when
_, i := test.ShowIterationOK(t, svc.Context, svc, ctrl, fxt.IterationByName("root").ID.String(), nil, nil)
// then
assertIterationLinking(t, i.Data)
require.NotNil(t, i.Data.Relationships.Workitems.Meta)
assert.Equal(t, 0, i.Data.Relationships.Workitems.Meta[KeyTotalWorkItems])
assert.Equal(t, 0, i.Data.Relationships.Workitems.Meta[KeyClosedWorkItems])
compareWithGoldenAgnostic(t, filepath.Join(rest.testDir, "show", "ok-root-iteration.res.payload.golden.json"), i)
})
rest.T().Run("child iteration", func(t *testing.T) {
// when
_, i := test.ShowIterationOK(t, svc.Context, svc, ctrl, fxt.IterationByName("child").ID.String(), nil, nil)
// then
assertIterationLinking(t, i.Data)
require.NotNil(t, i.Data.Relationships.Workitems.Meta)
assert.Equal(t, 0, i.Data.Relationships.Workitems.Meta[KeyTotalWorkItems])
assert.Equal(t, 0, i.Data.Relationships.Workitems.Meta[KeyClosedWorkItems])
compareWithGoldenAgnostic(t, filepath.Join(rest.testDir, "show", "ok-child-iteration.res.payload.golden.json"), i)
})
}

func (rest *TestIterationREST) TestShowIterationOKUsingExpiredIfModifiedSinceHeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
"data": {
"attributes": {
"created-at": "0001-01-01T00:00:00Z",
"name": "area 00000000-0000-0000-0000-000000000001",
"name": "root",
"parent_path": "/",
"parent_path_resolved": "/",
"updated-at": "0001-01-01T00:00:00Z",
"version": 0
},
"id": "00000000-0000-0000-0000-000000000002",
"id": "00000000-0000-0000-0000-000000000001",
"links": {
"related": "http:///api/areas/00000000-0000-0000-0000-000000000002",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000002"
"related": "http:///api/areas/00000000-0000-0000-0000-000000000001",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000001"
},
"relationships": {
"children": {
"links": {
"related": "http:///api/areas/00000000-0000-0000-0000-000000000002/children",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000002/children"
"related": "http:///api/areas/00000000-0000-0000-0000-000000000001/children",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000001/children"
}
},
"space": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"id": "00000000-0000-0000-0000-000000000002",
"type": "spaces"
},
"links": {
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000003",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000003"
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000002",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000002"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
"data": {
"attributes": {
"created-at": "0001-01-01T00:00:00Z",
"name": "area 00000000-0000-0000-0000-000000000001",
"name": "root",
"parent_path": "/",
"parent_path_resolved": "/",
"updated-at": "0001-01-01T00:00:00Z",
"version": 0
},
"id": "00000000-0000-0000-0000-000000000002",
"id": "00000000-0000-0000-0000-000000000001",
"links": {
"related": "http:///api/areas/00000000-0000-0000-0000-000000000002",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000002"
"related": "http:///api/areas/00000000-0000-0000-0000-000000000001",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000001"
},
"relationships": {
"children": {
"links": {
"related": "http:///api/areas/00000000-0000-0000-0000-000000000002/children",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000002/children"
"related": "http:///api/areas/00000000-0000-0000-0000-000000000001/children",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000001/children"
}
},
"space": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"id": "00000000-0000-0000-0000-000000000002",
"type": "spaces"
},
"links": {
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000003",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000003"
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000002",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000002"
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions controller/test-files/area/show/ok-root-area.headers.golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Cache-Control": [
"private,max-age=120"
],
"Content-Type": [
"application/vnd.api+json"
],
"Etag": [
"0icd7ov5CqwDXN6Fx9z18g=="
],
"Last-Modified": [
"Mon, 01 Jan 0001 00:00:00 GMT"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
"data": {
"attributes": {
"created-at": "0001-01-01T00:00:00Z",
"name": "area 00000000-0000-0000-0000-000000000001",
"name": "root",
"parent_path": "/",
"parent_path_resolved": "/",
"updated-at": "0001-01-01T00:00:00Z",
"version": 0
},
"id": "00000000-0000-0000-0000-000000000002",
"id": "00000000-0000-0000-0000-000000000001",
"links": {
"related": "http:///api/areas/00000000-0000-0000-0000-000000000002",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000002"
"related": "http:///api/areas/00000000-0000-0000-0000-000000000001",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000001"
},
"relationships": {
"children": {
"links": {
"related": "http:///api/areas/00000000-0000-0000-0000-000000000002/children",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000002/children"
"related": "http:///api/areas/00000000-0000-0000-0000-000000000001/children",
"self": "http:///api/areas/00000000-0000-0000-0000-000000000001/children"
}
},
"space": {
"data": {
"id": "00000000-0000-0000-0000-000000000003",
"id": "00000000-0000-0000-0000-000000000002",
"type": "spaces"
},
"links": {
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000003",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000003"
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000002",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000002"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@
"attributes": {
"active_status": true,
"created-at": "0001-01-01T00:00:00Z",
"description": "some description (see function github.com/fabric8-services/fabric8-wit/controller_test.(*TestIterationREST).TestShowIterationOK in controller/iteration_blackbox_test.go)",
"description": "some description (see function github.com/fabric8-services/fabric8-wit/controller_test.(*TestIterationREST).TestShow in controller/iteration_blackbox_test.go)",
"endAt": "0001-01-01T00:00:00Z",
"name": "iteration 00000000-0000-0000-0000-000000000001",
"parent_path": "/00000000-0000-0000-0000-000000000002",
"resolved_parent_path": "/space 00000000-0000-0000-0000-000000000003",
"name": "child",
"parent_path": "/00000000-0000-0000-0000-000000000001",
"resolved_parent_path": "/root",
"startAt": "0001-01-01T00:00:00Z",
"state": "new",
"updated-at": "0001-01-01T00:00:00Z",
"user_active": false
},
"id": "00000000-0000-0000-0000-000000000004",
"id": "00000000-0000-0000-0000-000000000002",
"links": {
"related": "http:///api/iterations/00000000-0000-0000-0000-000000000004",
"self": "http:///api/iterations/00000000-0000-0000-0000-000000000004"
"related": "http:///api/iterations/00000000-0000-0000-0000-000000000002",
"self": "http:///api/iterations/00000000-0000-0000-0000-000000000002"
},
"relationships": {
"parent": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"id": "00000000-0000-0000-0000-000000000001",
"type": "iterations"
},
"links": {
"related": "http:///api/iterations/00000000-0000-0000-0000-000000000002",
"self": "http:///api/iterations/00000000-0000-0000-0000-000000000002"
"related": "http:///api/iterations/00000000-0000-0000-0000-000000000001",
"self": "http:///api/iterations/00000000-0000-0000-0000-000000000001"
}
},
"space": {
"data": {
"id": "00000000-0000-0000-0000-000000000005",
"id": "00000000-0000-0000-0000-000000000003",
"type": "spaces"
},
"links": {
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000005",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000005"
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000003",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000003"
}
},
"workitems": {
"links": {
"related": "http:///api/workitems/?filter[iteration]=00000000-0000-0000-0000-000000000004"
"related": "http:///api/workitems/?filter[iteration]=00000000-0000-0000-0000-000000000002"
},
"meta": {
"closed": 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"data": {
"attributes": {
"active_status": false,
"created-at": "0001-01-01T00:00:00Z",
"description": "some description (see function github.com/fabric8-services/fabric8-wit/controller_test.(*TestIterationREST).TestShow in controller/iteration_blackbox_test.go)",
"name": "root",
"parent_path": "/",
"resolved_parent_path": "/",
"state": "new",
"updated-at": "0001-01-01T00:00:00Z",
"user_active": false
},
"id": "00000000-0000-0000-0000-000000000001",
"links": {
"related": "http:///api/iterations/00000000-0000-0000-0000-000000000001",
"self": "http:///api/iterations/00000000-0000-0000-0000-000000000001"
},
"relationships": {
"space": {
"data": {
"id": "00000000-0000-0000-0000-000000000002",
"type": "spaces"
},
"links": {
"related": "http:///api/spaces/00000000-0000-0000-0000-000000000002",
"self": "http:///api/spaces/00000000-0000-0000-0000-000000000002"
}
},
"workitems": {
"links": {
"related": "http:///api/workitems/?filter[iteration]=00000000-0000-0000-0000-000000000001"
},
"meta": {
"closed": 0,
"total": 0
}
}
},
"type": "iterations"
}
}
Loading

0 comments on commit f276f3a

Please sign in to comment.