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

Function TestOrganizationDeleteTrigger

coderd/database/querier_test.go:6006–6166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6004}
6005
6006func TestOrganizationDeleteTrigger(t *testing.T) {
6007 t.Parallel()
6008
6009 t.Run("WorkspaceExists", func(t *testing.T) {
6010 t.Parallel()
6011 db, _ := dbtestutil.NewDB(t)
6012
6013 orgA := dbfake.Organization(t, db).Do()
6014
6015 user := dbgen.User(t, db, database.User{})
6016
6017 dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
6018 OrganizationID: orgA.Org.ID,
6019 OwnerID: user.ID,
6020 }).Do()
6021
6022 ctx := testutil.Context(t, testutil.WaitShort)
6023 err := db.UpdateOrganizationDeletedByID(ctx, database.UpdateOrganizationDeletedByIDParams{
6024 UpdatedAt: dbtime.Now(),
6025 ID: orgA.Org.ID,
6026 })
6027 require.Error(t, err)
6028 // cannot delete organization: organization has 1 workspaces and 1 templates that must be deleted first
6029 require.ErrorContains(t, err, "cannot delete organization")
6030 require.ErrorContains(t, err, "has 1 workspaces")
6031 require.ErrorContains(t, err, "1 templates")
6032 })
6033
6034 t.Run("TemplateExists", func(t *testing.T) {
6035 t.Parallel()
6036 db, _ := dbtestutil.NewDB(t)
6037
6038 orgA := dbfake.Organization(t, db).Do()
6039
6040 user := dbgen.User(t, db, database.User{})
6041
6042 dbgen.Template(t, db, database.Template{
6043 OrganizationID: orgA.Org.ID,
6044 CreatedBy: user.ID,
6045 })
6046
6047 ctx := testutil.Context(t, testutil.WaitShort)
6048 err := db.UpdateOrganizationDeletedByID(ctx, database.UpdateOrganizationDeletedByIDParams{
6049 UpdatedAt: dbtime.Now(),
6050 ID: orgA.Org.ID,
6051 })
6052 require.Error(t, err)
6053 // cannot delete organization: organization has 0 workspaces and 1 templates that must be deleted first
6054 require.ErrorContains(t, err, "cannot delete organization")
6055 require.ErrorContains(t, err, "1 templates")
6056 })
6057
6058 t.Run("ProvisionerKeyExists", func(t *testing.T) {
6059 t.Parallel()
6060 db, _ := dbtestutil.NewDB(t)
6061
6062 orgA := dbfake.Organization(t, db).Do()
6063

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
OrganizationFunction · 0.92
UserFunction · 0.92
WorkspaceBuildFunction · 0.92
ContextFunction · 0.92
NowFunction · 0.92
TemplateFunction · 0.92
ProvisionerKeyFunction · 0.92
GroupFunction · 0.92
OrganizationMemberFunction · 0.92
RunMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected