本站源代码
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.

91 lines
2.4KB

  1. // Copyright 2019 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. "fmt"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestUserListIsPublicMember(t *testing.T) {
  11. assert.NoError(t, PrepareTestDatabase())
  12. tt := []struct {
  13. orgid int64
  14. expected map[int64]bool
  15. }{
  16. {3, map[int64]bool{2: true, 4: false}},
  17. {6, map[int64]bool{5: true}},
  18. {7, map[int64]bool{5: false}},
  19. {25, map[int64]bool{24: true}},
  20. {22, map[int64]bool{}},
  21. }
  22. for _, v := range tt {
  23. t.Run(fmt.Sprintf("IsPublicMemberOfOrdIg%d", v.orgid), func(t *testing.T) {
  24. testUserListIsPublicMember(t, v.orgid, v.expected)
  25. })
  26. }
  27. }
  28. func testUserListIsPublicMember(t *testing.T, orgID int64, expected map[int64]bool) {
  29. org, err := GetUserByID(orgID)
  30. assert.NoError(t, err)
  31. assert.NoError(t, org.GetMembers())
  32. assert.Equal(t, expected, org.MembersIsPublic)
  33. }
  34. func TestUserListIsUserOrgOwner(t *testing.T) {
  35. assert.NoError(t, PrepareTestDatabase())
  36. tt := []struct {
  37. orgid int64
  38. expected map[int64]bool
  39. }{
  40. {3, map[int64]bool{2: true, 4: false}},
  41. {6, map[int64]bool{5: true}},
  42. {7, map[int64]bool{5: true}},
  43. {25, map[int64]bool{24: false}}, // ErrTeamNotExist
  44. {22, map[int64]bool{}}, // No member
  45. }
  46. for _, v := range tt {
  47. t.Run(fmt.Sprintf("IsUserOrgOwnerOfOrdIg%d", v.orgid), func(t *testing.T) {
  48. testUserListIsUserOrgOwner(t, v.orgid, v.expected)
  49. })
  50. }
  51. }
  52. func testUserListIsUserOrgOwner(t *testing.T, orgID int64, expected map[int64]bool) {
  53. org, err := GetUserByID(orgID)
  54. assert.NoError(t, err)
  55. assert.NoError(t, org.GetMembers())
  56. assert.Equal(t, expected, org.Members.IsUserOrgOwner(orgID))
  57. }
  58. func TestUserListIsTwoFaEnrolled(t *testing.T) {
  59. assert.NoError(t, PrepareTestDatabase())
  60. tt := []struct {
  61. orgid int64
  62. expected map[int64]bool
  63. }{
  64. {3, map[int64]bool{2: false, 4: false}},
  65. {6, map[int64]bool{5: false}},
  66. {7, map[int64]bool{5: false}},
  67. {25, map[int64]bool{24: true}},
  68. {22, map[int64]bool{}},
  69. }
  70. for _, v := range tt {
  71. t.Run(fmt.Sprintf("IsTwoFaEnrolledOfOrdIg%d", v.orgid), func(t *testing.T) {
  72. testUserListIsTwoFaEnrolled(t, v.orgid, v.expected)
  73. })
  74. }
  75. }
  76. func testUserListIsTwoFaEnrolled(t *testing.T, orgID int64, expected map[int64]bool) {
  77. org, err := GetUserByID(orgID)
  78. assert.NoError(t, err)
  79. assert.NoError(t, org.GetMembers())
  80. assert.Equal(t, expected, org.Members.GetTwoFaStatus())
  81. }
上海开阖软件有限公司 沪ICP备12045867号-1