Skip to content

Commit

Permalink
Merge branch 'feature/cxspa-640' of https://github.com/SAP/spartacus
Browse files Browse the repository at this point in the history
…into feature/cxspa-640
  • Loading branch information
WeizhengSap committed Jun 27, 2022
2 parents e476b3f + b93a447 commit 33a0c19
Show file tree
Hide file tree
Showing 265 changed files with 2,177 additions and 1,977 deletions.
68 changes: 68 additions & 0 deletions docs/migration/5_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ The following keys have been added to `configurator-common.ts`:

- Component template modified, `input[attr.aria-label]="'common.search' | cxTranslate"` has been changed to `input[attr.aria-label]="'quickOrderForm.searchBoxLabel' | cxTranslate"`

- Styling for `cx-quick-order-form` dom element: deprecated class `search` was removed. Use `quick-order-form-search-icon` class instead.

### QuickOrderTableComponent

- Component template was modified to display native table instead of nested divs. The structure has been simplified and bootstrap classes has been removed.
Expand Down Expand Up @@ -615,6 +617,7 @@ If needed, type can be extended by module augmentation. For more details, see [E
### ComponentWrapperDirective

- `EventService` is now a new required constructor dependency.
- `cmfRef` has been made `protected` due to being unsafe.

### InnerComponentsHostDirective

Expand Down Expand Up @@ -703,6 +706,71 @@ Due to i18next migration, certain set of keys have been migrated (from `_plural`

- Template code for carousel item has been moved to a reusable component - `ProductCarouselItemComponent` Its selector is `<cx-product-carousel-item>`.

### KeyboardFocusModule

- `KeyboardFocusConfig` has been removed.
- `keyboardFocusFactory` had been removed.

### OnNavigateFocusService

- This service had been removed in favour of autoscroll fixes made to the `Router`.

### AsmMainUICmmponent

- Added `UserAccountFacade` to constructor.
- Removed `UserService` from constructor.

### CustomerEmulationComponent

- Added `UserAccountFacade` to constructor.
- Removed `UserService` from constructor.

### CxAgentAuthService

- Added `UserProfileFacade` to constructor.
- Removed `UserService` from constructor.

### SelectiveCartService

- Added `UserProfileFacade` to constructor.
- Removed `UserService` from constructor.

### SavedCartService

- Added `UserAccountFacade` to constructor.
- Removed `UserService` from constructor.

### WishListService

- Added `UserAccountFacade` to constructor.
- Removed `UserService` from constructor.

### UserFormComponent

- Added `UserProfileFacade` to constructor.
- Removed `UserService` from constructor.

### AdminGuard

- Added `UserAccountFacade` to constructor.
- Removed `UserService` from constructor.

### B2BUserEffects

- Added `UserAccountFacade` to constructor.
- Removed `UserService` from constructor.

### ApproverGuard

- Added `UserAccountFacade` to constructor.
- Removed `UserService` from constructor.

### OccEndpoints

- Endpoints `b2bUsers`, `b2bUser`, `b2bUserApprovers`, `b2bUserApprover`, `b2bUserUserGroups`, `b2bUserUserGroup`, `b2bUserPermissions`, `b2bUserPermission`, `budget`, `budgets`, `costCentersAll`, `costCenter`, `costCenters`, `costCenterBudgets`, `costCenterBudget`, `orgUnits`, `orgUnitsAvailable`, `orgUnitsTree`, `orgUnitsApprovalProcesses`, `orgUnit`, `orgUnitUsers`, `orgUnitUserRoles`, `orgUnitUserRole`, `orgUnitApprovers`, `orgUnitApprover`, `orgUnitsAddresses`, `orgUnitsAddress`, `permissions`, `permission`, `orderApprovalPermissionTypes`, `userGroups`, `userGroup`, `userGroupAvailableOrderApprovalPermissions`, `userGroupAvailableOrgCustomers`, `userGroupMembers`, `userGroupMember`, `userGroupOrderApprovalPermissions`, `userGroupOrderApprovalPermission` were removed from the declaration in `@spartacus/core`. Those endpoints are now provided with module augmentation from `@spartacus/organization/administration/occ`. Default values are also provided from this new entry point.
- Endpoints `orderApprovals`, `orderApproval`, `orderApprovalDecision`, were removed from the declaration in `@spartacus/core`. Those endpoints are now provided with module augmentation from `@spartacus/organization/order-approval/occ`. Default values are also provided from this new entry point.
- Endpoints `store`, `stores`, `storescounts`, were removed from the declaration in `@spartacus/core`. Those endpoints are now provided with module augmentation from `@spartacus/storefinder/occ`. Default values are also provided from this new entry point.

## Schematics

`Account` and `Profile` CLI names have been changed to `User-Account` and `User-Profile`, respectively, to better reflect their purpose.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
I18nTestingModule,
RoutingService,
User,
UserService,
} from '@spartacus/core';
import { UserAccountFacade } from '@spartacus/user/account/root';
import { Observable, of } from 'rxjs';
import { AsmComponentService } from '../services/asm-component.service';
import { AsmMainUiComponent } from './asm-main-ui.component';
Expand All @@ -40,7 +40,7 @@ class MockCsAgentAuthService implements Partial<CsAgentAuthService> {
startCustomerEmulationSession(_customerId: string) {}
}

class MockUserService implements Partial<UserService> {
class MockUserAccountFacade implements Partial<UserAccountFacade> {
get(): Observable<User> {
return of({});
}
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('AsmMainUiComponent', () => {
let fixture: ComponentFixture<AsmMainUiComponent>;
let authService: AuthService;
let csAgentAuthService: CsAgentAuthService;
let userService: UserService;
let userAccountFacade: UserAccountFacade;
let el: DebugElement;
let globalMessageService: GlobalMessageService;
let routingService: RoutingService;
Expand All @@ -136,7 +136,7 @@ describe('AsmMainUiComponent', () => {
providers: [
{ provide: AuthService, useClass: MockAuthService },
{ provide: CsAgentAuthService, useClass: MockCsAgentAuthService },
{ provide: UserService, useClass: MockUserService },
{ provide: UserAccountFacade, useClass: MockUserAccountFacade },
{ provide: GlobalMessageService, useClass: MockGlobalMessageService },
{ provide: RoutingService, useClass: MockRoutingService },
{ provide: AsmComponentService, useClass: MockAsmComponentService },
Expand All @@ -150,7 +150,7 @@ describe('AsmMainUiComponent', () => {
fixture = TestBed.createComponent(AsmMainUiComponent);
authService = TestBed.inject(AuthService);
csAgentAuthService = TestBed.inject(CsAgentAuthService);
userService = TestBed.inject(UserService);
userAccountFacade = TestBed.inject(UserAccountFacade);
globalMessageService = TestBed.inject(GlobalMessageService);
routingService = TestBed.inject(RoutingService);
asmComponentService = TestBed.inject(AsmComponentService);
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('AsmMainUiComponent', () => {
of(true)
);
spyOn(authService, 'isUserLoggedIn').and.returnValue(of(false));
spyOn(userService, 'get').and.returnValue(of({}));
spyOn(userAccountFacade, 'get').and.returnValue(of({}));
component.ngOnInit();
fixture.detectChanges();
expect(el.query(By.css('cx-csagent-login-form'))).toBeFalsy();
Expand All @@ -259,7 +259,7 @@ describe('AsmMainUiComponent', () => {
of(true)
);
spyOn(authService, 'isUserLoggedIn').and.returnValue(of(false));
spyOn(userService, 'get').and.returnValue(of({}));
spyOn(userAccountFacade, 'get').and.returnValue(of({}));
component.ngOnInit();
fixture.detectChanges();
expect(el.query(By.css('cx-csagent-login-form'))).toBeFalsy();
Expand All @@ -275,7 +275,7 @@ describe('AsmMainUiComponent', () => {
of(true)
);
spyOn(authService, 'isUserLoggedIn').and.returnValue(of(true));
spyOn(userService, 'get').and.returnValue(of(testUser));
spyOn(userAccountFacade, 'get').and.returnValue(of(testUser));
component.ngOnInit();
fixture.detectChanges();

Expand All @@ -293,7 +293,7 @@ describe('AsmMainUiComponent', () => {
of(true)
);
spyOn(authService, 'isUserLoggedIn').and.returnValue(of(true));
spyOn(userService, 'get').and.returnValue(of(testUser));
spyOn(userAccountFacade, 'get').and.returnValue(of(testUser));
component.ngOnInit();
fixture.detectChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
GlobalMessageType,
RoutingService,
User,
UserService,
} from '@spartacus/core';
import { UserAccountFacade } from '@spartacus/user/account/root';
import { Observable, of } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
import { AsmComponentService } from '../services/asm-component.service';
Expand All @@ -30,11 +30,11 @@ export class AsmMainUiComponent implements OnInit {
constructor(
protected authService: AuthService,
protected csAgentAuthService: CsAgentAuthService,
protected userService: UserService,
protected asmComponentService: AsmComponentService,
protected globalMessageService: GlobalMessageService,
protected routingService: RoutingService,
protected asmService: AsmService
protected asmService: AsmService,
protected userAccountFacade: UserAccountFacade
) {}

ngOnInit(): void {
Expand All @@ -46,7 +46,7 @@ export class AsmMainUiComponent implements OnInit {
switchMap((isLoggedIn) => {
if (isLoggedIn) {
this.handleCustomerSessionStartRedirection();
return this.userService.get();
return this.userAccountFacade.get();
} else {
return of(undefined);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { I18nTestingModule, User, UserService } from '@spartacus/core';
import { I18nTestingModule, User } from '@spartacus/core';
import { UserAccountFacade } from '@spartacus/user/account/root';

import { Observable, of } from 'rxjs';
import { AsmComponentService } from '../services/asm-component.service';
import { CustomerEmulationComponent } from './customer-emulation.component';

class MockUserService {
class MockUserAccountFacade implements Partial<UserAccountFacade> {
get(): Observable<User> {
return of({});
}
Expand All @@ -22,7 +24,7 @@ class MockAsmComponentService {
describe('CustomerEmulationComponent', () => {
let component: CustomerEmulationComponent;
let fixture: ComponentFixture<CustomerEmulationComponent>;
let userService: UserService;
let userAccountFacade: UserAccountFacade;
let asmComponentService: AsmComponentService;
let el: DebugElement;

Expand All @@ -32,7 +34,7 @@ describe('CustomerEmulationComponent', () => {
imports: [I18nTestingModule],
declarations: [CustomerEmulationComponent],
providers: [
{ provide: UserService, useClass: MockUserService },
{ provide: UserAccountFacade, useClass: MockUserAccountFacade },
{ provide: AsmComponentService, useClass: MockAsmComponentService },
],
}).compileComponents();
Expand All @@ -43,7 +45,7 @@ describe('CustomerEmulationComponent', () => {
fixture = TestBed.createComponent(CustomerEmulationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
userService = TestBed.inject(UserService);
userAccountFacade = TestBed.inject(UserAccountFacade);
asmComponentService = TestBed.inject(AsmComponentService);
el = fixture.debugElement;
});
Expand All @@ -54,7 +56,7 @@ describe('CustomerEmulationComponent', () => {

it('should display user info during customer emulation.', () => {
const testUser = { uid: 'user@test.com', name: 'Test User' } as User;
spyOn(userService, 'get').and.returnValue(of(testUser));
spyOn(userAccountFacade, 'get').and.returnValue(of(testUser));
component.ngOnInit();
fixture.detectChanges();

Expand All @@ -68,7 +70,7 @@ describe('CustomerEmulationComponent', () => {
it("should call logoutCustomer() on 'End Session' button click", () => {
//customer login
const testUser = { uid: 'user@test.com', name: 'Test User' } as User;
spyOn(userService, 'get').and.returnValue(of(testUser));
spyOn(userAccountFacade, 'get').and.returnValue(of(testUser));

component.ngOnInit();
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { User, UserService } from '@spartacus/core';
import { User } from '@spartacus/core';
import { UserAccountFacade } from '@spartacus/user/account/root';
import { Observable, Subscription } from 'rxjs';
import { AsmComponentService } from '../services/asm-component.service';

Expand All @@ -14,12 +15,12 @@ export class CustomerEmulationComponent implements OnInit, OnDestroy {

constructor(
protected asmComponentService: AsmComponentService,
protected userService: UserService
protected userAccountFacade: UserAccountFacade
) {}

ngOnInit() {
this.subscription.add(
this.userService.get().subscribe((user) => {
this.userAccountFacade.get().subscribe((user) => {
if (user) this.customer = user;
})
);
Expand Down
1 change: 1 addition & 0 deletions feature-libs/asm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@spartacus/core": "4.1.0-next.0",
"@spartacus/schematics": "4.1.0-next.0",
"@spartacus/storefront": "4.1.0-next.0",
"@spartacus/user": "4.1.0-next.0",
"rxjs": "^6.6.0"
},
"publishConfig": {
Expand Down
14 changes: 8 additions & 6 deletions feature-libs/asm/root/services/csagent-auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
OCC_USER_ID_ANONYMOUS,
OCC_USER_ID_CURRENT,
UserIdService,
UserService,
} from '@spartacus/core';
import { UserProfileFacade } from '@spartacus/user/profile/root';
import { TokenResponse } from 'angular-oauth2-oidc';
import { of } from 'rxjs';
import { take } from 'rxjs/operators';
Expand All @@ -34,7 +34,7 @@ class MockOAuthLibWrapperService implements Partial<OAuthLibWrapperService> {
}
}

class MockUserService implements Partial<UserService> {
class MockUserProfileFacade implements Partial<UserProfileFacade> {
get() {
return of({});
}
Expand All @@ -47,7 +47,7 @@ describe('CsAgentAuthService', () => {
let authService: AuthService;
let asmAuthStorageService: AsmAuthStorageService;
let oAuthLibWrapperService: OAuthLibWrapperService;
let userService: UserService;
let userProfileFacade: UserProfileFacade;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -63,7 +63,7 @@ describe('CsAgentAuthService', () => {
provide: OAuthLibWrapperService,
useClass: MockOAuthLibWrapperService,
},
{ provide: UserService, useClass: MockUserService },
{ provide: UserProfileFacade, useClass: MockUserProfileFacade },
],
});

Expand All @@ -72,7 +72,7 @@ describe('CsAgentAuthService', () => {
authService = TestBed.inject(AuthService);
asmAuthStorageService = TestBed.inject(AsmAuthStorageService);
oAuthLibWrapperService = TestBed.inject(OAuthLibWrapperService);
userService = TestBed.inject(UserService);
userProfileFacade = TestBed.inject(UserProfileFacade);
store = TestBed.inject(Store);
});

Expand Down Expand Up @@ -117,7 +117,9 @@ describe('CsAgentAuthService', () => {
).and.callThrough();
spyOn(userIdService, 'setUserId').and.callThrough();
spyOn(asmAuthStorageService, 'setEmulatedUserToken').and.callThrough();
spyOn(userService, 'get').and.returnValue(of({ customerId: 'custId' }));
spyOn(userProfileFacade, 'get').and.returnValue(
of({ customerId: 'custId' })
);
asmAuthStorageService.setToken({ access_token: 'token' } as AuthToken);

await service.authorizeCustomerSupportAgent('testUser', 'testPass');
Expand Down
7 changes: 4 additions & 3 deletions feature-libs/asm/root/services/csagent-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
OCC_USER_ID_ANONYMOUS,
OCC_USER_ID_CURRENT,
UserIdService,
UserService,
} from '@spartacus/core';

import { UserProfileFacade } from '@spartacus/user/profile/root';
import { combineLatest, Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { AsmAuthStorageService, TokenTarget } from './asm-auth-storage.service';
Expand All @@ -28,7 +29,7 @@ export class CsAgentAuthService {
protected userIdService: UserIdService,
protected oAuthLibWrapperService: OAuthLibWrapperService,
protected store: Store,
protected userService: UserService
protected userProfileFacade: UserProfileFacade
) {}

/**
Expand All @@ -54,7 +55,7 @@ export class CsAgentAuthService {
);
// Start emulation for currently logged in user
let customerId: string | undefined;
this.userService
this.userProfileFacade
.get()
.subscribe((user) => (customerId = user?.customerId))
.unsubscribe();
Expand Down
Loading

0 comments on commit 33a0c19

Please sign in to comment.