Skip to content

Commit 69054e0

Browse files
committed
fix tests
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent 8dd2cc3 commit 69054e0

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed

app/controlplane/pkg/biz/orginvitation_integration_test.go

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,60 +75,44 @@ func (s *OrgInvitationIntegrationTestSuite) TestList() {
7575

7676
func (s *OrgInvitationIntegrationTestSuite) TestCreate() {
7777
ctx := context.Background()
78-
s.T().Run("invalid org ID", func(t *testing.T) {
78+
s.T().Run("invalid org ID", func(_ *testing.T) {
7979
invite, err := s.OrgInvitation.Create(ctx, "deadbeef", receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
8080
s.Error(err)
8181
s.True(biz.IsErrInvalidUUID(err))
8282
s.Nil(invite)
8383
})
8484

85-
s.T().Run("missing receiver email", func(t *testing.T) {
85+
s.T().Run("missing receiver email", func(_ *testing.T) {
8686
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, "", biz.WithSender(uuid.MustParse(s.user.ID)))
8787
s.Error(err)
8888
s.True(biz.IsErrValidation(err))
8989
s.Nil(invite)
9090
})
9191

92-
s.T().Run("receiver email same than sender", func(t *testing.T) {
92+
s.T().Run("receiver email same than sender", func(_ *testing.T) {
9393
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, s.user.Email, biz.WithSender(uuid.MustParse(s.user.ID)))
9494
s.Error(err)
9595
s.ErrorContains(err, "sender and receiver emails cannot be the same")
9696
s.True(biz.IsErrValidation(err))
9797
s.Nil(invite)
9898
})
9999

100-
s.T().Run("receiver is already a member", func(t *testing.T) {
100+
s.T().Run("receiver is already a member", func(_ *testing.T) {
101101
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, s.user2.Email, biz.WithSender(uuid.MustParse(s.user.ID)))
102102
s.Error(err)
103103
s.ErrorContains(err, "user already exists in the org")
104104
s.True(biz.IsErrValidation(err))
105105
s.Nil(invite)
106106
})
107107

108-
s.T().Run("org not found", func(t *testing.T) {
108+
s.T().Run("org not found", func(_ *testing.T) {
109109
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, receiverEmail, biz.WithSender(uuid.Nil))
110110
s.Error(err)
111111
s.True(biz.IsNotFound(err))
112112
s.Nil(invite)
113113
})
114114

115-
s.T().Run("sender is not member of that org", func(t *testing.T) {
116-
invite, err := s.OrgInvitation.Create(ctx, s.org3.ID, receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
117-
s.Error(err)
118-
s.ErrorContains(err, "user does not have permission to invite to this org")
119-
s.True(biz.IsNotFound(err))
120-
s.Nil(invite)
121-
})
122-
123-
s.T().Run("sender is not member of that org but receiver is", func(t *testing.T) {
124-
invite, err := s.OrgInvitation.Create(ctx, s.org3.ID, s.user2.Email, biz.WithSender(uuid.MustParse(s.user.ID)))
125-
s.Error(err)
126-
s.ErrorContains(err, "user does not have permission to invite to this org")
127-
s.True(biz.IsNotFound(err))
128-
s.Nil(invite)
129-
})
130-
131-
s.T().Run("can create invites for org1 and 2", func(t *testing.T) {
115+
s.T().Run("can create invites for org1 and 2", func(_ *testing.T) {
132116
for _, org := range []*biz.Organization{s.org1, s.org2} {
133117
invite, err := s.OrgInvitation.Create(ctx, org.ID, receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
134118
s.NoError(err)
@@ -140,28 +124,28 @@ func (s *OrgInvitationIntegrationTestSuite) TestCreate() {
140124
}
141125
})
142126

143-
s.T().Run("but can't create if there is one pending", func(t *testing.T) {
127+
s.T().Run("but can't create if there is one pending", func(_ *testing.T) {
144128
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
145129
s.Error(err)
146130
s.ErrorContains(err, "already exists")
147131
s.True(biz.IsErrValidation(err))
148132
s.Nil(invite)
149133
})
150134

151-
s.T().Run("but it can if it's another email", func(t *testing.T) {
135+
s.T().Run("but it can if it's another email", func(_ *testing.T) {
152136
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, "anotheremail@cyberdyne.io", biz.WithSender(uuid.MustParse(s.user.ID)))
153137
s.Equal("anotheremail@cyberdyne.io", invite.ReceiverEmail)
154138
s.Equal(s.org1, invite.Org)
155139
s.NoError(err)
156140
})
157141

158-
s.T().Run("the default role is viewer", func(t *testing.T) {
142+
s.T().Run("the default role is viewer", func(_ *testing.T) {
159143
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, "viewer@cyberdyne.io", biz.WithSender(uuid.MustParse(s.user.ID)))
160144
s.NoError(err)
161145
s.Equal(authz.RoleViewer, invite.Role)
162146
})
163147

164-
s.T().Run("but can have other roles", func(t *testing.T) {
148+
s.T().Run("but can have other roles", func(_ *testing.T) {
165149
for _, r := range []authz.Role{authz.RoleOwner, authz.RoleAdmin, authz.RoleViewer} {
166150
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, fmt.Sprintf("%s@cyberdyne.io", r), biz.WithInvitationRole(r), biz.WithSender(uuid.MustParse(s.user.ID)))
167151
s.NoError(err)
@@ -181,12 +165,12 @@ func (s *OrgInvitationIntegrationTestSuite) TestAcceptPendingInvitations() {
181165
receiver, err := s.User.UpsertByEmail(ctx, receiverEmail, nil)
182166
require.NoError(s.T(), err)
183167

184-
s.T().Run("user doesn't exist", func(t *testing.T) {
168+
s.T().Run("user doesn't exist", func(_ *testing.T) {
185169
err := s.OrgInvitation.AcceptPendingInvitations(ctx, "non-existant@cyberdyne.io")
186170
s.ErrorContains(err, "not found")
187171
})
188172

189-
s.T().Run("no invites for user", func(t *testing.T) {
173+
s.T().Run("no invites for user", func(_ *testing.T) {
190174
err = s.OrgInvitation.AcceptPendingInvitations(ctx, receiverEmail)
191175
s.NoError(err)
192176

@@ -195,7 +179,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestAcceptPendingInvitations() {
195179
s.Len(memberships, 0)
196180
})
197181

198-
s.T().Run("user is invited to org 1 as viewer", func(t *testing.T) {
182+
s.T().Run("user is invited to org 1 as viewer", func(_ *testing.T) {
199183
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
200184
require.NoError(s.T(), err)
201185
err = s.OrgInvitation.AcceptPendingInvitations(ctx, receiverEmail)
@@ -214,7 +198,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestAcceptPendingInvitations() {
214198
s.Equal(biz.OrgInvitationStatusAccepted, invite.Status)
215199
})
216200

217-
s.T().Run("or take any other role", func(t *testing.T) {
201+
s.T().Run("or take any other role", func(_ *testing.T) {
218202
for i, r := range []authz.Role{authz.RoleOwner, authz.RoleAdmin, authz.RoleViewer} {
219203
// Create user and invite it with different roles
220204
receiverEmail := fmt.Sprintf("user%d@cyberdyne.io", i)
@@ -237,27 +221,27 @@ func (s *OrgInvitationIntegrationTestSuite) TestAcceptPendingInvitations() {
237221

238222
func (s *OrgInvitationIntegrationTestSuite) TestRevoke() {
239223
ctx := context.Background()
240-
s.T().Run("invalid ID", func(t *testing.T) {
224+
s.T().Run("invalid ID", func(_ *testing.T) {
241225
err := s.OrgInvitation.Revoke(ctx, s.org1.ID, "deadbeef")
242226
s.Error(err)
243227
s.True(biz.IsErrInvalidUUID(err))
244228
})
245229

246-
s.T().Run("invitation not found", func(t *testing.T) {
230+
s.T().Run("invitation not found", func(_ *testing.T) {
247231
err := s.OrgInvitation.Revoke(ctx, s.org1.ID, uuid.NewString())
248232
s.Error(err)
249233
s.True(biz.IsNotFound(err))
250234
})
251235

252-
s.T().Run("invitation in another org", func(t *testing.T) {
236+
s.T().Run("invitation in another org", func(_ *testing.T) {
253237
_, err := s.OrgInvitation.Create(ctx, s.org2.ID, receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
254238
s.NoError(err)
255239
err = s.OrgInvitation.Revoke(ctx, s.org1.ID, uuid.NewString())
256240
s.Error(err)
257241
s.True(biz.IsNotFound(err))
258242
})
259243

260-
s.T().Run("invitation not in pending state", func(t *testing.T) {
244+
s.T().Run("invitation not in pending state", func(_ *testing.T) {
261245
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
262246
require.NoError(s.T(), err)
263247
err = s.OrgInvitation.AcceptInvitation(ctx, invite.ID.String())
@@ -270,7 +254,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestRevoke() {
270254
s.True(biz.IsErrValidation(err))
271255
})
272256

273-
s.T().Run("happy path", func(t *testing.T) {
257+
s.T().Run("happy path", func(_ *testing.T) {
274258
invite, err := s.OrgInvitation.Create(ctx, s.org1.ID, receiverEmail, biz.WithSender(uuid.MustParse(s.user.ID)))
275259
require.NoError(s.T(), err)
276260
err = s.OrgInvitation.Revoke(ctx, s.org1.ID, invite.ID.String())

0 commit comments

Comments
 (0)