<commit_before>import Request from 'router/Request';
import Response from 'router/Response';
import ServerWindow from 'window/ServerWindow';
import CookieStorage from 'storage/CookieStorage';

describe('ima.storage.CookieStorage', () => {

	let cookieString = 'cok1=hello;Path=/;Expires=Fri, 31 Dec 9999 23:59:59 GMT; cok2=hello2;Path=/;Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieString = 'cok3=hello3; Path=/; Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieStringWithFirstLetterUppercase = 'Cok3=hello3; Path=/; Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieStringWithDomain = 'cok3=hello3; Path=/; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieStringWithComplex = 'cok3="hello3"; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT; HttpOnly; Secure; Path=/';
	let setCookieStringWithMaxAge = 'cok3="hello3"; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT; Max-Age=5; HttpOnly; Secure; Path=/';
	let cookiesStringForCookieHeader = 'cok1=hello; cok2=hello2';

	let request = null;
	let response = null;
	let cookie = null;
	let win = null;
	let transformFunction = {
		encode: function(s) {
			return s;
		},
		decode: function(s) {
			return s;
		}
	};

	beforeEach(() => {
		request = new Request();
		response = new Response();
		win = new ServerWindow();
		cookie = new CookieStorage(win, request, response);

		request.init({});
		response.init({}, transformFunction);

		spyOn(request, 'getCookieHeader')
			.and
			.returnValue(cookieString);

		spyOn(response, 'setCookie')
			.and
			.stub();

		cookie.init({ secure: false }, transformFunction);
	});

	it('should be parse exist cookies', () => {
		expect(request.getCookieHeader).toHaveBeenCalled();
		expect(cookie._storage.size).toEqual(2);
	});


	it('should be has method, which return true for exist cookie other false', () => {
		expect(cookie.has('cok1')).toBe(true);
		expect(cookie.has('cok2')).toBe(true);
		expect(cookie.has('cok3')).toBe(false);
	});

	it('should be get value from cookie', () => {
		expect(cookie.get('cok1')).toEqual('hello');
		expect(cookie.get('cok2')).toEqual('hello2');
		expect(cookie.get('cok3')).toBeUndefined();
	});

	it('should be set value to cookie', () => {
		cookie.set('cok3', 'hello3');

		expect(response.setCookie).toHaveBeenCalled();
	});

	it('should be delete value from cookie', () => {
		cookie.delete('cok2');

		expect(response.setCookie).toHaveBeenCalled();
		expect(cookie._storage.size).toEqual(1);
	});<commit_msg>#82 CookieStorage.delete() test with options<commit_after>import Request from 'router/Request';
import Response from 'router/Response';
import ServerWindow from 'window/ServerWindow';
import CookieStorage from 'storage/CookieStorage';

describe('ima.storage.CookieStorage', () => {

	let cookieString = 'cok1=hello;Path=/;Expires=Fri, 31 Dec 9999 23:59:59 GMT; cok2=hello2;Path=/;Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieString = 'cok3=hello3; Path=/; Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieStringWithFirstLetterUppercase = 'Cok3=hello3; Path=/; Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieStringWithDomain = 'cok3=hello3; Path=/; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT';
	let setCookieStringWithComplex = 'cok3="hello3"; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT; HttpOnly; Secure; Path=/';
	let setCookieStringWithMaxAge = 'cok3="hello3"; Domain=localhost:3001; Expires=Fri, 31 Dec 9999 23:59:59 GMT; Max-Age=5; HttpOnly; Secure; Path=/';
	let cookiesStringForCookieHeader = 'cok1=hello; cok2=hello2';

	let request = null;
	let response = null;
	let cookie = null;
	let win = null;
	let transformFunction = {
		encode: function(s) {
			return s;
		},
		decode: function(s) {
			return s;
		}
	};

	beforeEach(() => {
		request = new Request();
		response = new Response();
		win = new ServerWindow();
		cookie = new CookieStorage(win, request, response);

		request.init({});
		response.init({}, transformFunction);

		spyOn(request, 'getCookieHeader')
			.and
			.returnValue(cookieString);

		spyOn(response, 'setCookie')
			.and
			.stub();

		cookie.init({ secure: false }, transformFunction);
	});

	it('should be parse exist cookies', () => {
		expect(request.getCookieHeader).toHaveBeenCalled();
		expect(cookie._storage.size).toEqual(2);
	});


	it('should be has method, which return true for exist cookie other false', () => {
		expect(cookie.has('cok1')).toBe(true);
		expect(cookie.has('cok2')).toBe(true);
		expect(cookie.has('cok3')).toBe(false);
	});

	it('should be get value from cookie', () => {
		expect(cookie.get('cok1')).toEqual('hello');
		expect(cookie.get('cok2')).toEqual('hello2');
		expect(cookie.get('cok3')).toBeUndefined();
	});

	it('should be set value to cookie', () => {
		cookie.set('cok3', 'hello3');

		expect(response.setCookie).toHaveBeenCalled();
	});

	it('should be delete value from cookie', () => {
		cookie.delete('cok2');

		expect(response.setCookie).toHaveBeenCalled();
		expect(cookie._storage.size).toEqual(1);
	});

	it('should be delete value from cookie with options', () => {
		cookie.delete('cok2', { domain: 'localhost' });

		expect(response.setCookie).toHaveBeenCalled();
		expect(cookie._storage.size).toEqual(1);
	});
{'fraction_non_alphanumeric': 0.16770892552586697, 'fraction_numerical': 0.04813340913397764, 'mean_word_length': 5.275862068965517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '5614363', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1783, 'n_words': 405}