From 40fb040d9b6a339978bd8dcef7811944bc94c47b Mon Sep 17 00:00:00 2001 From: gaurav patel <100828173+GauravD2t@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:14:26 +0530 Subject: [PATCH] Added TEST cases Updated test cases which are previously fail due to added captcha to request a copy --- src/app/core/data/item-request-data.service.spec.ts | 7 ++++++- .../bitstream-request-a-copy-page.component.spec.ts | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/core/data/item-request-data.service.spec.ts b/src/app/core/data/item-request-data.service.spec.ts index a5d18725109..0e0d9a1063a 100644 --- a/src/app/core/data/item-request-data.service.spec.ts +++ b/src/app/core/data/item-request-data.service.spec.ts @@ -8,6 +8,8 @@ import { ItemRequest } from '../shared/item-request.model'; import { PostRequest } from './request.models'; import { RequestCopyEmail } from '../../request-copy/email-request-copy/request-copy-email.model'; import { RestRequestMethod } from './rest-request-method'; +import { HttpHeaders } from '@angular/common/http'; +import { HttpOptions } from '../dspace-rest/dspace-rest.service'; describe('ItemRequestDataService', () => { let service: ItemRequestDataService; @@ -40,8 +42,11 @@ describe('ItemRequestDataService', () => { describe('requestACopy', () => { it('should send a POST request containing the provided item request', (done) => { + let headers = new HttpHeaders(); + const options: HttpOptions = Object.create({}); + options.headers = headers; service.requestACopy(itemRequest).subscribe(() => { - expect(requestService.send).toHaveBeenCalledWith(new PostRequest(requestId, restApiEndpoint, itemRequest)); + expect(requestService.send).toHaveBeenCalledWith(new PostRequest(requestId, restApiEndpoint, itemRequest,options)); done(); }); }); diff --git a/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.spec.ts b/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.spec.ts index de54872f499..069860ec0f2 100644 --- a/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.spec.ts +++ b/src/app/item-page/bitstreams/request-a-copy/bitstream-request-a-copy-page.component.spec.ts @@ -254,7 +254,7 @@ describe('BitstreamRequestACopyPageComponent', () => { component.email.patchValue('user@name.org'); component.allfiles.patchValue('false'); component.message.patchValue('I would like to request a copy'); - + component.captchaToken = 'googleRecaptchaToken'; component.onSubmit(); const itemRequest = Object.assign(new ItemRequest(), { @@ -266,7 +266,7 @@ describe('BitstreamRequestACopyPageComponent', () => { requestMessage: 'I would like to request a copy' }); - expect(itemRequestDataService.requestACopy).toHaveBeenCalledWith(itemRequest); + expect(itemRequestDataService.requestACopy).toHaveBeenCalledWith(itemRequest,component.captchaToken); expect(notificationsService.success).toHaveBeenCalled(); expect(location.back).toHaveBeenCalled(); }); @@ -288,6 +288,7 @@ describe('BitstreamRequestACopyPageComponent', () => { component.email.patchValue('user@name.org'); component.allfiles.patchValue('false'); component.message.patchValue('I would like to request a copy'); + component.captchaToken = 'googleRecaptchaToken'; component.onSubmit(); const itemRequest = Object.assign(new ItemRequest(), @@ -300,7 +301,7 @@ describe('BitstreamRequestACopyPageComponent', () => { requestMessage: 'I would like to request a copy' }); - expect(itemRequestDataService.requestACopy).toHaveBeenCalledWith(itemRequest); + expect(itemRequestDataService.requestACopy).toHaveBeenCalledWith(itemRequest,component.captchaToken); expect(notificationsService.error).toHaveBeenCalled(); expect(location.back).not.toHaveBeenCalled(); });