|
1 | 1 | // |
2 | | -// Copyright 2024 The Chainloop Authors. |
| 2 | +// Copyright 2024-2025 The Chainloop Authors. |
3 | 3 | // |
4 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | // you may not use this file except in compliance with the License. |
@@ -80,28 +80,30 @@ User mapping: |
80 | 80 | func (s *userIntegrationTestSuite) TestDeleteUser() { |
81 | 81 | ctx := context.Background() |
82 | 82 |
|
| 83 | + // User deletion should be blocked because userOne is sole owner of userOneOrg |
83 | 84 | err := s.User.DeleteUser(ctx, s.userOne.ID) |
84 | | - s.NoError(err) |
| 85 | + s.Error(err) |
| 86 | + s.True(biz.IsErrValidation(err)) |
| 87 | + s.Contains(err.Error(), "sole owner") |
85 | 88 |
|
86 | | - // Organization where the user is the only member got deleted |
| 89 | + // Both organizations should still exist since deletion was blocked |
87 | 90 | gotOrgOne, err := s.Organization.FindByID(ctx, s.userOneOrg.ID) |
88 | | - s.Error(err) |
89 | | - s.True(biz.IsNotFound(err)) |
90 | | - s.Nil(gotOrgOne) |
| 91 | + s.NoError(err) |
| 92 | + s.NotNil(gotOrgOne) |
91 | 93 |
|
92 | | - // Organization that it's shared with another user is still present |
93 | 94 | gotSharedOrg, err := s.Organization.FindByID(ctx, s.sharedOrg.ID) |
94 | 95 | s.NoError(err) |
95 | 96 | s.NotNil(gotSharedOrg) |
96 | 97 |
|
97 | | - // user and associated memberships have been deleted |
| 98 | + // User should still exist since deletion was blocked |
98 | 99 | gotUser, err := s.User.FindByID(ctx, s.userOne.ID) |
99 | 100 | s.NoError(err) |
100 | | - s.Nil(gotUser) |
| 101 | + s.NotNil(gotUser) |
101 | 102 |
|
| 103 | + // Memberships should still exist since deletion was blocked |
102 | 104 | gotMembership, err := s.Membership.ByUser(ctx, s.userOne.ID) |
103 | 105 | s.NoError(err) |
104 | | - s.Empty(gotMembership) |
| 106 | + s.NotEmpty(gotMembership) |
105 | 107 | } |
106 | 108 |
|
107 | 109 | func (s *userIntegrationTestSuite) TestCurrentMembership() { |
@@ -224,15 +226,15 @@ func (s *userIntegrationTestSuite) SetupTest() { |
224 | 226 | // Create User 1 |
225 | 227 | s.userOne, err = s.User.UpsertByEmail(ctx, "user-1@test.com", nil) |
226 | 228 | assert.NoError(err) |
227 | | - // Attach both orgs |
228 | | - _, err = s.Membership.Create(ctx, s.userOneOrg.ID, s.userOne.ID) |
| 229 | + // Attach both orgs - make user owner of userOneOrg and owner of sharedOrg |
| 230 | + _, err = s.Membership.Create(ctx, s.userOneOrg.ID, s.userOne.ID, biz.WithMembershipRole(authz.RoleOwner)) |
229 | 231 | assert.NoError(err) |
230 | | - _, err = s.Membership.Create(ctx, s.sharedOrg.ID, s.userOne.ID, biz.WithCurrentMembership()) |
| 232 | + _, err = s.Membership.Create(ctx, s.sharedOrg.ID, s.userOne.ID, biz.WithMembershipRole(authz.RoleOwner), biz.WithCurrentMembership()) |
231 | 233 | assert.NoError(err) |
232 | 234 |
|
233 | | - // Create User 2 and attach shared org |
| 235 | + // Create User 2 and attach shared org as owner too |
234 | 236 | s.userTwo, err = s.User.UpsertByEmail(ctx, "user-2@test.com", nil) |
235 | 237 | assert.NoError(err) |
236 | | - _, err = s.Membership.Create(ctx, s.sharedOrg.ID, s.userTwo.ID, biz.WithCurrentMembership()) |
| 238 | + _, err = s.Membership.Create(ctx, s.sharedOrg.ID, s.userTwo.ID, biz.WithMembershipRole(authz.RoleOwner), biz.WithCurrentMembership()) |
237 | 239 | assert.NoError(err) |
238 | 240 | } |
0 commit comments