예제 #1
0
func TestWorkItemLinkTypeCheckValidForCreation(t *testing.T) {
	t.Parallel()
	resource.Require(t, resource.UnitTest)

	description := "An example description"
	a := link.WorkItemLinkType{
		ID:             satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573e231"),
		Name:           "Example work item link category",
		Description:    &description,
		Topology:       link.TopologyNetwork,
		Version:        0,
		SourceTypeName: workitem.SystemBug,
		TargetTypeName: workitem.SystemUserStory,
		ForwardName:    "blocks",
		ReverseName:    "blocked by",
		LinkCategoryID: satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573eAAA"),
	}

	// Check valid
	b := a
	require.Nil(t, b.CheckValidForCreation())

	// Check empty Name
	b = a
	b.Name = ""
	require.NotNil(t, b.CheckValidForCreation())

	// Check empty SourceTypeName
	b = a
	b.SourceTypeName = ""
	require.NotNil(t, b.CheckValidForCreation())

	// Check empty TargetTypeName
	b = a
	b.TargetTypeName = ""
	require.NotNil(t, b.CheckValidForCreation())

	// Check empty ForwardName
	b = a
	b.ForwardName = ""
	require.NotNil(t, b.CheckValidForCreation())

	// Check empty ReverseName
	b = a
	b.ReverseName = ""
	require.NotNil(t, b.CheckValidForCreation())

	// Check empty Topology
	b = a
	b.Topology = ""
	require.NotNil(t, b.CheckValidForCreation())

	// Check empty LinkCategoryID
	b = a
	b.LinkCategoryID = satoriuuid.Nil
	require.NotNil(t, b.CheckValidForCreation())
}
// TestWorkItemType_Equal Tests equality of two work item link categories
func TestWorkItemLinkCategory_Equal(t *testing.T) {
	t.Parallel()
	resource.Require(t, resource.UnitTest)

	description := "An example description"
	a := link.WorkItemLinkCategory{
		ID:          satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573e231"),
		Name:        "Example work item link category",
		Description: &description,
		Version:     0,
	}

	// Test types
	b := convert.DummyEqualer{}
	require.False(t, a.Equal(b))

	// Test lifecycle
	c := a
	c.Lifecycle = gormsupport.Lifecycle{CreatedAt: time.Now().Add(time.Duration(1000))}
	require.False(t, a.Equal(c))

	// Test version
	c = a
	c.Version += 1
	require.False(t, a.Equal(c))

	// Test name
	c = a
	c.Name = "bar"
	require.False(t, a.Equal(c))

	// Test description
	otherDescription := "bar"
	c = a
	c.Description = &otherDescription
	require.False(t, a.Equal(c))

	// Test equality
	c = a
	require.True(t, a.Equal(c))

	// Test ID
	c = a
	c.ID = satoriuuid.FromStringOrNil("33371e36-871b-43a6-9166-0c4bd573e333")
	require.False(t, a.Equal(c))

	// Test when one Description is nil
	c = a
	c.Description = nil
	require.False(t, a.Equal(c))
}
예제 #3
0
// TestWorkItemLink_Equal Tests equality of two work item links
func TestWorkItemLink_Equal(t *testing.T) {
	t.Parallel()
	resource.Require(t, resource.UnitTest)

	a := link.WorkItemLink{
		ID:         satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573e231"),
		SourceID:   1,
		TargetID:   2,
		LinkTypeID: satoriuuid.FromStringOrNil("966e982c-615c-4879-961f-56e912cbc4f2"),
	}

	// Test equality
	b := a
	require.True(t, a.Equal(b))

	// Test types
	c := convert.DummyEqualer{}
	require.False(t, a.Equal(c))

	// Test lifecycle
	b = a
	b.Lifecycle = gormsupport.Lifecycle{CreatedAt: time.Now().Add(time.Duration(1000))}
	require.False(t, a.Equal(b))

	// Test ID
	b = a
	b.ID = satoriuuid.FromStringOrNil("10616dae-0a28-4de5-9d79-c831dbcfd039")
	require.False(t, a.Equal(b))

	// Test Version
	b = a
	b.Version += 1
	require.False(t, a.Equal(b))

	// Test SourceID
	b = a
	b.SourceID = 1292387473
	require.False(t, a.Equal(b))

	// Test TargetID
	b = a
	b.TargetID = 93092303290
	require.False(t, a.Equal(b))

	// Test LinkTypeID
	b = a
	b.LinkTypeID = satoriuuid.FromStringOrNil("10a41146-3868-47cd-84ae-f96ea4c9d797")
	require.False(t, a.Equal(b))
}
func TestWorkItemLinkCategory_ConvertLinkCategoryFromModel(t *testing.T) {
	t.Parallel()
	resource.Require(t, resource.UnitTest)

	description := "An example description"
	m := link.WorkItemLinkCategory{
		ID:          satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573e231"),
		Name:        "Example work item link category",
		Description: &description,
		Version:     0,
	}

	id := m.ID.String()
	expected := app.WorkItemLinkCategorySingle{
		Data: &app.WorkItemLinkCategoryData{
			Type: link.EndpointWorkItemLinkCategories,
			ID:   &id,
			Attributes: &app.WorkItemLinkCategoryAttributes{
				Name:        &m.Name,
				Description: m.Description,
				Version:     &m.Version,
			},
		},
	}

	actual := link.ConvertLinkCategoryFromModel(m)
	require.Equal(t, expected.Data.Type, actual.Data.Type)
	require.Equal(t, *expected.Data.ID, *actual.Data.ID)
	require.Equal(t, *expected.Data.Attributes.Name, *actual.Data.Attributes.Name)
	require.Equal(t, *expected.Data.Attributes.Description, *actual.Data.Attributes.Description)
	require.Equal(t, *expected.Data.Attributes.Version, *actual.Data.Attributes.Version)
}
// cleanup removes all DB entries that will be created or have been created
// with this test suite. We need to remove them completely and not only set the
// "deleted_at" field, which is why we need the Unscoped() function.
func (s *workItemLinkSuite) cleanup() {
	db := s.db

	// First delete work item links and then the types;
	// otherwise referential integrity will be violated.
	for _, id := range s.deleteWorkItemLinks {
		db = db.Unscoped().Delete(&link.WorkItemLink{ID: satoriuuid.FromStringOrNil(id)})
		require.Nil(s.T(), db.Error)
	}
	s.deleteWorkItemLinks = nil

	// Delete all work item links for now
	db.Unscoped().Delete(&link.WorkItemLink{})
	require.Nil(s.T(), db.Error)

	// Delete work item link types and categories by name.
	// They will be created during the tests but have to be deleted by name
	// rather than ID, unlike the work items or work item links.
	db = db.Unscoped().Delete(&link.WorkItemLinkType{Name: "test-bug-blocker"})
	require.Nil(s.T(), db.Error)
	db = db.Unscoped().Delete(&link.WorkItemLinkCategory{Name: "test-user"})
	require.Nil(s.T(), db.Error)

	// Last but not least delete the work items
	for _, idStr := range s.deleteWorkItems {
		id, err := strconv.ParseUint(idStr, 10, 64)
		require.Nil(s.T(), err)
		db = db.Unscoped().Delete(&workitem.WorkItem{ID: id})
		require.Nil(s.T(), db.Error)
	}
	s.deleteWorkItems = nil

}
예제 #6
0
func TestWorkItemLinkCheckValidForCreation(t *testing.T) {
	t.Parallel()
	resource.Require(t, resource.UnitTest)

	a := link.WorkItemLink{
		ID:         satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573e231"),
		SourceID:   1,
		TargetID:   2,
		LinkTypeID: satoriuuid.FromStringOrNil("966e982c-615c-4879-961f-56e912cbc4f2"),
	}

	// Check valid
	b := a
	require.Nil(t, b.CheckValidForCreation())

	// Check empty LinkTypeID
	b = a
	b.LinkTypeID = satoriuuid.Nil
	require.NotNil(t, b.CheckValidForCreation())
}
// CreateWorkItemLink defines a work item link
func CreateWorkItemLink(sourceID uint64, targetID uint64, linkTypeID string) *app.CreateWorkItemLinkPayload {
	lt := link.WorkItemLink{
		SourceID:   sourceID,
		TargetID:   targetID,
		LinkTypeID: satoriuuid.FromStringOrNil(linkTypeID),
	}
	payload := link.ConvertLinkFromModel(lt)
	// The create payload is required during creation. Simply copy data over.
	return &app.CreateWorkItemLinkPayload{
		Data: payload.Data,
	}
}
// CreateWorkItemLinkType defines a work item link type
func CreateWorkItemLinkType(name string, sourceType string, targetType string, categoryID string) *app.CreateWorkItemLinkTypePayload {
	description := "Specify that one bug blocks another one."
	lt := link.WorkItemLinkType{
		Name:           name,
		Description:    &description,
		SourceTypeName: sourceType,
		TargetTypeName: targetType,
		Topology:       link.TopologyNetwork,
		ForwardName:    "forward name string for " + name,
		ReverseName:    "reverse name string for " + name,
		LinkCategoryID: satoriuuid.FromStringOrNil(categoryID),
	}
	payload := link.ConvertLinkTypeFromModel(lt)
	// The create payload is required during creation. Simply copy data over.
	return &app.CreateWorkItemLinkTypePayload{
		Data: payload.Data,
	}
}
예제 #9
0
// TestWorkItemType_Equal Tests equality of two work item link types
func TestWorkItemLinkType_Equal(t *testing.T) {
	t.Parallel()
	resource.Require(t, resource.UnitTest)

	description := "An example description"
	a := link.WorkItemLinkType{
		ID:             satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573e231"),
		Name:           "Example work item link category",
		Description:    &description,
		Topology:       "network",
		Version:        0,
		SourceTypeName: workitem.SystemBug,
		TargetTypeName: workitem.SystemUserStory,
		ForwardName:    "blocks",
		ReverseName:    "blocked by",
		LinkCategoryID: satoriuuid.FromStringOrNil("0e671e36-871b-43a6-9166-0c4bd573eAAA"),
	}

	// Test equality
	b := a
	require.True(t, a.Equal(b))

	// Test types
	c := convert.DummyEqualer{}
	require.False(t, a.Equal(c))

	// Test lifecycle
	b = a
	b.Lifecycle = gormsupport.Lifecycle{CreatedAt: time.Now().Add(time.Duration(1000))}
	require.False(t, a.Equal(b))

	// Test ID
	b = a
	b.ID = satoriuuid.FromStringOrNil("CCC71e36-871b-43a6-9166-0c4bd573eCCC")
	require.False(t, a.Equal(b))

	// Test Version
	b = a
	b.Version += 1
	require.False(t, a.Equal(b))

	// Test Name
	b = a
	b.Name = "bar"
	require.False(t, a.Equal(b))

	// Test Description
	otherDescription := "bar"
	b = a
	b.Description = &otherDescription
	require.False(t, a.Equal(b))

	// Test Topology
	b = a
	b.Topology = "tree"
	require.False(t, a.Equal(b))

	// Test SourceTypeName
	b = a
	b.SourceTypeName = "foobar"
	require.False(t, a.Equal(b))

	// Test TargetTypeName
	b = a
	b.TargetTypeName = "fooooobar"
	require.False(t, a.Equal(b))

	// Test ForwardName
	b = a
	b.ForwardName = "go, go, go!"
	require.False(t, a.Equal(b))

	// Test ReverseName
	b = a
	b.ReverseName = "backup, backup!"
	require.False(t, a.Equal(b))

	// Test LinkCategoryID
	b = a
	b.LinkCategoryID = satoriuuid.FromStringOrNil("aaa71e36-871b-43a6-9166-0c4bd573eCCC")
	require.False(t, a.Equal(b))
}