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

import { TestBed, async, inject } from '@angular/core/testing';
import { SignInService } from './sign-in.service';
import { HttpClientService } from '../../shared/services/http-client.service';
import { Http, RequestOptions, Headers, Response, ResponseOptions } from '@angular/http';
import { MockConnection, MockBackend } from '@angular/http/testing';
import {CookieService, CookieOptions} from 'angular2-cookie/core';

describe('SignInService', () => {
  let fixture: SignInService;
  let httpClientService: HttpClientService;
  let http: Http;
  let options: RequestOptions;
  let backend: MockBackend;
  let responseObject: any;
  let cookie: CookieService;
  let body: any;
  let requestHeaders: Headers;
  let requestUrl: string;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        HttpClientService
      ],
    });
    backend = new MockBackend();
    options = new RequestOptions();
    options.headers = new Headers();
    http = new Http(backend, options);
    cookie = new CookieService(new CookieOptions());
    httpClientService = new HttpClientService(http, cookie);
    fixture = new SignInService(httpClientService);
    body = { email: '<EMAIL>', password: '<PASSWORD>' };
  });

  fdescribe('when logging in', () => {
    afterEach(() => {
      backend.resolveAllConnections();
      backend.verifyNoPendingRequests();
      httpClientService.logOut();
    });

    describe('with successful credentials', () => {
      beforeEach(() => {
        backend.connections.subscribe((connection: MockConnection) => {
          requestHeaders = connection.request.headers;
          requestUrl = connection.request.url;
          const headers = new Headers();
          headers.append('Authorization', '98765');
          headers.append('RefreshToken', 'refresh-8885');
          connection.mockRespond(new Response(new ResponseOptions({
            body: responseObject,
            headers: headers
          })));
        });
      });

      it('should successfully login a user', () => {
        responseObject = { userToken: '<PASSWORD>', refreshToken: '<PASSWORD>', roles: ['123', '456'] };
        let response = http.post( `${process.env.ECHECK_API_ENDPOINT}/authenticate`, body);
        let login = fixture.logIn(body.email, body.password);
        options.headers.set('Authorization', 'successful');

        response.subscribe((res: Response) => {
          expect(res.json()).toEqual(responseObject);
          expect(requestHeaders).toBeDefined();
          expect(httpClientService.isLoggedIn()).toBeTruthy();
          expect(httpClientService.hasRefreshToken()).toBeTruthy();
        });
      });
    })

    describe('with bad credentials', () => {
      beforeEach(() => {
        backend.connections.subscribe((connection: MockConnection) => {
          requestHeaders = connection.request.headers;
          requestUrl = connection.request.url;
          const headers = new Headers();
          // do not add successful auth, refreshtoken headers
          connection.mockRespond(new Response(new ResponseOptions({
            body: responseObject,
            headers: headers
          })));
        });
      });

      it('should not login a user', () => {
        responseObject = { userToken: undefined };
        let response = http.post( `${process.env.ECHECK_API_ENDPOINT}/authenticate`, body);
        let login = fixture.logIn(body.email, body.password);
        response.subscribe((res: Response) => {
          console.log("123", httpClientService.isLoggedIn(), httpClientService.hasRefreshToken());
          expect(httpClientService.isLoggedIn()).toBeFalsy();
          expect(httpClientService.hasRefreshToken()).toBeFalsy();
        });
      });
    });

  });
});
<commit_msg>US5287: cleanup<commit_after>/* tslint:disable:no-unused-variable */

import { TestBed, async, inject } from '@angular/core/testing';
import { SignInService } from './sign-in.service';
import { HttpClientService } from '../../shared/services/http-client.service';
import { Http, RequestOptions, Headers, Response, ResponseOptions } from '@angular/http';
import { MockConnection, MockBackend } from '@angular/http/testing';
import {CookieService, CookieOptions} from 'angular2-cookie/core';

describe('SignInService', () => {
  let fixture: SignInService;
  let httpClientService: HttpClientService;
  let http: Http;
  let options: RequestOptions;
  let backend: MockBackend;
  let responseObject: any;
  let cookie: CookieService;
  let body: any;
  let requestHeaders: Headers;
  let requestUrl: string;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        HttpClientService
      ],
    });
    backend = new MockBackend();
    options = new RequestOptions();
    options.headers = new Headers();
    http = new Http(backend, options);
    cookie = new CookieService(new CookieOptions());
    httpClientService = new HttpClientService(http, cookie);
    fixture = new SignInService(httpClientService);
    body = { email: '<EMAIL>', password: '<PASSWORD>' };
  });

  describe('when logging in', () => {
    afterEach(() => {
      backend.resolveAllConnections();
      backend.verifyNoPendingRequests();
      httpClientService.logOut();
    });

    describe('with successful credentials', () => {
      beforeEach(() => {
        backend.connections.subscribe((connection: MockConnection) => {
          requestHeaders = connection.request.headers;
          requestUrl = connection.request.url;
          const headers = new Headers();
          headers.append('Authorization', '98765');
          headers.append('RefreshToken', '<PASSWORD>');
          connection.mockRespond(new Response(new ResponseOptions({
            body: responseObject,
            headers: headers
          })));
        });
      });

      it('should successfully login a user', () => {
        responseObject = { userToken: 'userToken1', refreshToken: '<PASSWORD>', roles: ['123', '456'] };
        let response = http.post( `${process.env.ECHECK_API_ENDPOINT}/authenticate`, body);
        let login = fixture.logIn(body.email, body.password);
        response.subscribe((res: Response) => {
          expect(res.json()).toEqual(responseObject);
          expect(requestHeaders).toBeDefined();
          expect(httpClientService.isLoggedIn()).toBeTruthy();
          expect(httpClientService.hasRefreshToken()).toBeTruthy();
        });
      });
    })

    describe('with bad credentials', () => {
      beforeEach(() => {
        backend.connections.subscribe((connection: MockConnection) => {
          requestHeaders = connection.request.headers;
          requestUrl = connection.request.url;
          const headers = new Headers();
          // do not add successful auth, refreshtoken headers
          connection.mockRespond(new Response(new ResponseOptions({
            body: responseObject,
            headers: headers
          })));
        });
      });

      it('should not login a user', () => {
        responseObject = { userToken: undefined };
        let response = http.post( `${process.env.ECHECK_API_ENDPOINT}/authenticate`, body);
        let login = fixture.logIn(body.email, body.password);
        response.subscribe((res: Response) => {
          expect(httpClientService.isLoggedIn()).toBeFalsy();
          expect(httpClientService.hasRefreshToken()).toBeFalsy();
        });
      });
    });

  });
});

{'fraction_non_alphanumeric': 0.13990121479108264, 'fraction_numerical': 0.004805766920304365, 'mean_word_length': 3.0453563714902807, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, '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': '4039921', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1960, 'n_words': 420}