Skip to content

Commit ae2bf08

Browse files
committed
Merge branch 'jaaydenh/orgs-soft-delete' of https://github.com/coder/coder into jaaydenh/orgs-soft-delete
2 parents 9466ff7 + dc5fc46 commit ae2bf08

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

coderd/database/querier_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/coder/coder/v2/coderd/database"
2222
"github.com/coder/coder/v2/coderd/database/db2sdk"
2323
"github.com/coder/coder/v2/coderd/database/dbauthz"
24+
"github.com/coder/coder/v2/coderd/database/dbfake"
2425
"github.com/coder/coder/v2/coderd/database/dbgen"
2526
"github.com/coder/coder/v2/coderd/database/dbtestutil"
2627
"github.com/coder/coder/v2/coderd/database/dbtime"
@@ -2916,6 +2917,38 @@ func TestGetUserStatusCounts(t *testing.T) {
29162917
}
29172918
}
29182919

2920+
func TestOrganizationDeleteTrigger(t *testing.T) {
2921+
t.Parallel()
2922+
2923+
if !dbtestutil.WillUsePostgres() {
2924+
t.SkipNow()
2925+
}
2926+
2927+
t.Run("WorkspaceExists", func(t *testing.T) {
2928+
db, _ := dbtestutil.NewDB(t)
2929+
2930+
orgA := dbfake.Organization(t, db).Do()
2931+
2932+
user := dbgen.User(t, db, database.User{})
2933+
2934+
dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
2935+
OrganizationID: orgA.Org.ID,
2936+
OwnerID: user.ID,
2937+
}).Do()
2938+
2939+
ctx := testutil.Context(t, testutil.WaitShort)
2940+
err := db.UpdateOrganizationDeletedByID(ctx, database.UpdateOrganizationDeletedByIDParams{
2941+
UpdatedAt: dbtime.Now(),
2942+
ID: orgA.Org.ID,
2943+
})
2944+
require.Error(t, err)
2945+
// cannot delete organization: organization has 1 workspaces and 1 templates that must be deleted first
2946+
require.ErrorContains(t, err, "cannot delete organization")
2947+
require.ErrorContains(t, err, "has 1 workspaces")
2948+
require.ErrorContains(t, err, "1 templates")
2949+
})
2950+
}
2951+
29192952
func requireUsersMatch(t testing.TB, expected []database.User, found []database.GetUsersRow, msg string) {
29202953
t.Helper()
29212954
require.ElementsMatch(t, expected, database.ConvertUserRows(found), msg)

0 commit comments

Comments
 (0)