Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: TTL-836 customer duplicated error message
  • Loading branch information
mmaquina committed Jul 24, 2023
commit 6ec0660c19ea62e482aba558aa72c8cc35364f33
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ToastrModule, ToastrService } from 'ngx-toastr';
import { INFO_SAVED_SUCCESSFULLY, INFO_DELETE_SUCCESSFULLY } from '../../shared/messages';

describe('CustomerEffects', () => {
fdescribe('CustomerEffects', () => {
let actions$: Observable<Action>;
let effects: CustomerEffects;
let service: CustomerService;
Expand Down Expand Up @@ -88,11 +88,12 @@ describe('CustomerEffects', () => {

it('action type is CREATE_CUSTOMER_FAIL when service fail in execution', async () => {
actions$ = of({ type: CustomerManagementActionTypes.CREATE_CUSTOMER, payload: customer });

spyOn(toastrService, 'error');
spyOn(service, 'createCustomer').and.returnValue(throwError({ error: { message: 'fail!' } }));
spyOn(service, 'createCustomer').and.returnValue(throwError({ error: 'Duplicated' }));

effects.createCustomer$.subscribe((action) => {
expect(toastrService.error).toHaveBeenCalled();
expect(toastrService.error).toHaveBeenCalledWith('Duplicated');
expect(action.type).toEqual(CustomerManagementActionTypes.CREATE_CUSTOMER_FAIL);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INFO_SAVED_SUCCESSFULLY, INFO_DELETE_SUCCESSFULLY } from '../../shared/messages';
import { INFO_SAVED_SUCCESSFULLY, INFO_DELETE_SUCCESSFULLY, DUPLICATED_ERROR } from '../../shared/messages';
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
Expand Down Expand Up @@ -46,7 +46,7 @@ export class CustomerEffects {
return new actions.CreateCustomerSuccess(customerData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.toastrService.error(error.error);
return of(new actions.CreateCustomerFail(error));
})
)
Expand Down