From 0cc1cd8db1e76319bd16d0d43391def615ee6bce Mon Sep 17 00:00:00 2001 From: ziajka Date: Wed, 21 Mar 2018 11:41:53 +0100 Subject: [PATCH] More tests for HttpServer --- .../services/http-server.service.spec.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/app/shared/services/http-server.service.spec.ts b/src/app/shared/services/http-server.service.spec.ts index 90cbeb7c..1950af56 100644 --- a/src/app/shared/services/http-server.service.spec.ts +++ b/src/app/shared/services/http-server.service.spec.ts @@ -52,6 +52,19 @@ describe('HttpServer', () => { expect(req.request.responseType).toEqual("text"); }); + it('should make GET query for getText method and preserve options', () => { + service.getText(server, '/test', { + headers: { + 'CustomHeader': 'value' + }, + responseType: 'text' + }).subscribe(); + + const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/test'); + expect(req.request.method).toEqual("GET"); + expect(req.request.responseType).toEqual("text"); + }); + it('should make POST query for post method', () => { service.post(server, '/test', {test: "1"}).subscribe(); @@ -112,4 +125,22 @@ describe('HttpServer', () => { expect(req.request.responseType).toEqual("json"); expect(req.request.headers.get('Authorization')).toEqual('Basic bG9naW46cGFzc3dvcmQ='); }); + + it('should add headers for `basic` authorization and preserve headers', () => { + server.authorization = "basic"; + server.login = "login"; + server.password = "password"; + + service.get(server, '/test', { + headers: { + 'CustomHeader': 'value' + } + }).subscribe(); + + const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/test'); + expect(req.request.method).toEqual("GET"); + expect(req.request.responseType).toEqual("json"); + expect(req.request.headers.get('Authorization')).toEqual('Basic bG9naW46cGFzc3dvcmQ='); + expect(req.request.headers.get('CustomHeader')).toEqual('value'); + }); });