MCPcopy Index your code
hub / github.com/coder/coder / TestOrganizationSync

Function TestOrganizationSync

enterprise/coderd/enidpsync/organizations_test.go:53–341  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestOrganizationSync(t *testing.T) {
54 t.Parallel()
55
56 requireUserOrgs := func(t *testing.T, db database.Store, user database.User, expected []uuid.UUID) {
57 t.Helper()
58
59 members, err := db.OrganizationMembers(dbauthz.AsSystemRestricted(context.Background()), database.OrganizationMembersParams{
60 UserID: user.ID,
61 })
62 require.NoError(t, err)
63
64 foundIDs := slice.List(members, func(m database.OrganizationMembersRow) uuid.UUID {
65 return m.OrganizationMember.OrganizationID
66 })
67 require.ElementsMatch(t, expected, foundIDs, "match user organizations")
68 }
69
70 entitled := entitlements.New()
71 entitled.Modify(func(entitlements *codersdk.Entitlements) {
72 entitlements.Features[codersdk.FeatureMultipleOrganizations] = codersdk.Feature{
73 Entitlement: codersdk.EntitlementEntitled,
74 Enabled: true,
75 Limit: nil,
76 Actual: nil,
77 }
78 })
79
80 testCases := []struct {
81 Name string
82 Case func(t *testing.T, db database.Store) OrganizationSyncTestCase
83 }{
84 {
85 Name: "SingleOrgDeployment",
86 Case: func(t *testing.T, db database.Store) OrganizationSyncTestCase {
87 def, _ := db.GetDefaultOrganization(context.Background())
88 other := dbfake.Organization(t, db).Do()
89 deleted := dbfake.Organization(t, db).Deleted(true).Do()
90 return OrganizationSyncTestCase{
91 Entitlements: entitled,
92 Settings: idpsync.DeploymentSyncSettings{
93 OrganizationField: "",
94 OrganizationMapping: nil,
95 OrganizationAssignDefault: true,
96 },
97 Exps: []Expectations{
98 {
99 Name: "NoOrganizations",
100 Claims: jwt.MapClaims{},
101 ExpectedParams: idpsync.OrganizationParams{
102 SyncEntitled: true,
103 },
104 ExpectedEnabled: false,
105 Sync: ExpectedUser{
106 Organizations: []uuid.UUID{},
107 },
108 },
109 {
110 Name: "AlreadyInOrgs",

Callers

nothing calls this directly

Calls 15

AsSystemRestrictedFunction · 0.92
ListFunction · 0.92
NewFunction · 0.92
OrganizationFunction · 0.92
OrganizationMemberFunction · 0.92
OrganizationFunction · 0.92
ContextFunction · 0.92
NewDBFunction · 0.92
NewFunction · 0.92
NewAuthorizerFunction · 0.92
NewSyncFunction · 0.92

Tested by

no test coverage detected