diff --git a/frontend/app/components/api/api-v3/hal-request/hal-request.service.test.ts b/frontend/app/components/api/api-v3/hal-request/hal-request.service.test.ts index 83056fcebe..90e0b4147d 100644 --- a/frontend/app/components/api/api-v3/hal-request/hal-request.service.test.ts +++ b/frontend/app/components/api/api-v3/hal-request/hal-request.service.test.ts @@ -29,10 +29,13 @@ import {opApiModule} from '../../../../angular-modules'; import {HalRequestService} from './hal-request.service'; import {HalResource} from '../hal-resources/hal-resource.service'; +import IPromise = angular.IPromise; +import IRootScopeService = angular.IRootScopeService; +import IHttpBackendService = angular.IHttpBackendService; describe('halRequest service', () => { - var $httpBackend:ng.IHttpBackendService; - var $rootScope:ng.IRootScopeService; + var $httpBackend:IHttpBackendService; + var $rootScope:IRootScopeService; var halRequest:HalRequestService; beforeEach(angular.mock.module(opApiModule.name)); @@ -46,9 +49,11 @@ describe('halRequest service', () => { describe('when requesting data', () => { var resource:HalResource; - var promise:ng.IPromise; + var promise:IPromise; var method:string; var data:any; + var headers = {Accept: 'foo'}; + const methods = ['get', 'put', 'post', 'patch', 'delete']; const runExpectations = () => { it('should return a HalResource', () => { @@ -56,7 +61,11 @@ describe('halRequest service', () => { }); }; const respond = status => { - $httpBackend.expect(method.toUpperCase(), 'href', data).respond(status, {}); + $httpBackend.expect(method.toUpperCase(), 'href', data, (headers:any) => { + return headers.Accept === 'foo'; + }) + .respond(status, {}); + promise .then(res => resource = res) .catch(res => resource = res); @@ -91,13 +100,13 @@ describe('halRequest service', () => { describe('when calling the http methods of the service', () => { runRequests(() => { - promise = halRequest[method]('href', data); + promise = halRequest[method]('href', data, headers); }); }); describe('when calling request()', () => { runRequests(() => { - promise = halRequest.request(method, 'href', data); + promise = halRequest.request(method, 'href', data, headers); }); }); diff --git a/frontend/app/components/api/api-v3/hal-request/hal-request.service.ts b/frontend/app/components/api/api-v3/hal-request/hal-request.service.ts index 5a7387ff58..b9ebe3710c 100644 --- a/frontend/app/components/api/api-v3/hal-request/hal-request.service.ts +++ b/frontend/app/components/api/api-v3/hal-request/hal-request.service.ts @@ -29,6 +29,7 @@ import {opApiModule} from '../../../../angular-modules'; import {HalResource} from '../hal-resources/hal-resource.service'; import {HalResourceFactoryService} from '../hal-resource-factory/hal-resource-factory.service'; +import IPromise = angular.IPromise; export class HalRequestService { constructor(protected $q:ng.IQService, @@ -42,14 +43,15 @@ export class HalRequestService { * @param method * @param href * @param data + * @param headers * @returns {IPromise} */ - public request(method:string, href:string, data?:any):ng.IPromise { + public request(method:string, href:string, data?:any, headers:any = {}):IPromise { if (!href) { return this.$q.when(null); } - const config:any = {method: method, url: href, data: data}; + const config:any = {method: method, url: href, data: data, headers: headers}; const createResource = response => this.halResourceFactory.createHalResource(response.data); @@ -66,20 +68,22 @@ export class HalRequestService { * * @param href * @param params + * @param headers * @returns {ng.IPromise} */ - public get(href:string, params?:any):ng.IPromise { - return this.request('get', href, params); + public get(href:string, params?:any, headers?:any):IPromise { + return this.request('get', href, params, headers); } /** * Perform a PUT request and return a resource promise. * @param href * @param data + * @param headers * @returns {ng.IPromise} */ - public put(href:string, data?:any):ng.IPromise { - return this.request('put', href, data); + public put(href:string, data?:any, headers?:any):IPromise { + return this.request('put', href, data, headers); } /** @@ -87,10 +91,11 @@ export class HalRequestService { * * @param href * @param data + * @param headers * @returns {ng.IPromise} */ - public post(href:string, data?:any):ng.IPromise { - return this.request('post', href, data); + public post(href:string, data?:any, headers?:any):IPromise { + return this.request('post', href, data, headers); } /** @@ -98,10 +103,11 @@ export class HalRequestService { * * @param href * @param data + * @param headers * @returns {ng.IPromise} */ - public patch(href:string, data?:any):ng.IPromise { - return this.request('patch', href, data); + public patch(href:string, data?:any, headers?:any):IPromise { + return this.request('patch', href, data, headers); } /** @@ -109,10 +115,11 @@ export class HalRequestService { * * @param href * @param data + * @param headers * @returns {ng.IPromise} */ - public delete(href:string, data?:any):ng.IPromise { - return this.request('delete', href, data); + public delete(href:string, data?:any, headers?:any):IPromise { + return this.request('delete', href, data, headers); } }