[UXP-10] typdocs and tests

This commit is contained in:
Sufiyan Shaikh
2022-06-14 20:53:20 +05:30
committed by Sufiyan Shaikh
parent 0783cd5cb6
commit 4906516359
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { GoogleRecaptchaService } from './google-recaptcha.service';
import { of as observableOf } from 'rxjs';
describe('GoogleRecaptchaService', () => {
let service: GoogleRecaptchaService;
let reCaptchaV3Service;
function init() {
reCaptchaV3Service = jasmine.createSpyObj('reCaptchaV3Service', {
execute: observableOf('googleRecaptchaToken')
});
service = new GoogleRecaptchaService(reCaptchaV3Service);
}
beforeEach(() => {
init();
});
describe('getRecaptchaToken', () => {
let result;
beforeEach(() => {
result = service.getRecaptchaToken('test');
});
it('should send a Request with action', () => {
expect(reCaptchaV3Service.execute).toHaveBeenCalledWith('test');
});
});
});

View File

@@ -1,6 +1,9 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ReCaptchaV3Service } from 'ng-recaptcha'; import { ReCaptchaV3Service } from 'ng-recaptcha';
/**
* A GoogleRecaptchaService used to send action and get a token from REST
*/
@Injectable() @Injectable()
export class GoogleRecaptchaService { export class GoogleRecaptchaService {
@@ -8,6 +11,10 @@ export class GoogleRecaptchaService {
private recaptchaV3Service: ReCaptchaV3Service private recaptchaV3Service: ReCaptchaV3Service
) {} ) {}
/**
* Returns an observable of string
* @param action action is the process type in which used to protect multiple spam REST calls
*/
public getRecaptchaToken (action) { public getRecaptchaToken (action) {
return this.recaptchaV3Service.execute(action); return this.recaptchaV3Service.execute(action);
} }