Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.checkoutDeliveryService.clearAddressVerificationResults();
} else if (results.decision === 'ACCEPT') {
this.submitAddress.emit(this.address.value);
} else if (results.decision === 'REJECT') {
// TODO: Workaround: allow server for decide is titleCode mandatory (if yes, provide personalized message)
if (
results.errors.errors.some(error => error.subject === 'titleCode')
) {
this.globalMessageService.add(
{ key: 'addressForm.titleRequired' },
GlobalMessageType.MSG_TYPE_ERROR
);
} else {
this.globalMessageService.add(
{ key: 'addressForm.invalidAddress' },
GlobalMessageType.MSG_TYPE_ERROR
);
}
this.checkoutDeliveryService.clearAddressVerificationResults();
} else if (results.decision === 'REVIEW') {
this.openSuggestedAddress(results);
}
});
.subscribe((results: AddressValidation) => {
if (results === 'FAIL') {
this.checkoutService.clearAddressVerificationResults();
} else if (results.decision === 'ACCEPT') {
this.submitAddress.emit(this.address.value);
} else if (results.decision === 'REJECT') {
// TODO: Workaround: allow server for decide is titleCode mandatory (if yes, provide personalized message)
if (
results.errors.errors.some(error => error.subject === 'titleCode')
) {
this.globalMessageService.add({
type: GlobalMessageType.MSG_TYPE_ERROR,
text: 'Title is required',
});
} else {
this.globalMessageService.add({
type: GlobalMessageType.MSG_TYPE_ERROR,
text: 'Invalid Address',
});
}
this.checkoutService.clearAddressVerificationResults();
} else if (results.decision === 'REVIEW') {
this.openSuggestedAddress(results);
}
});
CmsConfig,
CmsModule as CmsCoreModule,
defaultCmsModuleConfig,
} from '@spartacus/core';
// guards
import { guards } from './guards/index';
import { OutletModule } from '../outlet/outlet.module';
import { OutletDirective } from '../outlet/outlet.directive';
@NgModule({
imports: [
CommonModule,
HttpClientModule,
ConfigModule.withConfig(defaultCmsModuleConfig),
OutletModule,
CmsCoreModule,
],
providers: [...guards, { provide: CmsConfig, useExisting: Config }],
declarations: [],
exports: [OutletDirective],
})
export class CmsModule {}
PageLayoutModule,
} from '../../../cms-structure/page/index';
import { CartPageModule } from './cart-page/cart-page.module';
import { OrderConfirmationPageModule } from './order-confirmation-page/order-confirmation-page.module';
import { ProductPageModule } from './product-page/product-page.module';
import { defaultRoutingConfig } from './default-routing-config';
const pageModules = [
CartPageModule,
OrderConfirmationPageModule,
ProductPageModule,
];
@NgModule({
imports: [
ConfigModule.withConfig(defaultRoutingConfig),
CommonModule,
...pageModules,
PageLayoutModule,
RouterModule.forChild([
{
// This route can be dropped only when we have a mapping path to page label for content pages
path: null,
canActivate: [CmsPageGuard],
component: PageLayoutComponent,
data: { pageLabel: 'homepage', cxRoute: 'home' },
},
{
path: null,
canActivate: [LogoutGuard],
component: PageLayoutComponent,
data: { cxRoute: 'logout' },
it('should reset the processing state and display a success message', () => {
spyOn(userService, 'resetWithdrawConsentProcessState').and.stub();
spyOn(globalMessageService, 'add').and.stub();
component[onConsentWithdrawnSuccessMethod](true);
expect(
userService.resetWithdrawConsentProcessState
).toHaveBeenCalled();
expect(globalMessageService.add).toHaveBeenCalledWith(
{ key: 'consentManagementForm.message.success.withdrawn' },
GlobalMessageType.MSG_TYPE_CONFIRMATION
);
});
});
it('should add a global message and navigate to a url ', () => {
spyOn(globalMessageService, 'add').and.stub();
spyOn(routingService, 'go').and.stub();
component.onSuccess(true);
expect(globalMessageService.add).toHaveBeenCalledWith(
{ key: 'updateProfileForm.profileUpdateSuccess' },
GlobalMessageType.MSG_TYPE_CONFIRMATION
);
expect(routingService.go).toHaveBeenCalledWith({ cxRoute: 'home' });
});
});
it('should disableAddToHomeScreen after appinstalled is fired', () => {
spyOn(addToHomeService, 'disableAddToHomeScreen').and.stub();
const event = new Event('appinstalled');
winRef.nativeWindow.dispatchEvent(event);
expect(addToHomeService.disableAddToHomeScreen).toHaveBeenCalled();
expect(globalMessageService.add).toHaveBeenCalledWith(
{ key: 'pwa.addedToHomeScreen' },
GlobalMessageType.MSG_TYPE_CONFIRMATION
);
});
it('should be able to add global message', () => {
userService.getClaimCustomerCouponResultSuccess.and.returnValue(of(true));
routingService.getRouterState.and.returnValue(of(mockRouterState));
routingService.go.and.stub();
fixture.detectChanges();
expect(globalMessageService.add).toHaveBeenCalledWith(
{ key: 'myCoupons.claimCustomerCoupon' },
GlobalMessageType.MSG_TYPE_CONFIRMATION
);
expect(routingService.go).toHaveBeenCalledWith('/my-account/coupons');
});
});
it('should add global message and redirect to order history page after cancel success', () => {
service.cancelSuccess('1');
expect(service.clearCancelOrReturnRequestInputs).toHaveBeenCalled();
expect(userOrderService.resetCancelOrderProcessState).toHaveBeenCalled();
expect(routingService.go).toHaveBeenCalledWith({
cxRoute: 'orders',
});
expect(messageService.add).toHaveBeenCalledWith(
{
key: 'orderDetails.cancellationAndReturn.cancelSuccess',
params: { orderCode: '1' },
},
GlobalMessageType.MSG_TYPE_CONFIRMATION
);
});
it(`should catch 502 of error`, inject([HttpClient], (http: HttpClient) => {
http
.get('/test')
.pipe(catchError((error: any) => throwError(error)))
.subscribe(_result => {}, error => (this.error = error));
const mockReq = httpMock.expectOne(req => {
return req.method === 'GET';
});
mockReq.flush({}, { status: 502, statusText: 'Bad Gateway' });
expect(mockMessageService.add).toHaveBeenCalledWith({
type: GlobalMessageType.MSG_TYPE_ERROR,
text: 'A server error occurred. Please try again later.'
});
}));