forked from SAP/spartacus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: CXSPA-8645
- Loading branch information
Showing
514 changed files
with
27,432 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
feature-libs/cart/base/core/connectors/access-code/cart-access-code.adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <spartacus-team@sap.com> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Observable } from 'rxjs'; | ||
|
||
export abstract class CartAccessCodeAdapter { | ||
/** | ||
* Abstract method used to generate access code for a specific cart id. | ||
* | ||
* @param {string} userId | ||
* @param {string} cartId | ||
* | ||
*/ | ||
abstract getCartAccessCode( | ||
userId: string, | ||
cartId: string | ||
): Observable<string | undefined>; | ||
} |
39 changes: 39 additions & 0 deletions
39
feature-libs/cart/base/core/connectors/access-code/cart-access-code.connector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { of } from 'rxjs'; | ||
import { take } from 'rxjs/operators'; | ||
import { CartAccessCodeAdapter } from './cart-access-code.adapter'; | ||
import { CartAccessCodeConnector } from './cart-access-code.connector'; | ||
import createSpy = jasmine.createSpy; | ||
|
||
class MockCartAccessCodeAdapter implements CartAccessCodeAdapter { | ||
getCartAccessCode = createSpy().and.returnValue(of({})); | ||
} | ||
|
||
describe('CartAccessCodeConnector', () => { | ||
let service: CartAccessCodeConnector; | ||
let adapter: CartAccessCodeAdapter; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
CartAccessCodeConnector, | ||
{ | ||
provide: CartAccessCodeAdapter, | ||
useClass: MockCartAccessCodeAdapter, | ||
}, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(CartAccessCodeConnector); | ||
adapter = TestBed.inject(CartAccessCodeAdapter); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should call adapter', () => { | ||
service.getCartAccessCode('user1', 'cart1').pipe(take(1)).subscribe(); | ||
expect(adapter.getCartAccessCode).toHaveBeenCalledWith('user1', 'cart1'); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
feature-libs/cart/base/core/connectors/access-code/cart-access-code.connector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <spartacus-team@sap.com> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Injectable, inject } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { CartAccessCodeAdapter } from './cart-access-code.adapter'; | ||
|
||
@Injectable() | ||
export class CartAccessCodeConnector { | ||
protected adapter = inject(CartAccessCodeAdapter); | ||
|
||
public getCartAccessCode( | ||
userId: string, | ||
cartId: string | ||
): Observable<string | undefined> { | ||
return this.adapter.getCartAccessCode(userId, cartId); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
feature-libs/cart/base/core/connectors/access-code/converters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <spartacus-team@sap.com> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { InjectionToken } from '@angular/core'; | ||
import { Converter } from '@spartacus/core'; | ||
|
||
export const CART_ACCESS_CODE_NORMALIZER = new InjectionToken< | ||
Converter<any, string> | ||
>('CartAccessCodeNormalizer'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <spartacus-team@sap.com> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './cart-access-code.adapter'; | ||
export * from './cart-access-code.connector'; | ||
export * from './converters'; |
38 changes: 38 additions & 0 deletions
38
feature-libs/cart/base/core/connectors/guest-user/cart-guest-user.adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <spartacus-team@sap.com> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { CartGuestUser } from '@spartacus/cart/base/root'; | ||
import { Observable } from 'rxjs'; | ||
|
||
export abstract class CartGuestUserAdapter { | ||
/** | ||
* Abstract method used to create a guest user, and assigns the user to the cart. | ||
* | ||
* @param {string} userId | ||
* @param {string} cartId | ||
* @param {CartGuestUser} guestUserDetails | ||
* | ||
*/ | ||
abstract createCartGuestUser( | ||
userId: string, | ||
cartId: string, | ||
guestUserDetails?: CartGuestUser | ||
): Observable<CartGuestUser>; | ||
|
||
/** | ||
* Abstract method used to update a guest user, and assigns the user to the cart. | ||
* | ||
* @param {string} userId | ||
* @param {string} cartId | ||
* @param {CartGuestUser} guestUserDetails | ||
* | ||
*/ | ||
abstract updateCartGuestUser( | ||
userId: string, | ||
cartId: string, | ||
guestUserDetails: CartGuestUser | ||
): Observable<CartGuestUser>; | ||
} |
Oops, something went wrong.