Skip to content

Commit

Permalink
Added TEST cases
Browse files Browse the repository at this point in the history
Updated test cases which are previously fail due to added captcha to request a copy
  • Loading branch information
GauravD2t committed Dec 20, 2023
1 parent b9cc9e1 commit 40fb040
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/app/core/data/item-request-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('BitstreamRequestACopyPageComponent', () => {
component.email.patchValue('[email protected]');
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(),
{
Expand All @@ -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();
});
Expand All @@ -288,6 +288,7 @@ describe('BitstreamRequestACopyPageComponent', () => {
component.email.patchValue('[email protected]');
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(),
Expand All @@ -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();
});
Expand Down

0 comments on commit 40fb040

Please sign in to comment.