Ejemplo n.º 1
0
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)
}
Ejemplo n.º 2
0
func createOrUpdateWorkItemLinkCategory(ctx context.Context, linkCatRepo *link.GormWorkItemLinkCategoryRepository, name string, description string) error {
	cat, err := linkCatRepo.LoadCategoryFromDB(ctx, name)
	cause := errs.Cause(err)
	switch cause.(type) {
	case errors.NotFoundError:
		_, err := linkCatRepo.Create(ctx, &name, &description)
		if err != nil {
			return errs.WithStack(err)
		}
	case nil:
		log.Info(ctx, map[string]interface{}{
			"pkg":      "migration",
			"category": name,
		}, "Work item link category %s exists, will update/overwrite the description", name)

		cat.Description = &description
		linkCat := link.ConvertLinkCategoryFromModel(*cat)
		_, err = linkCatRepo.Save(ctx, linkCat)
		return errs.WithStack(err)
	}
	return nil
}