Files
MokoGIT/tests/integration/api_license_templates_test.go
jmiller bab29a83fa refactor: rename Go module path MokoConsulting/MokoGitea -> MokoConsulting/MokoGIT
Sweep all .go imports + go.mod, plus module-path refs in .golangci.yml,
Dockerfile, swagger templates, locale example, and repo/wiki URLs
(MokoGitea-Fork -> MokoGIT). Part of the MokoGIT rebrand.

Claude-Session: https://claude.ai/code/session_01Bqe7fAuHQeiLueYfeHFrHw
2026-07-14 15:31:19 -05:00

53 lines
1.5 KiB
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"net/url"
"testing"
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/options"
repo_module "code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/repository"
api "code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/structs"
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/tests"
"github.com/stretchr/testify/assert"
)
func TestAPIListLicenseTemplates(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequest(t, "GET", "/api/v1/licenses")
resp := MakeRequest(t, req, http.StatusOK)
// This tests if the API returns a list of strings
DecodeJSON(t, resp, []api.LicensesTemplateListEntry{})
}
func TestAPIGetLicenseTemplateInfo(t *testing.T) {
defer tests.PrepareTestEnv(t)()
// If Gitea has for some reason no License templates, we need to skip this test
if len(repo_module.Licenses) == 0 {
return
}
// Use the first template for the test
licenseName := repo_module.Licenses[0]
urlStr := "/api/v1/licenses/" + url.PathEscape(licenseName)
req := NewRequest(t, "GET", urlStr)
resp := MakeRequest(t, req, http.StatusOK)
licenseInfo := DecodeJSON(t, resp, &api.LicenseTemplateInfo{})
// We get the text of the template here
text, _ := options.License(licenseName)
assert.Equal(t, licenseInfo.Key, licenseName)
assert.Equal(t, licenseInfo.Name, licenseName)
assert.Equal(t, licenseInfo.Body, string(text))
}