Răsfoiți Sursa

fix(core): Publish AccountRegistrationEvent when creating Customer via admin

Co-authored-by: stefanfeldner <stefanfeldner@gmail.com>
Michael Bromley 2 ani în urmă
părinte
comite
e0bd0368d9

+ 2 - 2
packages/core/e2e/customer.e2e-spec.ts

@@ -61,7 +61,7 @@ class TestEmailPlugin implements OnModuleInit {
 
     onModuleInit() {
         this.eventBus.ofType(AccountRegistrationEvent).subscribe(event => {
-            sendEmailFn(event);
+            sendEmailFn?.(event);
         });
     }
 }
@@ -505,7 +505,7 @@ describe('Customer resolver', () => {
             customerErrorGuard.assertSuccess(createCustomer);
 
             expect(createCustomer.user!.verified).toBe(true);
-            expect(sendEmailFn).toHaveBeenCalledTimes(0);
+            expect(sendEmailFn).toHaveBeenCalledTimes(1);
         });
 
         it('return error result when using an existing, non-deleted emailAddress', async () => {

+ 4 - 4
packages/core/e2e/shop-auth.e2e-spec.ts

@@ -61,16 +61,16 @@ class TestEmailPlugin implements OnModuleInit {
 
     onModuleInit() {
         this.eventBus.ofType(AccountRegistrationEvent).subscribe(event => {
-            sendEmailFn(event);
+            sendEmailFn?.(event);
         });
         this.eventBus.ofType(PasswordResetEvent).subscribe(event => {
-            sendEmailFn(event);
+            sendEmailFn?.(event);
         });
         this.eventBus.ofType(IdentifierChangeRequestEvent).subscribe(event => {
-            sendEmailFn(event);
+            sendEmailFn?.(event);
         });
         this.eventBus.ofType(IdentifierChangeEvent).subscribe(event => {
-            sendEmailFn(event);
+            sendEmailFn?.(event);
         });
     }
 }

+ 1 - 2
packages/core/src/service/services/customer.service.ts

@@ -263,9 +263,8 @@ export class CustomerService {
                     customer.user = result;
                 }
             }
-        } else {
-            this.eventBus.publish(new AccountRegistrationEvent(ctx, customer.user));
         }
+        this.eventBus.publish(new AccountRegistrationEvent(ctx, customer.user));
         await this.channelService.assignToCurrentChannel(customer, ctx);
         const createdCustomer = await this.connection.getRepository(ctx, Customer).save(customer);
         await this.customFieldRelationService.updateRelations(ctx, Customer, input, createdCustomer);