Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (CXSPA-9098)-Coupon Codes is used in Coupon Campaign URL #19739

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7f6b77d
CXSPA-9098, fix the issue Coupon Codes is used in Coupon Campaign URL…
crisli001 Dec 9, 2024
d4587da
fix failed unit test
crisli001 Dec 9, 2024
9ba5cd1
fix failed unit test cases
crisli001 Dec 9, 2024
5388aa2
fix sonar issues
crisli001 Dec 10, 2024
967974e
fix sonar issues using const instead of let
crisli001 Dec 10, 2024
bce0e55
fix code validation failed issues
crisli001 Dec 10, 2024
31a383f
do code format for the PR
crisli001 Dec 10, 2024
b3005d3
Merge branch 'develop' into bugfix/CXSPA-9098
crisli001 Dec 10, 2024
19f4cd7
Merge branch 'develop' into bugfix/CXSPA-9098
crisli001 Dec 10, 2024
7858833
CXSPA-9098, fix breaking changes by add feature toggle and inject
crisli001 Dec 18, 2024
1b7b8db
CXSPA-9098, fix conflicts
crisli001 Dec 18, 2024
3694d1b
Merge branch 'develop' into bugfix/CXSPA-9098
crisli001 Dec 18, 2024
44dcf06
CXSPA-9098, fix module-import circular dependency
crisli001 Dec 18, 2024
d751b80
CXSPA-9098, remove unnecessary feature toggle
crisli001 Dec 19, 2024
525940f
Merge branch 'develop' into bugfix/CXSPA-9098
crisli001 Dec 19, 2024
c23b62d
Trigger Build
crisli001 Dec 19, 2024
4ad8cfe
CXSPA-9098, fix failed cypress test cases
crisli001 Dec 20, 2024
4851cca
Merge branch 'develop' into bugfix/CXSPA-9098
crisli001 Dec 20, 2024
3687735
Merge branch 'develop' into bugfix/CXSPA-9098
crisli001 Dec 22, 2024
0667bae
CXSPA-9098, try enhance case
crisli001 Dec 22, 2024
73c7b33
Merge branch 'bugfix/CXSPA-9098' of https://github.com/SAP/spartacus …
crisli001 Dec 22, 2024
cd3b128
Trigger Build
crisli001 Dec 22, 2024
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
7 changes: 7 additions & 0 deletions projects/assets/src/translations/en/myAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
"findProducts": "Find Products",
"status": "Status:",
"dialogTitle": "Coupon",
"claimCoupondialogTitle": "Add To Your Coupon List",
"claimCouponCode": {
"label": "Coupon Code",
"placeholder": "Enter the coupon code to claim a coupon"
},
"reset": "RESET",
"claim": "CLAIM",
"claimCustomerCoupon": "You have successfully claimed this coupon.",
"myCoupons": "My coupons",
"startDateAsc": "Start Date (ascending)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const defaultOccUserConfig: OccConfig = {
addressVerification: 'users/${userId}/addresses/verification',
customerCoupons: 'users/${userId}/customercoupons',
claimCoupon: 'users/${userId}/customercoupons/${couponCode}/claim',
claimCustomerCoupon: 'users/${userId}/customercoupons/claim',
couponNotification:
'users/${userId}/customercoupons/${couponCode}/notification',
notificationPreference: 'users/${userId}/notificationpreferences',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,45 @@ describe('OccCustomerCouponAdapter', () => {
mockReq.flush(customerCoupon2Customer);
});
});
describe('claim customer coupon with code in body', () => {
it('should claim a customer coupon with code in request body for a given user id', () => {
const customerCoupon: CustomerCoupon = {
couponId: couponCode,
name: 'coupon 1',
startDate: '',
endDate: '',
status: 'Effective',
description: '',
notificationOn: true,
};
const customerCoupon2Customer: CustomerCoupon2Customer = {
coupon: customerCoupon,
customer: {},
};

occCustomerCouponAdapter
.claimCustomerCouponWithCodeInBody(userId, couponCode)
.subscribe((result) => {
expect(result).toEqual(customerCoupon2Customer);
});

const mockReq = httpMock.expectOne((req) => {
return req.method === 'POST';
});

expect(occEnpointsService.buildUrl).toHaveBeenCalledWith(
'claimCustomerCoupon',
{
urlParams: {
userId: userId,
},
}
);

expect(mockReq.cancelled).toBeFalsy();
expect(mockReq.request.body).toEqual({ couponCode: couponCode });
expect(mockReq.request.responseType).toEqual('json');
mockReq.flush(customerCoupon2Customer);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ export class OccCustomerCouponAdapter implements CustomerCouponAdapter {

return this.http.post(url, { headers });
}
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
claimCustomerCouponWithCodeInBody(
userId: string,
codeVal: string
): Observable<CustomerCoupon2Customer> {
const url = this.occEndpoints.buildUrl('claimCustomerCoupon', {
urlParams: { userId },
});
const toClaim = {
couponCode: codeVal,
};
const headers = this.newHttpHeader();

return this.http.post(url, toClaim, { headers });
}

claimCustomerCoupon(
userId: string,
Expand Down
6 changes: 6 additions & 0 deletions projects/core/src/occ/occ-models/occ-endpoints.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ export interface OccEndpoints {
* @member {string}
*/
claimCoupon?: string | OccEndpoint;
/**
* Endpoint for claiming coupon with code in request body
*
* @member {string}
*/
claimCustomerCoupon?: string | OccEndpoint;
/**
* Endpoint for coupons
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export abstract class CustomerCouponAdapter {
couponCode: string
): Observable<{}>;

abstract claimCustomerCouponWithCodeInBody(
userId: string,
couponVal: string
): Observable<CustomerCoupon2Customer>;

abstract claimCustomerCoupon(
userId: string,
couponCode: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class MockUserAdapter implements CustomerCouponAdapter {
claimCustomerCoupon = createSpy('claimCustomerCoupon').and.callFake(
(userId) => of(`claim-${userId}`)
);
claimCustomerCouponWithCodeInBody = createSpy(
'claimCustomerCouponWithCodeInBody'
).and.callFake((userId) => of(`claim-${userId}`));
disclaimCustomerCoupon = createSpy('disclaimCustomerCoupon').and.callFake(
(userId) => of(`disclaim-${userId}`)
);
Expand Down Expand Up @@ -89,7 +92,7 @@ describe('CustomerCouponConnector', () => {
.claimCustomerCoupon('userId', 'couponCode')
.subscribe((res) => (result = res));
expect(result).toEqual('claim-userId');
expect(adapter.claimCustomerCoupon).toHaveBeenCalledWith(
expect(adapter.claimCustomerCouponWithCodeInBody).toHaveBeenCalledWith(
'userId',
'couponCode'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class CustomerCouponConnector {
userId: string,
couponCode: string
): Observable<CustomerCoupon2Customer> {
return this.adapter.claimCustomerCoupon(userId, couponCode);
return this.adapter.claimCustomerCouponWithCodeInBody(userId, couponCode);
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
}

disclaimCustomerCoupon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ viewportContext(['mobile', 'desktop'], () => {
});
});

describe('My coupons - claim coupons with code in body using authenticated user', () => {
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(() => {
cy.window().then((win) => {
win.sessionStorage.clear();
});
cy.requireLoggedIn();
});
myCoupons.testClaimCustomerCouponWithCodeInBody();
});

describe('My coupons - Authenticated user', () => {
beforeEach(() => {
cy.window().then((win) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ export function verifyClaimCouponSuccess(couponCode: string) {
});
}

export function verifClaimCouponSuccessWithCodeInBody(couponCode: string) {
claimCouponWithCodeInBody(couponCode);
cy.location('pathname').should('contain', myCouponsUrl);
cy.get('.cx-coupon-card').within(() => {
cy.get('.cx-coupon-card-id').should('contain', couponCode);
});
}

export function verifyClaimCouponFail(couponCode: string) {
claimCoupon(couponCode);
cy.location('pathname').should('contain', myCouponsUrl);
Expand All @@ -78,6 +86,14 @@ export function verifyClaimCouponFail(couponCode: string) {
});
}

export function verifyClaimCouponFailWithCodeInBody(couponCode: string) {
claimCouponWithCodeInBody(couponCode);
cy.location('pathname').should('contain', myCouponsUrl);
cy.get('.cx-coupon-card').within(() => {
cy.get('.cx-coupon-card-id').should('not.contain', couponCode);
});
}

export function goMyCoupon() {
cy.visit('/my-account/coupons');
cy.get('.cx-coupon-card').should('have.length', 3);
Expand Down Expand Up @@ -115,6 +131,24 @@ export function claimCoupon(couponCode: string) {
cy.wait(`@${getCoupons}`);
}

export function claimCouponWithCodeInBody(couponCode: string) {
const claimCoupon = waitForClaimCouponWithCodeInBody(couponCode);
const getCoupons = waitForGetCoupons();
const couponsPage = waitForPage(myCouponsUrl, 'getCouponsPage');
cy.visit(myCouponsUrl + '#' + couponCode);

verifyClaimDialog();
cy.wait(`@${claimCoupon}`);

cy.wait(`@${couponsPage}`);
cy.wait(`@${getCoupons}`);
}

export function verifyResetClaimCouponCode(couponCode: string) {
cy.visit(myCouponsUrl + '#' + couponCode);
verifyResetByClickButton(couponCode);
}

export function createStandardUser() {
standardUser.registrationData.email = generateMail(randomString(), true);
cy.requireLoggedIn(standardUser);
Expand Down Expand Up @@ -174,6 +208,24 @@ export function verifyReadMore() {
cy.get('.cx-dialog-header span').click();
}

export function verifyClaimDialog() {
cy.get('cx-claim-dialog').should('exist');
cy.get('.cx-dialog-body .cx-dialog-row-submit-button .btn:first').click({
force: true,
});
}

export function verifyResetByClickButton(couponCode: string) {
cy.get('cx-claim-dialog').should('exist');
cy.get('.cx-dialog-body input').should('have.value', couponCode);
cy.get('[formcontrolname="couponCode"]').clear().type('resetTest');
cy.get('.cx-dialog-body input').should('have.value', 'resetTest');
cy.get('.cx-dialog-body .cx-dialog-row--reset-button .btn:first').click({
force: true,
});
cy.get('.cx-dialog-body input').should('have.value', couponCode);
}

export function verifyFindProduct(couponCode: string, productNumber: number) {
const productSearchPage = waitForPage('search', 'getProductSearchPage');

Expand Down Expand Up @@ -214,6 +266,15 @@ export function waitForGetCoupons(): string {
return `${aliasName}`;
}

export function waitForClaimCouponWithCodeInBody(couponCode: string): string {
const aliasName = `claimCouponInBody_${couponCode}`;
cy.intercept({
method: 'POST',
url: `${pageUrl}/users/current/customercoupons/claim*`,
}).as(aliasName);
return `${aliasName}`;
}

export function testClaimCustomerCoupon() {
describe('Claim customer coupon', () => {
it('should claim customer coupon successfully', () => {
Expand All @@ -227,3 +288,22 @@ export function testClaimCustomerCoupon() {
});
});
}

export function testClaimCustomerCouponWithCodeInBody() {
describe('Claim customer coupon with code in requestBody', () => {
it('should claim customer coupon successfully with code in requestBody', () => {
verifClaimCouponSuccessWithCodeInBody(validCouponCode);
cy.saveLocalStorage();
});

it('should not claim invalid customer coupon', () => {
cy.restoreLocalStorage();
verifyClaimCouponFailWithCodeInBody(invalidCouponCode);
});

it('should reset coupon code val after clicking reset button', () => {
cy.restoreLocalStorage();
verifyResetClaimCouponCode(validCouponCode);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<div
class="cx-coupon-dialog"
role="dialog"
[cxFocus]="focusConfig"
(esc)="close('Escape clicked')"
aria-labelledby="dialogTitle"
>
<div class="cx-coupon-container">
<!-- Modal Header -->

<div class="cx-dialog-header modal-header">
<h3
*cxFeature="'a11yDialogsHeading'"
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
id="dialogTitle"
class="cx-dialog-title modal-title"
>
{{ 'myCoupons.claimCoupondialogTitle' | cxTranslate }}
</h3>
<div
*cxFeature="'!a11yDialogsHeading'"
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
id="dialogTitle"
class="cx-dialog-title modal-title"
>
{{ 'myCoupons.claimCoupondialogTitle' | cxTranslate }}
</div>
<button
type="button"
class="close"
title="{{ 'common.close' | cxTranslate }}"
[attr.aria-label]="'common.close' | cxTranslate"
(click)="close('Cross click')"
>
<span aria-hidden="true">
<cx-icon [type]="iconTypes.CLOSE"></cx-icon>
</span>
</button>
</div>
<!-- Modal Body -->
<div class="cx-dialog-body modal-body">
<form (ngSubmit)="onSubmit()" [formGroup]="form" class="cx-dialog-item">
<label>
<span class="label-content"
>{{ 'myCoupons.claimCouponCode.label' | cxTranslate }}
<ng-template [ngTemplateOutlet]="requiredAsterisk"></ng-template
></span>
<input
required="true"
type="text"
name="couponCode"
formControlName="couponCode"
placeholder="{{
'myCoupons.claimCouponCode.placeholder' | cxTranslate
}}"
class="form-control"
/>

<!-- TODO: (CXSPA-7315) Remove feature toggle in the next major -->
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
<cx-form-errors
*cxFeature="'formErrorsDescriptiveMessages'"
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
[translationParams]="{
label: 'myCoupons.claimCouponCode.label' | cxTranslate,
}"
[control]="form.get('couponCode')"
></cx-form-errors>
<cx-form-errors
*cxFeature="'!formErrorsDescriptiveMessages'"
[control]="form.get('couponCode')"
></cx-form-errors>
</label>
<div class="cx-dialog-row">
<div class="col-md-6 cx-dialog-row--reset-button">
<a
role="button"
class="btn btn-block btn-secondary"
(click)="cancelEdit()"
>
{{ 'myCoupons.reset' | cxTranslate }}
</a>
</div>
<div class="col-md-6 cx-dialog-row-submit-button">
<button
class="btn btn-block btn-primary"
[disabled]="form.disabled"
>
{{ 'myCoupons.claim' | cxTranslate }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>

<ng-template #requiredAsterisk>
<abbr
*cxFeature="'a11yRequiredAsterisks'"
crisli001 marked this conversation as resolved.
Show resolved Hide resolved
aria-hidden="true"
class="text-decoration-none"
title="{{ 'common.required' | cxTranslate }}"
>*</abbr
>
</ng-template>
Loading
Loading