Skip to content

Commit

Permalink
CXSPA-8201: Fix name issue
Browse files Browse the repository at this point in the history
  • Loading branch information
scarai-sap committed Aug 21, 2024
1 parent b135aec commit c1ab175
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { UserSignUp } from '@spartacus/user/profile/root';
import { OccUserProfileAdapter } from './occ-user-profile.adapter';
import { Observable, of } from 'rxjs';
import { CaptchaApiConfig, CaptchaRender } from '@spartacus/storefront';
import { CaptchaApiConfig, CaptchaRenderer } from '@spartacus/storefront';

export const mockOccModuleConfig: OccConfig = {
backend: {
Expand Down Expand Up @@ -68,7 +68,7 @@ const user: User = {
};

const mockToken = 'mock-token';
class MockCaptchaService implements CaptchaRender {
class MockCaptchaService implements CaptchaRenderer {
getCaptchaConfig(): Observable<CaptchaConfig> {
return of({
enabled: true,
Expand All @@ -88,7 +88,7 @@ class MockCaptchaService implements CaptchaRender {
const mockCaptchaApiConfig: CaptchaApiConfig = {
apiUrl: 'mock-url',
fields: { 'mock-field-key': 'mock-field-value' },
captchaRender: MockCaptchaService,
captchaRenderer: MockCaptchaService,
};

describe('OccUserProfileAdapter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { Title, UserSignUp } from '@spartacus/user/profile/root';
import { Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { CaptchaApiConfig, CaptchaRender } from '@spartacus/storefront';
import { CaptchaApiConfig, CaptchaRenderer } from '@spartacus/storefront';

const CONTENT_TYPE_JSON_HEADER = { 'Content-Type': 'application/json' };
const CONTENT_TYPE_URLENCODED_HEADER = {
Expand Down Expand Up @@ -185,9 +185,9 @@ export class OccUserProfileAdapter implements UserProfileAdapter {
}

protected appendCaptchaToken(currentHeaders: HttpHeaders): HttpHeaders {
if (this.injector && this.captchaConfig?.captchaRender) {
const provider = this.injector.get<CaptchaRender>(
this.captchaConfig.captchaRender
if (this.injector && this.captchaConfig?.captchaRenderer) {
const provider = this.injector.get<CaptchaRenderer>(
this.captchaConfig.captchaRenderer
);
const isCaptchaEnabled = provider
.getCaptchaConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Injectable, Type } from '@angular/core';
import { Config } from '@spartacus/core';
import { CaptchaRender } from './captcha.render';
import { CaptchaRenderer } from './captcha.renderer';

@Injectable({
providedIn: 'root',
Expand All @@ -18,13 +18,13 @@ import { CaptchaRender } from './captcha.render';
* Configuration for the frontend: This class defines how to render the captcha component
* and obtain the appropriate token.
*
* @property {Type<CaptchaRender>} - An implementation of the CaptchaRender
* @property {Type<CaptchaRenderer>} - An implementation of the CaptchaRenderer
* interface that renders the UI and interacts with the user.
* @property {string} [apiUrl] - An optional parameter specifying the API endpoint for captcha validation.
* @property {Object} [fields] - An optional parameter that holds additional fields needed for the captcha configuration.
*/
export abstract class CaptchaApiConfig {
captchaRender?: Type<CaptchaRender>;
captchaRenderer?: Type<CaptchaRenderer>;
apiUrl?: string;
fields?: { [key: string]: string };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Observable, of } from 'rxjs';
import { CaptchaConfig } from '@spartacus/core';
import { CaptchaComponent, CaptchaRender } from '@spartacus/storefront';
import { CaptchaComponent, CaptchaRenderer } from '@spartacus/storefront';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { CaptchaApiConfig } from './captcha-api-config';

class MockCaptchaService implements CaptchaRender {
class MockCaptchaService implements CaptchaRenderer {
getCaptchaConfig(): Observable<CaptchaConfig> {
return of({
enabled: true,
Expand All @@ -24,13 +24,13 @@ class MockCaptchaService implements CaptchaRender {
const mockCaptchaApiConfig: CaptchaApiConfig = {
apiUrl: 'mock-url',
fields: { 'mock-field-key': 'mock-field-value' },
captchaRender: MockCaptchaService,
captchaRenderer: MockCaptchaService,
};

describe('Captcha Component', () => {
let component: CaptchaComponent;
let fixture: ComponentFixture<CaptchaComponent>;
let service: CaptchaRender;
let service: CaptchaRenderer;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { of, Subscription } from 'rxjs';
import { concatMap } from 'rxjs/operators';

import { CaptchaApiConfig } from './captcha-api-config';
import { CaptchaRender } from './captcha.render';
import { CaptchaRenderer } from './captcha.renderer';

@Component({
selector: 'cx-captcha',
Expand All @@ -45,17 +45,17 @@ export class CaptchaComponent implements AfterViewInit, OnDestroy {
* config.
*/
ngAfterViewInit(): void {
if (this.config?.captchaRender) {
const captchaRender = this.injector.get<CaptchaRender>(
this.config.captchaRender
if (this.config?.captchaRenderer) {
const captchaRenderer = this.injector.get<CaptchaRenderer>(
this.config.captchaRenderer
);
this.subscription.add(
captchaRender
captchaRenderer
.getCaptchaConfig()
.pipe(
concatMap((captchaConfig) => {
if (captchaConfig?.enabled) {
return captchaRender.renderCaptcha({
return captchaRenderer.renderCaptcha({
element: this.captchaRef.nativeElement,
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Observable } from 'rxjs';
import { RenderParams } from './captcha.model';
import { CaptchaConfig } from '@spartacus/core';

export interface CaptchaRender {
export interface CaptchaRenderer {
/**
* Renders captcha widget
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { forkJoin, map, Observable, ReplaySubject, Subscription } from 'rxjs';
import { concatMap, take } from 'rxjs/operators';
import { RenderParams } from './captcha.model';
import { CaptchaApiConfig } from './captcha-api-config';
import { CaptchaRender } from './captcha.render';
import { CaptchaRenderer } from './captcha.renderer';

/**
* Global function to be passes as "onload" url param for captcha <script>, to be
Expand All @@ -32,7 +32,7 @@ declare global {
@Injectable({
providedIn: 'root',
})
export abstract class CaptchaService implements CaptchaRender, OnDestroy {
export abstract class CaptchaService implements CaptchaRenderer, OnDestroy {
protected token: string;
protected subscription = new Subscription();
protected captchaConfigSubject$ = new ReplaySubject<CaptchaConfig>(1);
Expand Down
2 changes: 1 addition & 1 deletion projects/storefrontlib/shared/components/captcha/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export * from './captcha.component';
export * from './captcha.module';
export * from './captcha.model';
export * from './captcha-api-config';
export * from './captcha.render';
export * from './captcha.renderer';
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import { MockCaptchaService } from '../mock-captcha.service';
import { CaptchaApiConfig } from '../../captcha-api-config';

export const MockCaptchaApiConfig: CaptchaApiConfig = {
captchaRender: MockCaptchaService,
captchaRenderer: MockCaptchaService,
};

0 comments on commit c1ab175

Please sign in to comment.