<commit_before>/* tslint:disable:no-unused-variable */

import { TestBed, async, inject } from '@angular/core/testing';
import { HttpClientService } from './http-client.service';
import { Http, RequestOptions, Headers, Response, ResponseOptions } from '@angular/http';
import { MockConnection, MockBackend } from '@angular/http/testing';

describe('HttpClientService', () => {
  let fixture: HttpClientService;
  let http: Http;
  let options: RequestOptions;
  let backend: MockBackend;
  let responseObject: any;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        HttpClientService
      ],
    });
    backend = new MockBackend();
    options = new RequestOptions();
    options.headers = new Headers();
    http = new Http(backend, options);
    fixture = new HttpClientService(http);
  });

  describe('get method', () => {
    responseObject = { 'test': 123 };
    let requestHeaders: Headers;
    let requestUrl: string;
    beforeEach(() => {
      backend.connections.subscribe((connection: MockConnection) => {
        requestHeaders = connection.request.headers;
        requestUrl = connection.request.url;
        connection.mockRespond(new Response(new ResponseOptions({
          body: responseObject
        })));
      });
    });

    afterEach(() => {
      backend.resolveAllConnections();
      backend.verifyNoPendingRequests();
    });

    it('should call http.get() with proper URL and use existing RequestOptions', () => {
      options.headers.set('this', 'should still be here');
      let response = fixture.get('/test/123', options);
      response.subscribe((res: Response) => {
        expect(res.json()).toEqual(responseObject);
        expect(requestHeaders).toBeDefined();
        expect(requestHeaders).toEqual(options.headers);
        expect(requestHeaders.get('Content-Type')).toEqual('application/json');
        expect(requestHeaders.get('Accept')).toEqual('application/json, text/plain, */*');
        expect(requestHeaders.get('Crds-Api-Key')).toEqual(process.env.ECHECK_API_TOKEN);
        expect(requestHeaders.get('this')).toEqual('should still be here');
        expect(requestUrl).toEqual('/test/123');
        expect(fixture.isLoggedIn()).toBeFalsy();
      });
    });

    it('should call http.get() with proper URL and create new RequestOptions', () => {
      options.headers.set('this', 'should not be here');
      let response = fixture.get('/test/123');
      response.subscribe((res: Response) => {
        expect(res.json()).toEqual(responseObject);
        expect(requestHeaders).toBeDefined();
        expect(requestHeaders).not.toEqual(options.headers);
        expect(requestHeaders.get('Content-Type')).toEqual('application/json');
        expect(requestHeaders.get('Accept')).toEqual('application/json, text/plain, */*');
        expect(requestHeaders.get('Crds-Api-Key')).toEqual(process.env.ECHECK_API_TOKEN);
        expect(requestHeaders.has('this')).toBeFalsy();
        expect(requestUrl).toEqual('/test/123');
        expect(fixture.isLoggedIn()).toBeFalsy();
      });
    });

    it('should set authentication token if sent in response', () => {
      responseObject.userToken = '<PASSWORD>';
      let response = fixture.get('/test/123');
      response.subscribe(() => {
        expect(fixture.isLoggedIn()).toBeTruthy();
      });
    });
  });
});<commit_msg>DE2004: Unit test sending auth header<commit_after>/* tslint:disable:no-unused-variable */

import { TestBed, async, inject } from '@angular/core/testing';
import { HttpClientService } from './http-client.service';
import { Http, RequestOptions, Headers, Response, ResponseOptions } from '@angular/http';
import { MockConnection, MockBackend } from '@angular/http/testing';

describe('HttpClientService', () => {
  let fixture: HttpClientService;
  let http: Http;
  let options: RequestOptions;
  let backend: MockBackend;
  let responseObject: any;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        HttpClientService
      ],
    });
    backend = new MockBackend();
    options = new RequestOptions();
    options.headers = new Headers();
    http = new Http(backend, options);
    fixture = new HttpClientService(http);
  });

  describe('get method', () => {
    responseObject = { 'test': 123 };
    let requestHeaders: Headers;
    let requestUrl: string;
    beforeEach(() => {
      backend.connections.subscribe((connection: MockConnection) => {
        requestHeaders = connection.request.headers;
        requestUrl = connection.request.url;
        connection.mockRespond(new Response(new ResponseOptions({
          body: responseObject
        })));
      });
    });

    afterEach(() => {
      backend.resolveAllConnections();
      backend.verifyNoPendingRequests();
    });

    it('should call http.get() with proper URL and use existing RequestOptions', () => {
      options.headers.set('this', 'should still be here');
      let response = fixture.get('/test/123', options);
      response.subscribe((res: Response) => {
        expect(res.json()).toEqual(responseObject);
        expect(requestHeaders).toBeDefined();
        expect(requestHeaders).toEqual(options.headers);
        expect(requestHeaders.get('Content-Type')).toEqual('application/json');
        expect(requestHeaders.get('Accept')).toEqual('application/json, text/plain, */*');
        expect(requestHeaders.get('Crds-Api-Key')).toEqual(process.env.ECHECK_API_TOKEN);
        expect(requestHeaders.get('this')).toEqual('should still be here');
        expect(requestUrl).toEqual('/test/123');
        expect(fixture.isLoggedIn()).toBeFalsy();
      });
    });

    it('should call http.get() with proper URL and create new RequestOptions', () => {
      options.headers.set('this', 'should not be here');
      let response = fixture.get('/test/123');
      response.subscribe((res: Response) => {
        expect(res.json()).toEqual(responseObject);
        expect(requestHeaders).toBeDefined();
        expect(requestHeaders).not.toEqual(options.headers);
        expect(requestHeaders.get('Content-Type')).toEqual('application/json');
        expect(requestHeaders.get('Accept')).toEqual('application/json, text/plain, */*');
        expect(requestHeaders.get('Crds-Api-Key')).toEqual(process.env.ECHECK_API_TOKEN);
        expect(requestHeaders.has('this')).toBeFalsy();
        expect(requestUrl).toEqual('/test/123');
        expect(fixture.isLoggedIn()).toBeFalsy();
      });
    });

    it('should set authentication token if sent in response', () => {
      responseObject.userToken = '<PASSWORD>';
      let response = fixture.get('/test/123');
      response.subscribe(() => {
        expect(fixture.isLoggedIn()).toBeTruthy();
      });
    });

    it('should send authentication token if logged in', () => {
      responseObject.userToken = '<PASSWORD>';
      let response = fixture.get('/test/123');
      response.subscribe(() => {
        expect(fixture.isLoggedIn()).toBeTruthy();
        let r2 = fixture.get('/test/123');
        r2.subscribe(() => {
          expect(requestHeaders.has('Authorization')).toBeTruthy();
          expect(requestHeaders.get('Authorization')).toEqual('98765');
        });
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.16072166368268834, 'fraction_numerical': 0.0072992700729927005, 'mean_word_length': 3.425350396099939, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2402585', 'n_tokens_mistral': 1996, 'n_tokens_neox': 2003, 'n_words': 357}