예제 #1
1
func (test *TestIterationRepository) TestListIterationBySpace() {
	t := test.T()
	resource.Require(t, resource.Database)

	repo := iteration.NewIterationRepository(test.DB)

	spaceID := uuid.NewV4()

	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)
	}
	repo.Create(context.Background(), &iteration.Iteration{
		Name:    "Other Spring #2",
		SpaceID: uuid.NewV4(),
	})

	its, err := repo.List(context.Background(), spaceID)
	assert.Nil(t, err)
	assert.Len(t, its, 3)
}
예제 #2
0
func (test *TestIterationRepository) TestCreateChildIteration() {
	t := test.T()
	resource.Require(t, resource.Database)

	repo := iteration.NewIterationRepository(test.DB)

	start := time.Now()
	end := start.Add(time.Hour * (24 * 8 * 3))
	name := "Sprint #24"
	name2 := "Sprint #24.1"

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

	i2 := iteration.Iteration{
		Name:     name2,
		SpaceID:  uuid.NewV4(),
		StartAt:  &start,
		EndAt:    &end,
		ParentID: i.ID,
	}
	repo.Create(context.Background(), &i2)

	i2L, err := repo.Load(context.Background(), i2.ID)
	require.Nil(t, err)
	assert.NotEqual(t, uuid.Nil, i2.ParentID)
	assert.Equal(t, i2.ParentID, i2L.ParentID)
}
예제 #3
0
func (test *TestIterationRepository) TestCreateIteration() {
	t := test.T()
	resource.Require(t, resource.Database)

	repo := iteration.NewIterationRepository(test.DB)

	start := time.Now()
	end := start.Add(time.Hour * (24 * 8 * 3))
	name := "Sprint #24"

	i := iteration.Iteration{
		Name:    name,
		SpaceID: uuid.NewV4(),
		StartAt: &start,
		EndAt:   &end,
	}

	repo.Create(context.Background(), &i)
	if i.ID == uuid.Nil {
		t.Errorf("Iteration was not created, ID nil")
	}

	if i.CreatedAt.After(time.Now()) {
		t.Errorf("Iteration was not created, CreatedAt after Now()?")
	}
	assert.Equal(t, start, *i.StartAt)
	assert.Equal(t, end, *i.EndAt)
	assert.Equal(t, name, i.Name)
}
// TestGetCountsPerIteration makes sure that the query being executed is correctly returning
// the counts of work items
func (s *workItemRepoBlackBoxTest) TestGetCountsPerIteration() {
	defer cleaner.DeleteCreatedEntities(s.DB)()
	// create seed data
	spaceRepo := space.NewRepository(s.DB)
	spaceInstance := space.Space{
		Name: "Testing space",
	}
	spaceRepo.Create(context.Background(), &spaceInstance)
	fmt.Println("space id = ", spaceInstance.ID)
	assert.NotEqual(s.T(), uuid.UUID{}, spaceInstance.ID)

	iterationRepo := iteration.NewIterationRepository(s.DB)
	iteration1 := iteration.Iteration{
		Name:    "Sprint 1",
		SpaceID: spaceInstance.ID,
	}
	iterationRepo.Create(context.Background(), &iteration1)
	fmt.Println("iteration1 id = ", iteration1.ID)
	assert.NotEqual(s.T(), uuid.UUID{}, iteration1.ID)

	iteration2 := iteration.Iteration{
		Name:    "Sprint 2",
		SpaceID: spaceInstance.ID,
	}
	iterationRepo.Create(context.Background(), &iteration2)
	fmt.Println("iteration2 id = ", iteration2.ID)
	assert.NotEqual(s.T(), uuid.UUID{}, iteration2.ID)

	for i := 0; i < 3; i++ {
		s.repo.Create(
			context.Background(), workitem.SystemBug,
			map[string]interface{}{
				workitem.SystemTitle:     fmt.Sprintf("New issue #%d", i),
				workitem.SystemState:     workitem.SystemStateNew,
				workitem.SystemIteration: iteration1.ID.String(),
			}, "xx")
	}
	for i := 0; i < 2; i++ {
		s.repo.Create(
			context.Background(), workitem.SystemBug,
			map[string]interface{}{
				workitem.SystemTitle:     fmt.Sprintf("Closed issue #%d", i),
				workitem.SystemState:     workitem.SystemStateClosed,
				workitem.SystemIteration: iteration1.ID.String(),
			}, "xx")
	}
	countsMap, _ := s.repo.GetCountsPerIteration(context.Background(), spaceInstance.ID)
	assert.Len(s.T(), countsMap, 1)
	require.Contains(s.T(), countsMap, iteration1.ID.String())
	assert.Equal(s.T(), 5, countsMap[iteration1.ID.String()].Total)
	assert.Equal(s.T(), 2, countsMap[iteration1.ID.String()].Closed)
}
예제 #5
0
func (test *TestIterationRepository) TestUpdateIteration() {
	t := test.T()
	resource.Require(t, resource.Database)

	repo := iteration.NewIterationRepository(test.DB)

	start := time.Now()
	end := start.Add(time.Hour * (24 * 8 * 3))
	name := "Sprint #24"

	i := iteration.Iteration{
		Name:    name,
		SpaceID: uuid.NewV4(),
		StartAt: &start,
		EndAt:   &end,
	}
	// creates an iteration
	repo.Create(context.Background(), &i)
	require.NotEqual(t, uuid.Nil, i.ID, "Iteration was not created, ID nil")

	desc := "Updated item"
	i.Description = &desc
	updatedName := "Sprint 25"
	i.Name = updatedName
	// update iteration with new values of Name and Desc
	updatedIteration, err := repo.Save(context.Background(), i)
	require.Nil(t, err)
	assert.Equal(t, updatedIteration.Name, updatedName)
	assert.Equal(t, *updatedIteration.Description, desc)

	changedStart := start.Add(time.Hour)
	i.StartAt = &changedStart
	changedEnd := start.Add(time.Hour * 2)
	i.EndAt = &changedEnd
	// update iteration with new values of StartAt, EndAt
	updatedIteration, err = repo.Save(context.Background(), i)
	require.Nil(t, err)
	assert.Equal(t, changedStart, *updatedIteration.StartAt)
	assert.Equal(t, changedEnd, *updatedIteration.EndAt)
}
예제 #6
0
func (rest *TestSpaceIterationREST) TestWICountsWithIterationListBySpace() {
	t := rest.T()
	resource.Require(t, resource.Database)
	// create seed data
	spaceRepo := space.NewRepository(rest.DB)
	spaceInstance := space.Space{
		Name: "Testing space",
	}
	spaceRepo.Create(context.Background(), &spaceInstance)
	fmt.Println("space id = ", spaceInstance.ID)
	assert.NotEqual(rest.T(), uuid.UUID{}, spaceInstance.ID)

	iterationRepo := iteration.NewIterationRepository(rest.DB)
	iteration1 := iteration.Iteration{
		Name:    "Sprint 1",
		SpaceID: spaceInstance.ID,
	}
	iterationRepo.Create(context.Background(), &iteration1)
	fmt.Println("iteration1 id = ", iteration1.ID)
	assert.NotEqual(rest.T(), uuid.UUID{}, iteration1.ID)

	iteration2 := iteration.Iteration{
		Name:    "Sprint 2",
		SpaceID: spaceInstance.ID,
	}
	iterationRepo.Create(context.Background(), &iteration2)
	fmt.Println("iteration2 id = ", iteration2.ID)
	assert.NotEqual(rest.T(), uuid.UUID{}, iteration2.ID)

	wirepo := workitem.NewWorkItemRepository(rest.DB)

	for i := 0; i < 3; i++ {
		wirepo.Create(
			context.Background(), workitem.SystemBug,
			map[string]interface{}{
				workitem.SystemTitle:     fmt.Sprintf("New issue #%d", i),
				workitem.SystemState:     workitem.SystemStateNew,
				workitem.SystemIteration: iteration1.ID.String(),
			}, "xx")
	}
	for i := 0; i < 2; i++ {
		wirepo.Create(
			context.Background(), workitem.SystemBug,
			map[string]interface{}{
				workitem.SystemTitle:     fmt.Sprintf("Closed issue #%d", i),
				workitem.SystemState:     workitem.SystemStateClosed,
				workitem.SystemIteration: iteration1.ID.String(),
			}, "xx")
	}

	svc, ctrl := rest.UnSecuredController()
	_, cs := test.ListSpaceIterationsOK(t, svc.Context, svc, ctrl, spaceInstance.ID.String())
	assert.Len(t, cs.Data, 2)
	for _, iterationItem := range cs.Data {
		if iterationItem.ID.String() == iteration1.ID.String() {
			assert.Equal(t, 5, iterationItem.Relationships.Workitems.Meta["total"])
			assert.Equal(t, 2, iterationItem.Relationships.Workitems.Meta["closed"])
		} else if iterationItem.ID.String() == iteration2.ID.String() {
			assert.Equal(t, 0, iterationItem.Relationships.Workitems.Meta["total"])
			assert.Equal(t, 0, iterationItem.Relationships.Workitems.Meta["closed"])
		}
	}
	// seed 5 WI to iteration2
	for i := 0; i < 5; i++ {
		wirepo.Create(
			context.Background(), workitem.SystemBug,
			map[string]interface{}{
				workitem.SystemTitle:     fmt.Sprintf("New issue #%d", i),
				workitem.SystemState:     workitem.SystemStateNew,
				workitem.SystemIteration: iteration2.ID.String(),
			}, "xx")
	}
	_, cs = test.ListSpaceIterationsOK(t, svc.Context, svc, ctrl, spaceInstance.ID.String())
	assert.Len(t, cs.Data, 2)
	for _, iterationItem := range cs.Data {
		if iterationItem.ID.String() == iteration1.ID.String() {
			assert.Equal(t, 5, iterationItem.Relationships.Workitems.Meta["total"])
			assert.Equal(t, 2, iterationItem.Relationships.Workitems.Meta["closed"])
		} else if iterationItem.ID.String() == iteration2.ID.String() {
			assert.Equal(t, 5, iterationItem.Relationships.Workitems.Meta["total"])
			assert.Equal(t, 0, iterationItem.Relationships.Workitems.Meta["closed"])
		}
	}
}
예제 #7
0
// Iterations returns a iteration repository
func (g *GormBase) Iterations() iteration.Repository {
	return iteration.NewIterationRepository(g.db)
}