code.gitea.io/gitea@v1.21.7/services/convert/issue_test.go (about)

     1  // Copyright 2020 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package convert
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  	"time"
    10  
    11  	issues_model "code.gitea.io/gitea/models/issues"
    12  	repo_model "code.gitea.io/gitea/models/repo"
    13  	"code.gitea.io/gitea/models/unittest"
    14  	"code.gitea.io/gitea/modules/setting"
    15  	api "code.gitea.io/gitea/modules/structs"
    16  	"code.gitea.io/gitea/modules/timeutil"
    17  
    18  	"github.com/stretchr/testify/assert"
    19  )
    20  
    21  func TestLabel_ToLabel(t *testing.T) {
    22  	assert.NoError(t, unittest.PrepareTestDatabase())
    23  	label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
    24  	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: label.RepoID})
    25  	assert.Equal(t, &api.Label{
    26  		ID:    label.ID,
    27  		Name:  label.Name,
    28  		Color: "abcdef",
    29  		URL:   fmt.Sprintf("%sapi/v1/repos/user2/repo1/labels/%d", setting.AppURL, label.ID),
    30  	}, ToLabel(label, repo, nil))
    31  }
    32  
    33  func TestMilestone_APIFormat(t *testing.T) {
    34  	milestone := &issues_model.Milestone{
    35  		ID:              3,
    36  		RepoID:          4,
    37  		Name:            "milestoneName",
    38  		Content:         "milestoneContent",
    39  		IsClosed:        false,
    40  		NumOpenIssues:   5,
    41  		NumClosedIssues: 6,
    42  		CreatedUnix:     timeutil.TimeStamp(time.Date(1999, time.January, 1, 0, 0, 0, 0, time.UTC).Unix()),
    43  		UpdatedUnix:     timeutil.TimeStamp(time.Date(1999, time.March, 1, 0, 0, 0, 0, time.UTC).Unix()),
    44  		DeadlineUnix:    timeutil.TimeStamp(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC).Unix()),
    45  	}
    46  	assert.Equal(t, api.Milestone{
    47  		ID:           milestone.ID,
    48  		State:        api.StateOpen,
    49  		Title:        milestone.Name,
    50  		Description:  milestone.Content,
    51  		OpenIssues:   milestone.NumOpenIssues,
    52  		ClosedIssues: milestone.NumClosedIssues,
    53  		Created:      milestone.CreatedUnix.AsTime(),
    54  		Updated:      milestone.UpdatedUnix.AsTimePtr(),
    55  		Deadline:     milestone.DeadlineUnix.AsTimePtr(),
    56  	}, *ToAPIMilestone(milestone))
    57  }