1- using Bit . Core . Auth . Models . Business . Tokenables ;
1+ using Bit . Core . Auth . Models . Api . Request . Accounts ;
2+ using Bit . Core . Auth . Models . Business . Tokenables ;
23using Bit . Core . Auth . UserFeatures . Registration . Implementations ;
34using Bit . Core . Entities ;
45using Bit . Core . Exceptions ;
@@ -40,22 +41,55 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenIsNewUserAndEn
4041 . HasVerifiedDomainWithBlockClaimedDomainPolicyAsync ( Arg . Any < string > ( ) )
4142 . Returns ( false ) ;
4243
43- sutProvider . GetDependency < IMailService > ( )
44- . SendRegistrationVerificationEmailAsync ( email , Arg . Any < string > ( ) )
45- . Returns ( Task . CompletedTask ) ;
44+ var mockedToken = "token" ;
45+ sutProvider . GetDependency < IDataProtectorTokenFactory < RegistrationEmailVerificationTokenable > > ( )
46+ . Protect ( Arg . Any < RegistrationEmailVerificationTokenable > ( ) )
47+ . Returns ( mockedToken ) ;
48+
49+ // Act
50+ var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ;
51+
52+ // Assert
53+ await sutProvider . GetDependency < IMailService > ( )
54+ . Received ( 1 )
55+ . SendRegistrationVerificationEmailAsync ( email , mockedToken , null ) ;
56+ Assert . Null ( result ) ;
57+ }
58+
59+ [ Theory ]
60+ [ BitAutoData ]
61+ public async Task SendVerificationEmailForRegistrationCommand_WhenFromMarketingIsPremium_SendsEmailWithMarketingParameterAndReturnsNull ( SutProvider < SendVerificationEmailForRegistrationCommand > sutProvider ,
62+ string email , string name , bool receiveMarketingEmails )
63+ {
64+ // Arrange
65+ sutProvider . GetDependency < IUserRepository > ( )
66+ . GetByEmailAsync ( email )
67+ . ReturnsNull ( ) ;
68+
69+ sutProvider . GetDependency < GlobalSettings > ( )
70+ . EnableEmailVerification = true ;
71+
72+ sutProvider . GetDependency < GlobalSettings > ( )
73+ . DisableUserRegistration = false ;
74+
75+ sutProvider . GetDependency < IOrganizationDomainRepository > ( )
76+ . HasVerifiedDomainWithBlockClaimedDomainPolicyAsync ( Arg . Any < string > ( ) )
77+ . Returns ( false ) ;
4678
4779 var mockedToken = "token" ;
4880 sutProvider . GetDependency < IDataProtectorTokenFactory < RegistrationEmailVerificationTokenable > > ( )
4981 . Protect ( Arg . Any < RegistrationEmailVerificationTokenable > ( ) )
5082 . Returns ( mockedToken ) ;
5183
84+ var fromMarketing = MarketingInitiativeConstants . Premium ;
85+
5286 // Act
53- var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ;
87+ var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails , fromMarketing ) ;
5488
5589 // Assert
5690 await sutProvider . GetDependency < IMailService > ( )
5791 . Received ( 1 )
58- . SendRegistrationVerificationEmailAsync ( email , mockedToken ) ;
92+ . SendRegistrationVerificationEmailAsync ( email , mockedToken , fromMarketing ) ;
5993 Assert . Null ( result ) ;
6094 }
6195
@@ -87,12 +121,12 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenIsExistingUser
87121 . Returns ( mockedToken ) ;
88122
89123 // Act
90- var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ;
124+ var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ;
91125
92126 // Assert
93127 await sutProvider . GetDependency < IMailService > ( )
94128 . DidNotReceive ( )
95- . SendRegistrationVerificationEmailAsync ( email , mockedToken ) ;
129+ . SendRegistrationVerificationEmailAsync ( email , mockedToken , null ) ;
96130 Assert . Null ( result ) ;
97131 }
98132
@@ -124,7 +158,7 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenIsNewUserAndEn
124158 . Returns ( mockedToken ) ;
125159
126160 // Act
127- var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ;
161+ var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ;
128162
129163 // Assert
130164 Assert . Equal ( mockedToken , result ) ;
@@ -140,7 +174,7 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenOpenRegistrati
140174 . DisableUserRegistration = true ;
141175
142176 // Act & Assert
143- await Assert . ThrowsAsync < BadRequestException > ( ( ) => sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ) ;
177+ await Assert . ThrowsAsync < BadRequestException > ( ( ) => sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ) ;
144178 }
145179
146180 [ Theory ]
@@ -166,7 +200,7 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenIsExistingUser
166200 . Returns ( false ) ;
167201
168202 // Act & Assert
169- await Assert . ThrowsAsync < BadRequestException > ( ( ) => sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ) ;
203+ await Assert . ThrowsAsync < BadRequestException > ( ( ) => sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ) ;
170204 }
171205
172206 [ Theory ]
@@ -177,7 +211,7 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenNullEmail_Thro
177211 sutProvider . GetDependency < GlobalSettings > ( )
178212 . DisableUserRegistration = false ;
179213
180- await Assert . ThrowsAsync < ArgumentNullException > ( async ( ) => await sutProvider . Sut . Run ( null , name , receiveMarketingEmails ) ) ;
214+ await Assert . ThrowsAsync < ArgumentNullException > ( async ( ) => await sutProvider . Sut . Run ( null , name , receiveMarketingEmails , null ) ) ;
181215 }
182216
183217 [ Theory ]
@@ -187,7 +221,7 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenEmptyEmail_Thr
187221 {
188222 sutProvider . GetDependency < GlobalSettings > ( )
189223 . DisableUserRegistration = false ;
190- await Assert . ThrowsAsync < ArgumentNullException > ( async ( ) => await sutProvider . Sut . Run ( "" , name , receiveMarketingEmails ) ) ;
224+ await Assert . ThrowsAsync < ArgumentNullException > ( async ( ) => await sutProvider . Sut . Run ( "" , name , receiveMarketingEmails , null ) ) ;
191225 }
192226
193227 [ Theory ]
@@ -210,7 +244,7 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenBlockedDomain_
210244 . Returns ( true ) ;
211245
212246 // Act & Assert
213- var exception = await Assert . ThrowsAsync < BadRequestException > ( ( ) => sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ) ;
247+ var exception = await Assert . ThrowsAsync < BadRequestException > ( ( ) => sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ) ;
214248 Assert . Equal ( "This email address is claimed by an organization using Bitwarden." , exception . Message ) ;
215249 }
216250
@@ -246,7 +280,7 @@ public async Task SendVerificationEmailForRegistrationCommand_WhenAllowedDomain_
246280 . Returns ( mockedToken ) ;
247281
248282 // Act
249- var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ;
283+ var result = await sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ;
250284
251285 // Assert
252286 Assert . Equal ( mockedToken , result ) ;
@@ -270,7 +304,7 @@ public async Task SendVerificationEmailForRegistrationCommand_InvalidEmailFormat
270304
271305 // Act & Assert
272306 var exception = await Assert . ThrowsAsync < BadRequestException > ( ( ) =>
273- sutProvider . Sut . Run ( email , name , receiveMarketingEmails ) ) ;
307+ sutProvider . Sut . Run ( email , name , receiveMarketingEmails , null ) ) ;
274308 Assert . Equal ( "Invalid email address format." , exception . Message ) ;
275309 }
276310}
0 commit comments