diff --git a/src/app/core/auth/browser-auth-request.service.spec.ts b/src/app/core/auth/browser-auth-request.service.spec.ts index 2875553feb..b41d981bcf 100644 --- a/src/app/core/auth/browser-auth-request.service.spec.ts +++ b/src/app/core/auth/browser-auth-request.service.spec.ts @@ -18,17 +18,19 @@ describe(`BrowserAuthRequestService`, () => { }); describe(`createShortLivedTokenRequest`, () => { - it(`should return a PostRequest`, () => { + it(`should return a PostRequest`, (done) => { const obs = (service as any).createShortLivedTokenRequest(href) as Observable; obs.subscribe((result: PostRequest) => { expect(result.constructor.name).toBe('PostRequest'); + done(); }); }); - it(`should return a request with the given href`, () => { + it(`should return a request with the given href`, (done) => { const obs = (service as any).createShortLivedTokenRequest(href) as Observable; obs.subscribe((result: PostRequest) => { expect(result.href).toBe(href); + done(); }); }); }); diff --git a/src/app/core/auth/server-auth-request.service.spec.ts b/src/app/core/auth/server-auth-request.service.spec.ts index 181603eef7..df6d78256b 100644 --- a/src/app/core/auth/server-auth-request.service.spec.ts +++ b/src/app/core/auth/server-auth-request.service.spec.ts @@ -3,9 +3,12 @@ import { RequestService } from '../data/request.service'; import { ServerAuthRequestService } from './server-auth-request.service'; import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http'; import { Observable, of as observableOf } from 'rxjs'; -import { XSRF_RESPONSE_HEADER } from '../xsrf/xsrf.interceptor'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { PostRequest } from '../data/request.models'; +import { + XSRF_REQUEST_HEADER, + XSRF_RESPONSE_HEADER +} from '../xsrf/xsrf.interceptor'; describe(`ServerAuthRequestService`, () => { let href: string; @@ -21,9 +24,11 @@ describe(`ServerAuthRequestService`, () => { requestService = jasmine.createSpyObj('requestService', { 'generateRequestId': '8bb0582d-5013-4337-af9c-763beb25aae2' }); + let headers = new HttpHeaders(); + headers = headers.set(XSRF_RESPONSE_HEADER, mockToken); httpResponse = { body: { bar: false }, - headers: new HttpHeaders({ XSRF_RESPONSE_HEADER: mockToken }), + headers: headers, statusText: '200' } as HttpResponse; httpClient = jasmine.createSpyObj('httpClient', { @@ -36,24 +41,27 @@ describe(`ServerAuthRequestService`, () => { }); describe(`createShortLivedTokenRequest`, () => { - it(`should return a PostRequest`, () => { + it(`should return a PostRequest`, (done) => { const obs = (service as any).createShortLivedTokenRequest(href) as Observable; obs.subscribe((result: PostRequest) => { expect(result.constructor.name).toBe('PostRequest'); + done(); }); }); - it(`should return a request with the given href`, () => { + it(`should return a request with the given href`, (done) => { const obs = (service as any).createShortLivedTokenRequest(href) as Observable; obs.subscribe((result: PostRequest) => { - expect(result.href).toBe(href) ; + expect(result.href).toBe(href); + done(); }); }); - it(`should return a request with a xsrf header`, () => { + it(`should return a request with a xsrf header`, (done) => { const obs = (service as any).createShortLivedTokenRequest(href) as Observable; obs.subscribe((result: PostRequest) => { - expect(result.options.headers.get(XSRF_RESPONSE_HEADER)).toBe(mockToken); + expect(result.options.headers.get(XSRF_REQUEST_HEADER)).toBe(mockToken); + done(); }); }); }); diff --git a/src/app/core/auth/server-auth-request.service.ts b/src/app/core/auth/server-auth-request.service.ts index 183e085589..d6302081bc 100644 --- a/src/app/core/auth/server-auth-request.service.ts +++ b/src/app/core/auth/server-auth-request.service.ts @@ -52,14 +52,14 @@ export class ServerAuthRequestService extends AuthRequestService { .set('Cookie', `${DSPACE_XSRF_COOKIE}=${xsrfToken}`)), map((headers: HttpHeaders) => // Create a new PostRequest using those headers and the given href - Object.assign(new PostRequest( + new PostRequest( this.requestService.generateRequestId(), href, {}, { headers: headers, }, - ),{}) + ) ) ); }