code.gitea.io/gitea@v1.21.7/tests/integration/api_settings_test.go (about)

     1  // Copyright 2020 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"net/http"
     8  	"testing"
     9  
    10  	"code.gitea.io/gitea/modules/setting"
    11  	api "code.gitea.io/gitea/modules/structs"
    12  	"code.gitea.io/gitea/tests"
    13  
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestAPIExposedSettings(t *testing.T) {
    18  	defer tests.PrepareTestEnv(t)()
    19  
    20  	ui := new(api.GeneralUISettings)
    21  	req := NewRequest(t, "GET", "/api/v1/settings/ui")
    22  	resp := MakeRequest(t, req, http.StatusOK)
    23  
    24  	DecodeJSON(t, resp, &ui)
    25  	assert.Len(t, ui.AllowedReactions, len(setting.UI.Reactions))
    26  	assert.ElementsMatch(t, setting.UI.Reactions, ui.AllowedReactions)
    27  
    28  	apiSettings := new(api.GeneralAPISettings)
    29  	req = NewRequest(t, "GET", "/api/v1/settings/api")
    30  	resp = MakeRequest(t, req, http.StatusOK)
    31  
    32  	DecodeJSON(t, resp, &apiSettings)
    33  	assert.EqualValues(t, &api.GeneralAPISettings{
    34  		MaxResponseItems:       setting.API.MaxResponseItems,
    35  		DefaultPagingNum:       setting.API.DefaultPagingNum,
    36  		DefaultGitTreesPerPage: setting.API.DefaultGitTreesPerPage,
    37  		DefaultMaxBlobSize:     setting.API.DefaultMaxBlobSize,
    38  	}, apiSettings)
    39  
    40  	repo := new(api.GeneralRepoSettings)
    41  	req = NewRequest(t, "GET", "/api/v1/settings/repository")
    42  	resp = MakeRequest(t, req, http.StatusOK)
    43  
    44  	DecodeJSON(t, resp, &repo)
    45  	assert.EqualValues(t, &api.GeneralRepoSettings{
    46  		MirrorsDisabled:      !setting.Mirror.Enabled,
    47  		HTTPGitDisabled:      setting.Repository.DisableHTTPGit,
    48  		MigrationsDisabled:   setting.Repository.DisableMigrations,
    49  		TimeTrackingDisabled: false,
    50  		LFSDisabled:          !setting.LFS.StartServer,
    51  	}, repo)
    52  
    53  	attachment := new(api.GeneralAttachmentSettings)
    54  	req = NewRequest(t, "GET", "/api/v1/settings/attachment")
    55  	resp = MakeRequest(t, req, http.StatusOK)
    56  
    57  	DecodeJSON(t, resp, &attachment)
    58  	assert.EqualValues(t, &api.GeneralAttachmentSettings{
    59  		Enabled:      setting.Attachment.Enabled,
    60  		AllowedTypes: setting.Attachment.AllowedTypes,
    61  		MaxFiles:     setting.Attachment.MaxFiles,
    62  		MaxSize:      setting.Attachment.MaxSize,
    63  	}, attachment)
    64  }