More tests for HttpServer

This commit is contained in:
ziajka 2018-03-21 11:41:53 +01:00
parent b4e2b38585
commit 0cc1cd8db1

View File

@ -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');
});
});