github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/pkg/cmd/label/http_test.go (about)

     1  package label
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/ungtb10d/cli/v2/internal/ghrepo"
     8  	"github.com/ungtb10d/cli/v2/pkg/httpmock"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestLabelList_pagination(t *testing.T) {
    13  	reg := &httpmock.Registry{}
    14  	client := &http.Client{Transport: reg}
    15  
    16  	reg.Register(
    17  		httpmock.GraphQL(`query LabelList\b`),
    18  		httpmock.StringResponse(`
    19  		{
    20  			"data": {
    21  				"repository": {
    22  					"labels": {
    23  						"totalCount": 2,
    24  						"nodes": [
    25  							{
    26  								"name": "bug",
    27  								"color": "d73a4a",
    28  								"description": "This is a bug label"
    29  							}
    30  						],
    31  						"pageInfo": {
    32  							"hasNextPage": true,
    33  							"endCursor": "Y3Vyc29yOnYyOpK5MjAxOS0xMC0xMVQwMTozODowMyswODowMM5f3HZq"
    34  						}
    35  					}
    36  				}
    37  			}
    38  		}`),
    39  	)
    40  
    41  	reg.Register(
    42  		httpmock.GraphQL(`query LabelList\b`),
    43  		httpmock.StringResponse(`
    44  		{
    45  			"data": {
    46  				"repository": {
    47  					"labels": {
    48  						"totalCount": 2,
    49  						"nodes": [
    50  							{
    51  								"name": "docs",
    52  								"color": "ffa8da",
    53  								"description": "This is a docs label"
    54  							}
    55  						],
    56  						"pageInfo": {
    57  							"hasNextPage": false,
    58  							"endCursor": "Y3Vyc29yOnYyOpK5MjAyMi0wMS0zMVQxODo1NTo1MiswODowMM7hiAL3"
    59  						}
    60  					}
    61  				}
    62  			}
    63  		}`),
    64  	)
    65  
    66  	repo := ghrepo.New("OWNER", "REPO")
    67  	labels, totalCount, err := listLabels(client, repo, listQueryOptions{Limit: 10})
    68  	assert.NoError(t, err)
    69  
    70  	assert.Equal(t, 2, totalCount)
    71  	assert.Equal(t, 2, len(labels))
    72  
    73  	assert.Equal(t, "bug", labels[0].Name)
    74  	assert.Equal(t, "d73a4a", labels[0].Color)
    75  	assert.Equal(t, "This is a bug label", labels[0].Description)
    76  
    77  	assert.Equal(t, "docs", labels[1].Name)
    78  	assert.Equal(t, "ffa8da", labels[1].Color)
    79  	assert.Equal(t, "This is a docs label", labels[1].Description)
    80  }