diff options
author | Jack Vine <jackv24@users.noreply.github.com> | 2022-09-24 20:54:33 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-24 19:24:33 +0800 |
commit | 83680c97a7fd23d2a2953302771ed2b234c0689e (patch) | |
tree | ff0affb5ab524b24955a1793074150cac2572f2f /tests/integration | |
parent | da0a9ec81132dabbec0d217d5f6a49550ce6793a (diff) | |
download | gitea-83680c97a7fd23d2a2953302771ed2b234c0689e.tar.gz gitea-83680c97a7fd23d2a2953302771ed2b234c0689e.zip |
NPM Package Registry search API endpoint (#20280)
Close #20098, in the NPM registry API, implemented to match what's described by https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search
Currently have only implemented the bare minimum to work with the [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui.html).
Co-authored-by: Jack Vine <jackv@jack-lemur-suse.cat-prometheus.ts.net>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/api_packages_npm_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/integration/api_packages_npm_test.go b/tests/integration/api_packages_npm_test.go index fe6cea1cb6..14ed681be3 100644 --- a/tests/integration/api_packages_npm_test.go +++ b/tests/integration/api_packages_npm_test.go @@ -224,6 +224,37 @@ func TestPackageNpm(t *testing.T) { test(t, http.StatusOK, packageTag2) }) + t.Run("Search", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + url := fmt.Sprintf("/api/packages/%s/npm/-/v1/search", user.Name) + + cases := []struct { + Query string + Skip int + Take int + ExpectedTotal int64 + ExpectedResults int + }{ + {"", 0, 0, 1, 1}, + {"", 0, 10, 1, 1}, + {"gitea", 0, 10, 0, 0}, + {"test", 0, 10, 1, 1}, + {"test", 1, 10, 1, 0}, + } + + for i, c := range cases { + req := NewRequest(t, "GET", fmt.Sprintf("%s?text=%s&from=%d&size=%d", url, c.Query, c.Skip, c.Take)) + resp := MakeRequest(t, req, http.StatusOK) + + var result npm.PackageSearch + DecodeJSON(t, resp, &result) + + assert.Equal(t, c.ExpectedTotal, result.Total, "case %d: unexpected total hits", i) + assert.Len(t, result.Objects, c.ExpectedResults, "case %d: unexpected result count", i) + } + }) + t.Run("Delete", func(t *testing.T) { defer tests.PrintCurrentTest(t)() |