<commit_before>import { TestBed, inject, async } from '@angular/core/testing';
import { BaseRequestOptions, Response, Http, ResponseOptions }
	from '@angular/http';
import { MockBackend } from '@angular/http/testing';

import { ColorsService } from './colors.service';

describe('ColorsService', () => {
	beforeEach(async() => {
		TestBed.configureTestingModule({
			providers: [
				ColorsService,
				{
					provide: Http, useFactory: (backend, options) => {
						return new Http(backend, options);
					},
					deps: [MockBackend, BaseRequestOptions]
				},
				MockBackend,
				BaseRequestOptions
			]
		});
	});

	it('should ...', inject([ColorsService], (service: ColorsService) => {
		expect(service).toBeTruthy();
	}));

	it('should retrieve the list of colors', done => {
		inject([ColorsService, MockBackend],
			(service: ColorsService, backend: MockBackend) => {
		let response = JSON.stringify([
			['black', 'Black'],
			['white', 'White'],
			['red-500', 'Red 500']
		]);
		backend.connections.subscribe(connection => {
			connection.mockRespond(new Response(new ResponseOptions(
				{body: response})));
		});

		service.getColors().then(colors => {
			expect(colors[0]).toContain('black');
			expect(colors[0]).toContain('white',);
			expect(colors[1]).toContain('red-500');
			done();
		});
	})() });

	it('should move the colors in a 10 wide grid', done => {
		inject([ColorsService, MockBackend],
			(service: ColorsService, backend: MockBackend) => {
			let response = JSON.stringify([['0-0', ''], ['0-1', ''],
				['1-0', ''], ['1-1', ''], ['1-2', ''], ['1-3', ''],
				['1-4', ''], ['1-5', ''], ['1-6', ''], ['1-7', ''],
				['1-8', ''], ['1-9', ''], ['2-0', ''], ['2-1', ''],
				['2-2', ''], ['2-3', ''], ['2-4', ''], ['2-5', '']]);
		backend.connections.subscribe(connection => {
			connection.mockRespond(new Response(new ResponseOptions(
				{body: response})));
		});

		service.getColors().then(colors => {
			console.log(colors);
			expect(colors).toEqual([['0-0', '0-1'], ['1-0', '1-1', '1-2', '1-3',
			'1-4', '1-5', '1-6', '1-7', '1-8', '1-9'], ['2-0', '2-1', '2-2',
			'2-3', '2-4', '2-5']]);
			done();
		});
	})() });
});<commit_msg>Test error handling of color service [ci skip]<commit_after>import { TestBed, inject, async, fakeAsync, tick }
	from '@angular/core/testing';
import { BaseRequestOptions, Response, Http, ResponseOptions }
	from '@angular/http';
import { MockBackend } from '@angular/http/testing';

import { ColorsService } from './colors.service';

describe('ColorsService', () => {
	beforeEach(async() => {
		TestBed.configureTestingModule({
			providers: [
				ColorsService,
				{
					provide: Http, useFactory: (backend, options) => {
						return new Http(backend, options);
					},
					deps: [MockBackend, BaseRequestOptions]
				},
				MockBackend,
				BaseRequestOptions
			]
		});
	});

	it('should ...', inject([ColorsService], (service: ColorsService) => {
		expect(service).toBeTruthy();
	}));

	it('should retrieve the list of colors', done => {
		inject([ColorsService, MockBackend],
			(service: ColorsService, backend: MockBackend) => {
		let response = JSON.stringify([
			['black', 'Black'],
			['white', 'White'],
			['red-500', 'Red 500']
		]);
		backend.connections.subscribe(connection => {
			connection.mockRespond(new Response(new ResponseOptions(
				{body: response})));
		});

		service.getColors().then(colors => {
			expect(colors[0]).toContain('black');
			expect(colors[0]).toContain('white',);
			expect(colors[1]).toContain('red-500');
			done();
		});
	})() });

	it('should move the colors in a 10 wide grid', done => {
		inject([ColorsService, MockBackend],
			(service: ColorsService, backend: MockBackend) => {
			let response = JSON.stringify([['0-0', ''], ['0-1', ''],
				['1-0', ''], ['1-1', ''], ['1-2', ''], ['1-3', ''],
				['1-4', ''], ['1-5', ''], ['1-6', ''], ['1-7', ''],
				['1-8', ''], ['1-9', ''], ['2-0', ''], ['2-1', ''],
				['2-2', ''], ['2-3', ''], ['2-4', ''], ['2-5', '']]);
		backend.connections.subscribe(connection => {
			connection.mockRespond(new Response(new ResponseOptions(
				{body: response})));
		});

		service.getColors().then(colors => {
			expect(colors).toEqual([['0-0', '0-1'], ['1-0', '1-1', '1-2', '1-3',
			'1-4', '1-5', '1-6', '1-7', '1-8', '1-9'], ['2-0', '2-1', '2-2',
			'2-3', '2-4', '2-5']]);
			done();
		});
	})() });

	it('should query the correct url', inject([ColorsService, MockBackend],
		(service: ColorsService, backend: MockBackend) => {
		let lastConnection;
		backend.connections.subscribe(
			(connection: any) => lastConnection = connection);
		service.getColors();
		expect(lastConnection).toBeDefined(
			'no http service connection at all?');
		expect(lastConnection.request.url).toMatch('api/colors/',
			'url valid');
	}));

	it('should return an error when server is down', fakeAsync(() => {
		inject([ColorsService, MockBackend],
			(service: ColorsService, backend: MockBackend) => {
			let result;
			let catchedError;
			backend.connections.subscribe(connection => {
				connection.mockRespond(new Response(new ResponseOptions({
					status: 404,
					statusText: 'URL not found',
				})));
			});
			service.getColors()
				.then(colors => result = colors)
				.catch(error => catchedError = error);
			tick();
			expect(result).toBeUndefined();
			expect(catchedError).toBeDefined();
		})()
	}));
});
{'fraction_non_alphanumeric': 0.23715562174236784, 'fraction_numerical': 0.03257632166790767, 'mean_word_length': 3.92032967032967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, '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': '392930', 'n_tokens_mistral': 2126, 'n_tokens_neox': 1855, 'n_words': 360}