You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.8 KiB

API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestStarRepo(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. const userID = 2
  12. const repoID = 1
  13. AssertNotExistsBean(t, &Star{UID: userID, RepoID: repoID})
  14. assert.NoError(t, StarRepo(userID, repoID, true))
  15. AssertExistsAndLoadBean(t, &Star{UID: userID, RepoID: repoID})
  16. assert.NoError(t, StarRepo(userID, repoID, true))
  17. AssertExistsAndLoadBean(t, &Star{UID: userID, RepoID: repoID})
  18. assert.NoError(t, StarRepo(userID, repoID, false))
  19. AssertNotExistsBean(t, &Star{UID: userID, RepoID: repoID})
  20. }
  21. func TestIsStaring(t *testing.T) {
  22. assert.NoError(t, PrepareTestDatabase())
  23. assert.True(t, IsStaring(2, 4))
  24. assert.False(t, IsStaring(3, 4))
  25. }
  26. func TestRepository_GetStargazers(t *testing.T) {
  27. // repo with stargazers
  28. assert.NoError(t, PrepareTestDatabase())
  29. repo := AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository)
  30. gazers, err := repo.GetStargazers(ListOptions{Page: 0})
  31. assert.NoError(t, err)
  32. if assert.Len(t, gazers, 1) {
  33. assert.Equal(t, int64(2), gazers[0].ID)
  34. }
  35. }
  36. func TestRepository_GetStargazers2(t *testing.T) {
  37. // repo with stargazers
  38. assert.NoError(t, PrepareTestDatabase())
  39. repo := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
  40. gazers, err := repo.GetStargazers(ListOptions{Page: 0})
  41. assert.NoError(t, err)
  42. assert.Len(t, gazers, 0)
  43. }
  44. func TestUser_GetStarredRepos(t *testing.T) {
  45. // user who has starred repos
  46. assert.NoError(t, PrepareTestDatabase())
  47. user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  48. starred, err := user.GetStarredRepos(false, 1, 10, "")
  49. assert.NoError(t, err)
  50. if assert.Len(t, starred, 1) {
  51. assert.Equal(t, int64(4), starred[0].ID)
  52. }
  53. starred, err = user.GetStarredRepos(true, 1, 10, "")
  54. assert.NoError(t, err)
  55. if assert.Len(t, starred, 2) {
  56. assert.Equal(t, int64(2), starred[0].ID)
  57. assert.Equal(t, int64(4), starred[1].ID)
  58. }
  59. }
  60. func TestUser_GetStarredRepos2(t *testing.T) {
  61. // user who has no starred repos
  62. assert.NoError(t, PrepareTestDatabase())
  63. user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
  64. starred, err := user.GetStarredRepos(false, 1, 10, "")
  65. assert.NoError(t, err)
  66. assert.Len(t, starred, 0)
  67. starred, err = user.GetStarredRepos(true, 1, 10, "")
  68. assert.NoError(t, err)
  69. assert.Len(t, starred, 0)
  70. }
  71. func TestUserGetStarredRepoCount(t *testing.T) {
  72. assert.NoError(t, PrepareTestDatabase())
  73. user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  74. counts, err := user.GetStarredRepoCount(false)
  75. assert.NoError(t, err)
  76. assert.Equal(t, int64(1), counts)
  77. counts, err = user.GetStarredRepoCount(true)
  78. assert.NoError(t, err)
  79. assert.Equal(t, int64(2), counts)
  80. }