@@ -5,15 +5,34 @@ import { databaseBuilder, expect, sinon } from '../../../../test-helper.js';
5
5
6
6
describe ( 'Integration | Identity Access Management | Domain | UseCase | self-delete-user-account' , function ( ) {
7
7
context ( 'when user can self delete their account' , function ( ) {
8
- it ( 'doesn’t throw ForbiddenError' , async function ( ) {
9
- // given
10
- const userId = databaseBuilder . factory . buildUser ( ) . id ;
11
- await databaseBuilder . commit ( ) ;
8
+ context ( 'when user has an email' , function ( ) {
9
+ it ( 'doesn’t throw ForbiddenError and creates a SendEmailJob' , async function ( ) {
10
+ // given
11
+ const userId = databaseBuilder . factory . buildUser ( ) . id ;
12
+ await databaseBuilder . commit ( ) ;
12
13
13
- sinon . stub ( config . featureToggles , 'isSelfAccountDeletionEnabled' ) . value ( true ) ;
14
+ sinon . stub ( config . featureToggles , 'isSelfAccountDeletionEnabled' ) . value ( true ) ;
14
15
15
- // when & then
16
- await expect ( usecases . selfDeleteUserAccount ( { userId } ) ) . to . not . be . rejectedWith ( ForbiddenAccess ) ;
16
+ // when & then
17
+ await expect ( usecases . selfDeleteUserAccount ( { userId } ) ) . to . not . be . rejectedWith ( ForbiddenAccess ) ;
18
+
19
+ await expect ( 'SendEmailJob' ) . to . have . been . performed . withJobsCount ( 1 ) ;
20
+ } ) ;
21
+ } ) ;
22
+
23
+ context ( 'when user doesn’t have an email' , function ( ) {
24
+ it ( 'doesn’t throw ForbiddenError and doesn’t create a SendEmailJob' , async function ( ) {
25
+ // given
26
+ const userId = databaseBuilder . factory . buildUser . withoutPixAuthenticationMethod ( ) . id ;
27
+ await databaseBuilder . commit ( ) ;
28
+
29
+ sinon . stub ( config . featureToggles , 'isSelfAccountDeletionEnabled' ) . value ( true ) ;
30
+
31
+ // when & then
32
+ await expect ( usecases . selfDeleteUserAccount ( { userId } ) ) . to . not . be . rejectedWith ( ForbiddenAccess ) ;
33
+
34
+ await expect ( 'SendEmailJob' ) . to . have . been . performed . withJobsCount ( 0 ) ;
35
+ } ) ;
17
36
} ) ;
18
37
} ) ;
19
38
0 commit comments