Skip to content

Commit

Permalink
Merge branch 'epic/b2b-commerce-quotes' of https://github.com/SAP/spa…
Browse files Browse the repository at this point in the history
…rtacus into epic/b2b-commerce-quotes
  • Loading branch information
ChristophHi committed Sep 15, 2023
2 parents 0f6fc99 + 2e793ec commit 6a35be9
Show file tree
Hide file tree
Showing 15 changed files with 470 additions and 269 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { TestBed } from '@angular/core/testing';
import {
Cart,
ORDER_ENTRY_PROMOTIONS_NORMALIZER,
PromotionResult,
} from '@spartacus/cart/base/root';
import { ConverterService, PRODUCT_NORMALIZER } from '@spartacus/core';
import { ConverterService, Occ, PRODUCT_NORMALIZER } from '@spartacus/core';
import { OccCartNormalizer } from './occ-cart-normalizer';

class MockConverterService {
Expand Down Expand Up @@ -88,4 +89,23 @@ describe('OccCartNormalizer', () => {
},
]);
});
describe('handleQuote', () => {
const quoteCode = '00100092';
const source: Occ.Cart = { sapQuote: { code: quoteCode } };

it('should set quote code if sapQuote is present in OCC response', () => {
const target: Cart = {};
occCartNormalizer['handleQuote'](source, target);
expect(target.quoteCode).toBe(quoteCode);
});

it('should ignore missing sapQuote in OCC response', () => {
const target: Cart = {};
occCartNormalizer['handleQuote'](
{ ...source, sapQuote: undefined },
target
);
expect(target.quoteCode).toBe(undefined);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class OccCartNormalizer implements Converter<Occ.Cart, Cart> {
}

this.removeDuplicatePromotions(source, target);
this.handleQuote(source, target);

if (source.entries) {
target.entries = source.entries.map((entry) => ({
Expand All @@ -41,6 +42,12 @@ export class OccCartNormalizer implements Converter<Occ.Cart, Cart> {
return target;
}

protected handleQuote(source: Occ.Cart, target: Cart) {
if (source.sapQuote) {
target.quoteCode = source.sapQuote.code;
}
}

/**
* Remove all duplicate promotions
*/
Expand Down
1 change: 1 addition & 0 deletions feature-libs/cart/base/root/models/cart.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface Cart {
totalTax?: Price;
totalUnitCount?: number;
user?: Principal;
quoteCode?: string;
}

export interface CartModification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MockCommerceQuotesFacade implements Partial<QuoteFacade> {
return mockQuoteDetails$.asObservable();
}
performQuoteAction(
_quoteCode: string,
_quote: Quote,
_quoteAction: QuoteActionType
): Observable<unknown> {
return EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MockCommerceQuotesFacade implements Partial<QuoteFacade> {
return mockQuoteDetails$.asObservable();
}
performQuoteAction(
_quoteCode: string,
_quote: Quote,
_quoteAction: QuoteActionType
): Observable<unknown> {
return EMPTY;
Expand Down Expand Up @@ -359,7 +359,7 @@ describe('QuoteActionsByRoleComponent', () => {
component.onClick(QuoteActionType.SUBMIT, newMockQuoteWithSubmitAction);
launchDialogService.closeDialog('yes');
expect(facade.performQuoteAction).toHaveBeenCalledWith(
newMockQuoteWithSubmitAction.code,
newMockQuoteWithSubmitAction,
QuoteActionType.SUBMIT
);
});
Expand All @@ -373,7 +373,7 @@ describe('QuoteActionsByRoleComponent', () => {
);
editButton.click();
expect(facade.performQuoteAction).toHaveBeenCalledWith(
mockQuote.code,
mockQuote,
QuoteActionType.EDIT
);
});
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('QuoteActionsByRoleComponent', () => {
component['handleConfirmationDialogClose'](QuoteActionType.EDIT, context);
launchDialogService.closeDialog('yes');
expect(facade.performQuoteAction).toHaveBeenCalledWith(
mockCode,
mockQuote,
QuoteActionType.EDIT
);
expect(globalMessageService.add).not.toHaveBeenCalled();
Expand All @@ -486,7 +486,7 @@ describe('QuoteActionsByRoleComponent', () => {
);
launchDialogService.closeDialog('yes');
expect(facade.performQuoteAction).toHaveBeenCalledWith(
mockCode,
mockQuote,
QuoteActionType.SUBMIT
);
expect(globalMessageService.add).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {

performAction(action: QuoteActionType, quote: Quote) {
if (!this.isConfirmationDialogRequired(action, quote.state)) {
this.quoteFacade.performQuoteAction(quote.code, action);
this.quoteFacade.performQuoteAction(quote, action);
return;
}

Expand Down Expand Up @@ -118,9 +118,7 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {
this.launchDialogService.dialogClose
.pipe(
filter((reason) => reason === 'yes'),
tap(() =>
this.quoteFacade.performQuoteAction(context.quote.code, action)
),
tap(() => this.quoteFacade.performQuoteAction(context.quote, action)),
filter(() => !!context.successMessage),
tap(() =>
this.globalMessageService.add(
Expand All @@ -140,7 +138,7 @@ export class QuoteActionsByRoleComponent implements OnInit, OnDestroy {
: GlobalMessageType.MSG_TYPE_CONFIRMATION;
}

requote(quoteId: string) {
protected requote(quoteId: string) {
this.quoteFacade.requote(quoteId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('QuoteRequestDialogComponent', () => {
});

expect(quoteFacade.performQuoteAction).toHaveBeenCalledWith(
quoteCode,
mockCreatedQuote,
QuoteActionType.SUBMIT
);
expect(launchDialogService.closeDialog).toHaveBeenCalledWith('success');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ export class QuoteRequestDialogComponent {
params: { quoteId: quote.code },
});
} else {
this.quoteFacade.performQuoteAction(
quote.code,
QuoteActionType.SUBMIT
);
this.quoteFacade.performQuoteAction(quote, QuoteActionType.SUBMIT);
}
this.dismissModal('success');
})
Expand Down
Loading

0 comments on commit 6a35be9

Please sign in to comment.