@@ -34,12 +34,12 @@ const receiverEmail = "sarah@cyberdyne.io"
3434
3535func (s * OrgInvitationIntegrationTestSuite ) TestList () {
3636 ctx := context .Background ()
37- inviteOrg1A , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .ID , receiverEmail )
37+ inviteOrg1A , err := s .OrgInvitation .Create (ctx , s .org1 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
3838 s .NoError (err )
3939 // same org but another user
40- inviteOrg1B , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s . user2 . ID , "another-email@cyberdyne.io" )
40+ inviteOrg1B , err := s .OrgInvitation .Create (ctx , s .org1 .ID , "another-email@cyberdyne.io" , biz . WithSender ( uuid . MustParse ( s . user2 . ID )) )
4141 s .NoError (err )
42- inviteOrg2A , err := s .OrgInvitation .Create (ctx , s .org2 .ID , s .user .ID , receiverEmail )
42+ inviteOrg2A , err := s .OrgInvitation .Create (ctx , s .org2 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
4343 s .NoError (err )
4444
4545 testCases := []struct {
@@ -76,59 +76,52 @@ func (s *OrgInvitationIntegrationTestSuite) TestList() {
7676func (s * OrgInvitationIntegrationTestSuite ) TestCreate () {
7777 ctx := context .Background ()
7878 s .T ().Run ("invalid org ID" , func (t * testing.T ) {
79- invite , err := s .OrgInvitation .Create (ctx , "deadbeef" , s .user .ID , receiverEmail )
80- s .Error (err )
81- s .True (biz .IsErrInvalidUUID (err ))
82- s .Nil (invite )
83- })
84-
85- s .T ().Run ("invalid user ID" , func (t * testing.T ) {
86- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , "deadbeef" , receiverEmail )
79+ invite , err := s .OrgInvitation .Create (ctx , "deadbeef" , receiverEmail , biz .WithSender (uuid .MustParse (s .user .ID )))
8780 s .Error (err )
8881 s .True (biz .IsErrInvalidUUID (err ))
8982 s .Nil (invite )
9083 })
9184
9285 s .T ().Run ("missing receiver email" , func (t * testing.T ) {
93- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .ID , "" )
86+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , "" , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
9487 s .Error (err )
9588 s .True (biz .IsErrValidation (err ))
9689 s .Nil (invite )
9790 })
9891
9992 s .T ().Run ("receiver email same than sender" , func (t * testing.T ) {
100- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .ID , s .user .Email )
93+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .Email , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
10194 s .Error (err )
10295 s .ErrorContains (err , "sender and receiver emails cannot be the same" )
10396 s .True (biz .IsErrValidation (err ))
10497 s .Nil (invite )
10598 })
10699
107100 s .T ().Run ("receiver is already a member" , func (t * testing.T ) {
108- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user . ID , s . user2 . Email )
101+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user2 . Email , biz . WithSender ( uuid . MustParse ( s . user . ID )) )
109102 s .Error (err )
110103 s .ErrorContains (err , "user already exists in the org" )
111104 s .True (biz .IsErrValidation (err ))
112105 s .Nil (invite )
113106 })
114107
115108 s .T ().Run ("org not found" , func (t * testing.T ) {
116- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , uuid . NewString (), receiverEmail )
109+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , receiverEmail , biz . WithSender ( uuid . Nil ) )
117110 s .Error (err )
118111 s .True (biz .IsNotFound (err ))
119112 s .Nil (invite )
120113 })
121114
122115 s .T ().Run ("sender is not member of that org" , func (t * testing.T ) {
123- invite , err := s .OrgInvitation .Create (ctx , s .org3 .ID , s .user .ID , receiverEmail )
116+ invite , err := s .OrgInvitation .Create (ctx , s .org3 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
124117 s .Error (err )
125118 s .ErrorContains (err , "user does not have permission to invite to this org" )
126119 s .True (biz .IsNotFound (err ))
127120 s .Nil (invite )
128121 })
129122
130123 s .T ().Run ("sender is not member of that org but receiver is" , func (t * testing.T ) {
131- invite , err := s .OrgInvitation .Create (ctx , s .org3 .ID , s .user . ID , s . user2 . Email )
124+ invite , err := s .OrgInvitation .Create (ctx , s .org3 .ID , s .user2 . Email , biz . WithSender ( uuid . MustParse ( s . user . ID )) )
132125 s .Error (err )
133126 s .ErrorContains (err , "user does not have permission to invite to this org" )
134127 s .True (biz .IsNotFound (err ))
@@ -137,7 +130,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestCreate() {
137130
138131 s .T ().Run ("can create invites for org1 and 2" , func (t * testing.T ) {
139132 for _ , org := range []* biz.Organization {s .org1 , s .org2 } {
140- invite , err := s .OrgInvitation .Create (ctx , org .ID , s .user .ID , receiverEmail )
133+ invite , err := s .OrgInvitation .Create (ctx , org .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
141134 s .NoError (err )
142135 s .Equal (org , invite .Org )
143136 s .Equal (s .user , invite .Sender )
@@ -148,36 +141,36 @@ func (s *OrgInvitationIntegrationTestSuite) TestCreate() {
148141 })
149142
150143 s .T ().Run ("but can't create if there is one pending" , func (t * testing.T ) {
151- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .ID , receiverEmail )
144+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
152145 s .Error (err )
153146 s .ErrorContains (err , "already exists" )
154147 s .True (biz .IsErrValidation (err ))
155148 s .Nil (invite )
156149 })
157150
158151 s .T ().Run ("but it can if it's another email" , func (t * testing.T ) {
159- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s . user . ID , "anotheremail@cyberdyne.io" )
152+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , "anotheremail@cyberdyne.io" , biz . WithSender ( uuid . MustParse ( s . user . ID )) )
160153 s .Equal ("anotheremail@cyberdyne.io" , invite .ReceiverEmail )
161154 s .Equal (s .org1 , invite .Org )
162155 s .NoError (err )
163156 })
164157
165158 s .T ().Run ("the default role is viewer" , func (t * testing.T ) {
166- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s . user . ID , "viewer@cyberdyne.io" )
159+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , "viewer@cyberdyne.io" , biz . WithSender ( uuid . MustParse ( s . user . ID )) )
167160 s .NoError (err )
168161 s .Equal (authz .RoleViewer , invite .Role )
169162 })
170163
171164 s .T ().Run ("but can have other roles" , func (t * testing.T ) {
172165 for _ , r := range []authz.Role {authz .RoleOwner , authz .RoleAdmin , authz .RoleViewer } {
173- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s . user . ID , fmt .Sprintf ("%s@cyberdyne.io" , r ), biz .WithInvitationRole (r ))
166+ 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 ) ))
174167 s .NoError (err )
175168 s .Equal (r , invite .Role )
176169 }
177170 })
178171
179172 s .Run ("and the email address is downcased" , func () {
180- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s . user . ID , "WasCamelCase@cyberdyne.io" )
173+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , "WasCamelCase@cyberdyne.io" , biz . WithSender ( uuid . MustParse ( s . user . ID )) )
181174 s .NoError (err )
182175 s .Equal ("wascamelcase@cyberdyne.io" , invite .ReceiverEmail )
183176 })
@@ -203,7 +196,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestAcceptPendingInvitations() {
203196 })
204197
205198 s .T ().Run ("user is invited to org 1 as viewer" , func (t * testing.T ) {
206- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .ID , receiverEmail )
199+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
207200 require .NoError (s .T (), err )
208201 err = s .OrgInvitation .AcceptPendingInvitations (ctx , receiverEmail )
209202 s .NoError (err )
@@ -227,7 +220,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestAcceptPendingInvitations() {
227220 receiverEmail := fmt .Sprintf ("user%d@cyberdyne.io" , i )
228221 receiver , err := s .User .UpsertByEmail (ctx , receiverEmail , nil )
229222 s .NoError (err )
230- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s . user . ID , receiverEmail , biz .WithInvitationRole (r ))
223+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , receiverEmail , biz .WithInvitationRole (r ), biz . WithSender ( uuid . MustParse ( s . user . ID ) ))
231224 s .NoError (err )
232225 s .Equal (r , invite .Role )
233226 // accept the invite and make sure the new membership has the role
@@ -257,15 +250,15 @@ func (s *OrgInvitationIntegrationTestSuite) TestRevoke() {
257250 })
258251
259252 s .T ().Run ("invitation in another org" , func (t * testing.T ) {
260- _ , err := s .OrgInvitation .Create (ctx , s .org2 .ID , s .user .ID , receiverEmail )
253+ _ , err := s .OrgInvitation .Create (ctx , s .org2 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
261254 s .NoError (err )
262255 err = s .OrgInvitation .Revoke (ctx , s .org1 .ID , uuid .NewString ())
263256 s .Error (err )
264257 s .True (biz .IsNotFound (err ))
265258 })
266259
267260 s .T ().Run ("invitation not in pending state" , func (t * testing.T ) {
268- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .ID , receiverEmail )
261+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
269262 require .NoError (s .T (), err )
270263 err = s .OrgInvitation .AcceptInvitation (ctx , invite .ID .String ())
271264 require .NoError (s .T (), err )
@@ -278,7 +271,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestRevoke() {
278271 })
279272
280273 s .T ().Run ("happy path" , func (t * testing.T ) {
281- invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , s .user .ID , receiverEmail )
274+ invite , err := s .OrgInvitation .Create (ctx , s .org1 .ID , receiverEmail , biz . WithSender ( uuid . MustParse ( s .user .ID )) )
282275 require .NoError (s .T (), err )
283276 err = s .OrgInvitation .Revoke (ctx , s .org1 .ID , invite .ID .String ())
284277 s .NoError (err )
@@ -322,10 +315,10 @@ func (s *OrgInvitationIntegrationTestSuite) TestInvitationWithGroupContext() {
322315 invite , err := s .OrgInvitation .Create (
323316 ctx ,
324317 s .org1 .ID ,
325- s .user .ID ,
326318 receiverForGroupEmail ,
327319 biz .WithInvitationRole (authz .RoleViewer ),
328320 biz .WithInvitationContext (invitationContext ),
321+ biz .WithSender (uuid .MustParse (s .user .ID )),
329322 )
330323 require .NoError (t , err )
331324 require .NotNil (t , invite )
@@ -388,10 +381,10 @@ func (s *OrgInvitationIntegrationTestSuite) TestInvitationWithGroupContext() {
388381 invite , err := s .OrgInvitation .Create (
389382 ctx ,
390383 s .org1 .ID ,
391- s .user .ID ,
392384 anotherReceiverEmail ,
393385 biz .WithInvitationRole (authz .RoleViewer ),
394386 biz .WithInvitationContext (invitationContext ),
387+ biz .WithSender (uuid .MustParse (s .user .ID )),
395388 )
396389 require .NoError (t , err )
397390 require .NotNil (t , invite )
@@ -455,9 +448,9 @@ func (s *OrgInvitationIntegrationTestSuite) TestInvitationWithProjectContext() {
455448 invite , err := s .OrgInvitation .Create (
456449 ctx ,
457450 s .org1 .ID ,
458- s .user .ID ,
459451 receiverForProjectEmail ,
460452 biz .WithInvitationRole (authz .RoleViewer ),
453+ biz .WithSender (uuid .MustParse (s .user .ID )),
461454 biz .WithInvitationContext (invitationContext ),
462455 )
463456 require .NoError (t , err )
@@ -519,8 +512,8 @@ func (s *OrgInvitationIntegrationTestSuite) TestInvitationWithProjectContext() {
519512 invite , err := s .OrgInvitation .Create (
520513 ctx ,
521514 s .org1 .ID ,
522- s .user .ID ,
523515 anotherReceiverEmail ,
516+ biz .WithSender (uuid .MustParse (s .user .ID )),
524517 biz .WithInvitationRole (authz .RoleViewer ),
525518 biz .WithInvitationContext (invitationContext ),
526519 )
@@ -580,8 +573,8 @@ func (s *OrgInvitationIntegrationTestSuite) TestInvitationWithProjectContext() {
580573 invite , err := s .OrgInvitation .Create (
581574 ctx ,
582575 s .org1 .ID ,
583- s .user .ID ,
584576 combinedReceiverEmail ,
577+ biz .WithSender (uuid .MustParse (s .user .ID )),
585578 biz .WithInvitationRole (authz .RoleViewer ),
586579 biz .WithInvitationContext (invitationContext ),
587580 )
@@ -662,7 +655,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestInvitationWithProjectContext() {
662655 invite , err := s .Repos .OrgInvitationRepo .Create (
663656 ctx ,
664657 uuid .MustParse (s .org1 .ID ),
665- uuid .MustParse (s .user .ID ),
658+ biz . ToPtr ( uuid .MustParse (s .user .ID ) ),
666659 newReceiverEmail ,
667660 authz .RoleViewer ,
668661 invitationContext ,
@@ -691,7 +684,7 @@ func (s *OrgInvitationIntegrationTestSuite) TestInvitationWithProjectContext() {
691684 invite , err := s .Repos .OrgInvitationRepo .Create (
692685 ctx ,
693686 uuid .MustParse (s .org1 .ID ),
694- uuid .MustParse (s .user .ID ),
687+ biz . ToPtr ( uuid .MustParse (s .user .ID ) ),
695688 newReceiverEmail ,
696689 authz .RoleViewer ,
697690 invitationContext ,
0 commit comments