Skip to content

Commit

Permalink
Merge branch 'feature/CXINT-1850' of github.com:SAP/spartacus into fe…
Browse files Browse the repository at this point in the history
…ature/CXINT-1850
  • Loading branch information
SherwinVarghese committed Jul 21, 2023
2 parents 0618646 + 849a72b commit 08e0e6a
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 69 deletions.
7 changes: 3 additions & 4 deletions .env-cmdrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@
"CX_B2B": "true"
},
"s4om": {
"CX_BASE_URL": "https://backoffice.c2twgq1sul-sapcxteam1-d11-public.model-t.myhybris.cloud",
"CX_CDC": "false",
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s8-public.model-t.myhybris.cloud",
"CX_B2B": "true",
"CX_S4OM": "true"
},
"requested-delivery-date": {
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s1-public.model-t.myhybris.cloud",
"CX_REQUESTED_DELIVERY_DATE": true
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s8-public.model-t.myhybris.cloud",
"CX_REQUESTED_DELIVERY_DATE": "true"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import {
export class RequestedDeliveryDateBadRequestHandler extends HttpErrorHandler {
responseStatus = HttpResponseStatus.BAD_REQUEST;

hasMatch(errorResponse: HttpErrorResponse): boolean {
return (
super.hasMatch(errorResponse) && this.getErrors(errorResponse)?.length > 0
);
}

handleError(request: HttpRequest<any>, response: HttpErrorResponse) {
if (request && this.getErrors(response)?.length) {
this.globalMessageService.add(
Expand All @@ -31,7 +37,9 @@ export class RequestedDeliveryDateBadRequestHandler extends HttpErrorHandler {

protected getErrors(response: HttpErrorResponse): ErrorModel[] {
return (response.error?.errors).filter(
(error: any) => error?.type === 'ValidationError'
(error: any) =>
error?.type === 'ValidationError' &&
error?.message === 'checkout.multi.requestedretrievaldatevalid.error'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
DatePickerModule,
OutletContextData,
} from '@spartacus/storefront';
import { of } from 'rxjs';
import { of, throwError } from 'rxjs';
import { RequestedDeliveryDateFacade } from '../../facade/requested-delivery-date.facade';
import { DeliveryModeDatePickerComponent } from './delivery-mode-date-picker.component';

Expand Down Expand Up @@ -184,7 +184,7 @@ describe('DeliveryModeDatePickerComponent', () => {
).toHaveBeenCalled();
});

it('should call setRequestedDeliveryDate when form value changes and show info message', (done) => {
it('should call setRequestedDeliveryDate when form value changes and show info message on success', (done) => {
spyOn(component['globalMessageService'], 'add');
const requestedRetrievalAt = '2023-05-03';
const earliestRetrievalAt = '2023-09-15';
Expand Down Expand Up @@ -229,6 +229,55 @@ describe('DeliveryModeDatePickerComponent', () => {
});
});

it('should show error message when backend OCC API returns UnknownResourceError', (done) => {
spyOn(component['globalMessageService'], 'add');

component['requestedDelDateFacade'].setRequestedDeliveryDate = jasmine
.createSpy('setRequestedDeliveryDate')
.and.returnValue(
throwError({
error: {
errors: [
{
message:
'There is no resource for path /occ/v2/powertools-spa/users/user.lname%40sap-cx.com/carts/0000003004/requestedretrievaldate',
type: 'UnknownResourceError',
},
],
},
})
);

const earliestRetrievalAt = '2023-09-15';
component['cartEntry'] = {
earliestRetrievalAt,
code: '123',
user: {
uid: 'current',
},
} as any;
component.ngOnInit();
expect(component['requestedRetrievalAt']).toEqual(earliestRetrievalAt);
expect(component['form'].get('requestDeliveryDate')?.value).toEqual(
earliestRetrievalAt
);
expect(
component['requestedDelDateFacade'].setRequestedDeliveryDate
).toHaveBeenCalled();

component['requestedDelDateFacade']
.setRequestedDeliveryDate('current', '123', earliestRetrievalAt)
.subscribe({
error: () => {
expect(component['globalMessageService'].add).toHaveBeenCalledWith(
{ key: 'requestedDeliveryDate.errorMessage' },
GlobalMessageType.MSG_TYPE_ERROR
);
done();
},
});
});

it('should unsubscribe from subscription on component destruction', () => {
spyOn(component['subscription'], 'unsubscribe');
component.ngOnDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnDestroy, OnInit, Optional } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { Cart } from '@spartacus/cart/base/root';
import { CheckoutSupportedDeliveryModesQueryReloadEvent } from '@spartacus/checkout/base/root';
import {
CxDatePipe,
ErrorModel,
EventService,
GlobalMessageService,
GlobalMessageType,
Expand Down Expand Up @@ -119,19 +121,35 @@ export class DeliveryModeDatePickerComponent implements OnInit, OnDestroy {
this.subscription.add(
this.requestedDelDateFacade
.setRequestedDeliveryDate(userId, cartId, requestedDate)
.subscribe(() => {
this.eventService.dispatch(
{},
CheckoutSupportedDeliveryModesQueryReloadEvent
);
this.globalMessageService.add(
{ key: 'requestedDeliveryDate.successMessage' },
GlobalMessageType.MSG_TYPE_INFO
);
.subscribe({
next: () => {
this.eventService.dispatch(
{},
CheckoutSupportedDeliveryModesQueryReloadEvent
);
this.globalMessageService.add(
{ key: 'requestedDeliveryDate.successMessage' },
GlobalMessageType.MSG_TYPE_INFO
);
},
error: (error: HttpErrorResponse) => {
if (error && this.getErrors(error)?.length) {
this.globalMessageService.add(
{ key: 'requestedDeliveryDate.errorMessage' },
GlobalMessageType.MSG_TYPE_ERROR
);
}
},
})
);
}

getErrors(response: HttpErrorResponse): ErrorModel[] {
return (response.error?.errors).filter(
(error: any) => error?.type === 'UnknownResourceError'
);
}

ngOnDestroy(): void {
this.subscription.unsubscribe();
}
Expand Down
3 changes: 2 additions & 1 deletion integration-libs/s4om/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"@spartacus/schematics": "6.3.0-1",
"@spartacus/storefront": "6.3.0-1",
"@spartacus/styles": "6.3.0-1",
"rxjs": "^6.6.0"
"rxjs": "^6.6.0",
"@spartacus/requested-delivery-date": "6.3.0-1"
},
"publishConfig": {
"access": "public"
Expand Down
13 changes: 12 additions & 1 deletion integration-libs/s4om/schematics/add-s4om/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@
"features": {
"type": "array",
"uniqueItems": true,
"default": ["S4HANA-Order-Management"]
"default": ["S4HANA-Order-Management"],
"x-prompt": {
"message": "Which S/4 HANA Order Management features would you like to set up?",
"type": "list",
"items": [
{ "value": "S4HANA-Order-Management", "label": "Schedule Lines" },
{
"value": "Requested-Delivery-Date",
"label": "Requested Delivery Date"
}
]
}
}
},
"required": []
Expand Down
17 changes: 9 additions & 8 deletions projects/schematics/src/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@
"@angular/common": "^15.2.4",
"@angular/core": "^15.2.4",
"@angular/forms": "^15.2.4",
"@spartacus/cart": "5.0.0",
"@spartacus/checkout": "5.0.0",
"@spartacus/core": "5.0.0",
"@spartacus/order": "5.0.0",
"@spartacus/schematics": "5.0.0",
"@spartacus/storefront": "5.0.0",
"@spartacus/styles": "5.0.0",
"@spartacus/cart": "6.3.0-1",
"@spartacus/checkout": "6.3.0-1",
"@spartacus/core": "6.3.0-1",
"@spartacus/order": "6.3.0-1",
"@spartacus/schematics": "6.3.0-1",
"@spartacus/storefront": "6.3.0-1",
"@spartacus/styles": "6.3.0-1",
"rxjs": "^6.6.0"
},
"@spartacus/smartedit": {
Expand Down Expand Up @@ -339,7 +339,8 @@
"@spartacus/schematics": "6.3.0-1",
"@spartacus/storefront": "6.3.0-1",
"@spartacus/styles": "6.3.0-1",
"rxjs": "^6.6.0"
"rxjs": "^6.6.0",
"@spartacus/requested-delivery-date": "6.3.0-1"
},
"@spartacus/segment-refs": {
"@angular-devkit/schematics": "^15.2.4",
Expand Down
1 change: 1 addition & 0 deletions projects/schematics/src/shared/utils/graph-utils_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ describe('Graph utils', () => {
SPARTACUS_CART,
SPARTACUS_ORDER,
SPARTACUS_CHECKOUT,
SPARTACUS_REQUESTED_DELIVERY_DATE,
SPARTACUS_TRACKING,
SPARTACUS_ORGANIZATION,
SPARTACUS_ASM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import * as b2bCheckout from '../../../helpers/b2b/b2b-checkout';
import {
interceptOrdersEndpoint,
waitForResponse,
waitForResponse
} from '../../../helpers/order-history';
import * as rddHelper from '../../../helpers/vendor/requested-delivery-date/requested-delivery-date';
import * as s4Helper from '../../../helpers/vendor/s4om/s4om';
import {
ORDER_REQUEST_ENDPOINT,
order_type,
POWERTOOLS_BASESITE,
USER_REQUEST_ENDPOINT,
USER_REQUEST_ENDPOINT
} from '../../../sample-data/b2b-checkout';
import { isolateTestsBefore } from '../../../support/utils/test-isolation';

Expand Down Expand Up @@ -120,7 +120,11 @@ describe('Requested Delivery Date', { testIsolation: false }, () => {
s4Helper.s4omB2BUnit
);
rddHelper.verifyRDDOrderDetailPage(formattedDate);
<<<<<<< HEAD
rddHelper.setOrderConfirmationIdInSessionStorage();
=======
s4Helper.setOrderConfirmationIdInSessionStorage('rddOrderId');
>>>>>>> 849a72b5f1438f77b7f4009ff64ed4d102d024c9
});
});

Expand All @@ -131,13 +135,11 @@ describe('Requested Delivery Date', { testIsolation: false }, () => {
waitForResponse(ordersAlias);

const rddOrderId = window.sessionStorage.getItem('rddOrderId');
cy.wrap(rddOrderId).should('not.be.undefined');
cy.get('cx-order-history h2').should('contain', 'Order history');
cy.get('#order-history-table').should('contain', rddOrderId);
cy.get('.cx-order-history-po a').should('contain', rddHelper.poNumber);
cy.get('.cx-order-history-cost-center a').should(
'contain',
s4Helper.s4omCostCenter
cy.wrap(rddOrderId).should('not.be.null');
s4Helper.findRowInOrderHistoryTable(
ordersAlias,
rddOrderId,
rddHelper.poNumber
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('S4HANA Order management', { testIsolation: false }, () => {
});

it('should select delivery mode', () => {
b2bCheckout.selectAccountDeliveryMode();
s4omHelper.selectAccountDeliveryMode();
});

it('should review and place order', () => {
Expand All @@ -90,10 +90,12 @@ describe('S4HANA Order management', { testIsolation: false }, () => {
true,
s4omHelper.s4omPONumber,
null,
s4omHelper.s4omPONumber,
s4omHelper.s4omCostCenter,
s4omHelper.s4omB2BUnit
);
s4omHelper.verifyScheduleLineInfo();
s4omHelper.setOrderConfirmationIdInSessionStorage('s4omOrderId');
});
});
describe('Schedule lines in Order History', () => {
Expand All @@ -102,9 +104,14 @@ describe('S4HANA Order management', { testIsolation: false }, () => {
const ordersAlias = interceptOrdersEndpoint();
waitForResponse(ordersAlias);

cy.get('cx-order-history h2').should('contain', 'Order history');
cy.get('.cx-order-history-po a').should('contain', poNumber);
//cy.get('.cx-order-history-cost-center a').should('contain', s4omHelper.s4omCostCenter);
const s4omPastOrderId =
window.sessionStorage.getItem('s4omOrderId') || '103439';
cy.wrap(s4omPastOrderId).should('not.be.null');
s4omHelper.findRowInOrderHistoryTable(
ordersAlias,
s4omPastOrderId,
poNumber
);
});

it('should be able to view a past order detail in order detail page with schedule line delivery information', () => {
Expand All @@ -115,7 +122,11 @@ describe('S4HANA Order management', { testIsolation: false }, () => {
)}/users/current/orders/*`,
}).as('getOrderDetail');

cy.visit('/my-account/order/' + s4omHelper.s4omPastOrderId);
const s4omPastOrderId =
window.sessionStorage.getItem('s4omOrderId') ||
s4omHelper.s4omPastOrderId;
cy.wrap(s4omPastOrderId).should('not.be.null');
cy.visit('/my-account/order/' + s4omPastOrderId);
cy.wait('@getOrderDetail');

s4omHelper.reviewB2bOrderDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as alerts from '../../global-message';

export const poNumber = '777';

export const rddTabbingConfig: TabbingOrderConfig = {
export const rddDeliveryModeTabbingConfig: TabbingOrderConfig = {
...tabbingOrderConfig,
deliveryMode: [
{ value: 'Method ofPayment', type: TabbingOrderTypes.LINK },
Expand Down Expand Up @@ -68,7 +68,7 @@ export function selectAccountDeliveryMode() {
// Accessibility
verifyTabbingOrder(
'cx-page-layout.MultiStepCheckoutSummaryPageTemplate',
rddTabbingConfig.deliveryMode
rddDeliveryModeTabbingConfig.deliveryMode
);
});
cy.wait(`@cart_refresh`).then((xhr) => {
Expand Down Expand Up @@ -171,19 +171,3 @@ export function interceptPutRequestedRetrievalAtEndpoint() {
)}/**/requestedretrievaldate?requestedRetrievalAt=*`,
}).as('putRetrievalAt');
}

export function setOrderConfirmationIdInSessionStorage() {
cy.get('cx-order-overview .container').within(() => {
cy.get('.cx-summary-card:nth-child(1)').within(() => {
cy.get('cx-card:nth-child(1)')
.first()
.within(() => {
cy.get('.cx-card-title').should('contain', 'Order Number');
cy.get('.cx-card-label').then(($el) => {
Cypress.env('rddOrderId', $el.text());
window.sessionStorage.setItem('rddOrderId', $el.text().trim());
});
});
});
});
}
Loading

0 comments on commit 08e0e6a

Please sign in to comment.