Skip to content

Commit d193edd

Browse files
committed
feat: add dbauthz test for new query
1 parent e94e7c9 commit d193edd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,39 @@ func (s *MethodTestSuite) TestOrganization() {
809809
o := dbgen.Organization(s.T(), db, database.Organization{})
810810
check.Args(o.ID).Asserts(o, policy.ActionRead).Returns(o)
811811
}))
812+
s.Run("GetOrganizationResourceCountByID", s.Subtest(func(db database.Store, check *expects) {
813+
u := dbgen.User(s.T(), db, database.User{})
814+
o := dbgen.Organization(s.T(), db, database.Organization{})
815+
816+
t := dbgen.Template(s.T(), db, database.Template{
817+
CreatedBy: u.ID,
818+
OrganizationID: o.ID,
819+
})
820+
dbgen.Workspace(s.T(), db, database.WorkspaceTable{
821+
OrganizationID: o.ID,
822+
OwnerID: u.ID,
823+
TemplateID: t.ID,
824+
})
825+
dbgen.Group(s.T(), db, database.Group{OrganizationID: o.ID})
826+
dbgen.OrganizationMember(s.T(), db, database.OrganizationMember{
827+
OrganizationID: o.ID,
828+
UserID: u.ID,
829+
})
830+
831+
check.Args(o.ID).Asserts(
832+
rbac.ResourceOrganizationMember.InOrg(o.ID), policy.ActionRead,
833+
rbac.ResourceWorkspace.InOrg(o.ID), policy.ActionRead,
834+
rbac.ResourceGroup.InOrg(o.ID), policy.ActionRead,
835+
rbac.ResourceTemplate.InOrg(o.ID), policy.ActionRead,
836+
rbac.ResourceProvisionerJobs.InOrg(o.ID), policy.ActionRead,
837+
).Returns(database.GetOrganizationResourceCountByIDRow{
838+
WorkspaceCount: 1,
839+
GroupCount: 1,
840+
TemplateCount: 1,
841+
MemberCount: 1,
842+
ProvisionerKeyCount: 0,
843+
})
844+
}))
812845
s.Run("GetDefaultOrganization", s.Subtest(func(db database.Store, check *expects) {
813846
o, _ := db.GetDefaultOrganization(context.Background())
814847
check.Args().Asserts(o, policy.ActionRead).Returns(o)

0 commit comments

Comments
 (0)