func (rest *TestSpaceIterationREST) TestSuccessCreateIterationWithOptionalValues() {
	t := rest.T()
	resource.Require(t, resource.Database)

	var p *space.Space
	iterationName := "Sprint #22"
	iterationDesc := "testing description"
	ci := createSpaceIteration(iterationName, &iterationDesc)

	application.Transactional(rest.db, func(app application.Application) error {
		repo := app.Spaces()
		testSpace := space.Space{
			Name: "Test 1",
		}
		p, _ = repo.Create(context.Background(), &testSpace)
		return nil
	})
	svc, ctrl := rest.SecuredController()
	_, c := test.CreateSpaceIterationsCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
	assert.NotNil(t, c.Data.ID)
	assert.NotNil(t, c.Data.Relationships.Space)
	assert.Equal(t, p.ID.String(), *c.Data.Relationships.Space.Data.ID)
	assert.Equal(t, *c.Data.Attributes.Name, iterationName)
	assert.Equal(t, *c.Data.Attributes.Description, iterationDesc)

	// create another Iteration with nil description
	iterationName2 := "Sprint #23"
	ci = createSpaceIteration(iterationName2, nil)
	_, c = test.CreateSpaceIterationsCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
	assert.Equal(t, *c.Data.Attributes.Name, iterationName2)
	assert.Nil(t, c.Data.Attributes.Description)
}
func (tester *TestSearchSpaces) createTestData() ([]space.Space, error) {
	names := []string{"TEST_A", "TEST_AB", "TEST_B", "TEST_C"}
	for i := 0; i < 20; i++ {
		names = append(names, "TEST_"+strconv.Itoa(i))
	}

	spaces := []space.Space{}

	err := application.Transactional(tester.db, func(app application.Application) error {
		for _, name := range names {
			space := space.Space{
				Name:        name,
				Description: strings.ToTitle("description for " + name),
			}
			newSpace, err := app.Spaces().Create(context.Background(), &space)
			if err != nil {
				return err
			}
			spaces = append(spaces, *newSpace)
		}
		return nil
	})
	if err != nil {
		return nil, fmt.Errorf("Failed to insert testdata", err)
	}
	return spaces, nil
}
Example #3
0
func createSpaceAndIteration(t *testing.T, db *gormapplication.GormDB) iteration.Iteration {
	var itr iteration.Iteration
	application.Transactional(db, func(app application.Application) error {
		repo := app.Iterations()

		newSpace := space.Space{
			Name: "Test 1" + uuid.NewV4().String(),
		}
		p, err := app.Spaces().Create(context.Background(), &newSpace)
		if err != nil {
			t.Error(err)
		}
		start := time.Now()
		end := start.Add(time.Hour * (24 * 8 * 3))
		name := "Sprint #2"

		i := iteration.Iteration{
			Name:    name,
			SpaceID: p.ID,
			StartAt: &start,
			EndAt:   &end,
		}
		repo.Create(context.Background(), &i)
		itr = i
		return nil
	})
	return itr
}
Example #4
0
func (rest *TestSpaceAreaREST) TestListAreas() {
	t := rest.T()
	resource.Require(t, resource.Database)

	// Create a new space where we'll create 3 areas
	var s *space.Space

	// Create another space where we'll create 1 area.
	var anotherSpace *space.Space

	application.Transactional(rest.db, func(app application.Application) error {
		var err error
		repo := app.Spaces()
		newSpace := &space.Space{
			Name: "Test Space 1" + uuid.NewV4().String(),
		}
		s, err = repo.Create(context.Background(), newSpace)
		require.Nil(t, err)

		newSpace = &space.Space{
			Name: "Another space" + uuid.NewV4().String(),
		}
		anotherSpace, err = repo.Create(context.Background(), newSpace)
		require.Nil(t, err)
		return nil
	})

	svc, ctrl := rest.SecuredController()
	spaceId := s.ID
	anotherSpaceId := anotherSpace.ID
	var createdAreaUuids1 []uuid.UUID

	for i := 0; i < 3; i++ {
		name := "Test Area #20" + strconv.Itoa(i)
		spaceAreaContext := createSpaceArea(name, &name)
		_, c := test.CreateSpaceAreasCreated(t, svc.Context, svc, ctrl, spaceId.String(), spaceAreaContext)
		require.NotNil(t, c.Data.ID)
		require.NotNil(t, c.Data.Relationships.Space)
		createdAreaUuids1 = append(createdAreaUuids1, *c.Data.ID)
	}

	name := "area in a different space"
	anotherSpaceAreaContext := createSpaceArea(name, &name)
	_, createdArea := test.CreateSpaceAreasCreated(t, svc.Context, svc, ctrl, anotherSpaceId.String(), anotherSpaceAreaContext)
	require.NotNil(t, createdArea)

	_, areaList := test.ListSpaceAreasOK(t, svc.Context, svc, ctrl, spaceId.String())
	assert.Len(t, areaList.Data, 3)
	for i := 0; i < len(createdAreaUuids1); i++ {
		assert.NotNil(t, searchInAreaSlice(createdAreaUuids1[i], areaList))
	}

	_, anotherAreaList := test.ListSpaceAreasOK(t, svc.Context, svc, ctrl, anotherSpaceId.String())
	assert.Len(t, anotherAreaList.Data, 1)
	assert.Equal(t, anotherAreaList.Data[0].ID, createdArea.Data.ID)

}
func (rest *TestSpaceIterationREST) TestListIterationsBySpace() {
	t := rest.T()
	resource.Require(t, resource.Database)

	var spaceID uuid.UUID
	application.Transactional(rest.db, func(app application.Application) error {
		repo := app.Iterations()

		newSpace := space.Space{
			Name: "Test 1",
		}
		p, err := app.Spaces().Create(context.Background(), &newSpace)
		if err != nil {
			t.Error(err)
		}
		spaceID = p.ID

		for i := 0; i < 3; i++ {
			start := time.Now()
			end := start.Add(time.Hour * (24 * 8 * 3))
			name := "Sprint #2" + strconv.Itoa(i)

			i := iteration.Iteration{
				Name:    name,
				SpaceID: spaceID,
				StartAt: &start,
				EndAt:   &end,
			}
			repo.Create(context.Background(), &i)
		}
		return nil
	})

	svc, ctrl := rest.UnSecuredController()
	_, cs := test.ListSpaceIterationsOK(t, svc.Context, svc, ctrl, spaceID.String())
	assert.Len(t, cs.Data, 3)
	for _, iterationItem := range cs.Data {
		subString := fmt.Sprintf("?filter[iteration]=%s", iterationItem.ID.String())
		require.Contains(t, *iterationItem.Relationships.Workitems.Links.Related, subString)
		assert.Equal(t, 0, iterationItem.Relationships.Workitems.Meta["total"])
		assert.Equal(t, 0, iterationItem.Relationships.Workitems.Meta["closed"])
	}
}
Example #6
0
func (rest *TestSpaceAreaREST) TestSuccessCreateArea() {
	t := rest.T()

	resource.Require(t, resource.Database)

	var p *space.Space
	ci := createSpaceArea("Area #21", nil)

	application.Transactional(rest.db, func(app application.Application) error {
		repo := app.Spaces()
		newSpace := &space.Space{
			Name: "Test 1" + uuid.NewV4().String(),
		}
		p, _ = repo.Create(context.Background(), newSpace)
		return nil
	})
	svc, ctrl := rest.SecuredController()
	_, c := test.CreateSpaceAreasCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
	require.NotNil(t, c.Data.ID)
	require.NotNil(t, c.Data.Relationships.Space)
	assert.Equal(t, p.ID.String(), *c.Data.Relationships.Space.Data.ID)
}
func (rest *TestSpaceIterationREST) TestSuccessCreateIteration() {
	t := rest.T()
	resource.Require(t, resource.Database)

	var p *space.Space
	ci := createSpaceIteration("Sprint #21", nil)

	application.Transactional(rest.db, func(app application.Application) error {
		repo := app.Spaces()
		newSpace := space.Space{
			Name: "Test 1",
		}
		p, _ = repo.Create(context.Background(), &newSpace)
		return nil
	})
	svc, ctrl := rest.SecuredController()
	_, c := test.CreateSpaceIterationsCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
	require.NotNil(t, c.Data.ID)
	require.NotNil(t, c.Data.Relationships.Space)
	assert.Equal(t, p.ID.String(), *c.Data.Relationships.Space.Data.ID)
	assert.Equal(t, iteration.IterationStateNew, *c.Data.Attributes.State)
}
Example #8
0
func createSpaceAndArea(t *testing.T, db *gormapplication.GormDB) area.Area {
	var areaObj area.Area
	application.Transactional(db, func(app application.Application) error {
		repo := app.Areas()

		newSpace := &space.Space{
			Name: "Test Space 1" + uuid.NewV4().String(),
		}
		p, err := app.Spaces().Create(context.Background(), newSpace)
		if err != nil {
			t.Error(err)
		}
		name := "Area #2"

		i := area.Area{
			Name:    name,
			SpaceID: p.ID,
		}
		repo.Create(context.Background(), &i)
		areaObj = i
		return nil
	})
	return areaObj
}