describe('Request', function(){

    var Request = null;

    it('require Request', function(){
    	Request = require('../../lib/index.js').Net.Request;
    	expect(Request).toBeTruthy();

        beforeEach(function(){
            Request = require('../../lib/index.js').Net.Request;
        });
	});

    it('Request - construction #1', function(){
        var request = new Request("http://www.onet.pl/");
        expect(request.getUrl()).toBe('http://www.onet.pl/');
    });

    it('Request - construction #2', function(){
        var baseRequest = new Request("http://www.onet.pl/");
        var request = new Request(baseRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl/');
    });

    it('Request - construction #3', function(){
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.headers.host = 'www.onet.pl';
        httpRequest.url = "/";
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl/');
    });

    it('Request - construction #4', function(){
        var httpString = 'GET /index.html HTTP/1.1\r\n' +
                      'Pragma: no-cache\r\n' +
                      '\r\n' +
                      'body-data';
        var httpBuffer = new Buffer(httpString, 'binary');
        expect(function(){
            new Request(httpBuffer);
        }).toThrow();
    });


    /*

    //BBBBB
GET // HTTP/1.1
Host: www.onet.pl

//AAAAA
GET http://www.onet.pl// HTTP/1.1
Host: www.onet.pl

//CCCCC
GET http://www.onet.pl// HTTP/1.1
*/


    it('Request - construction IncomingMessage: HTTP/1.1 normal request', function(){
        // uri relative to domain + host header
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.headers.host = 'www.onet.pl';
        httpRequest.url = "/";
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl/');
    });

    it('Request - construction IncomingMessage: HTTP/1.1 normal request PROXY', function(){
        // uri absolute with domain + host header
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.headers.host = 'www.onet.pl';
        httpRequest.url = 'http://www.onet.pl/';
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl/');
    });

    it('Request - construction IncomingMessage: HTTP/0.9', function(){
        // uri absolute with domain without host header
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.url = 'http://www.onet.pl/';
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl/');
    });


    it('Request - construction IncomingMessage: HTTP/1.1 normal request (double slash)', function(){
        // uri relative to domain + host header
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.headers.host = 'www.onet.pl';
        httpRequest.url = "//";
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl//');
    });

    it('Request - construction IncomingMessage: HTTP/1.1 normal request PROXY (double slash)', function(){
        // uri absolute with domain + host header
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.headers.host = 'www.onet.pl';
        httpRequest.url = 'http://www.onet.pl//';
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl//');
    });

    it('Request - construction IncomingMessage: HTTP/0.9 (double slash)', function(){
        // uri absolute with domain without host header
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.url = 'http://www.onet.pl//';
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.onet.pl//');
    });


    it('Request - construction IncomingMessage: HTTP/1.1 normal request (alo.rs issue)', function(){
        // uri relative to domain + host header
        var http = require('http');
        var httpRequest = new http.IncomingMessage({});
        httpRequest.headers.host = 'www.alo.rs';
        httpRequest.url = "//resources/img/25-07-2014/intext_big/1333219-1.jpg";
        var request = new Request(httpRequest);
        expect(request.getUrl()).toBe('http://www.alo.rs//resources/img/25-07-2014/intext_big/1333219-1.jpg');
    });


    it('Request - toBuffer #1', function(){
        var request = new Request();
        expect(function(){
            request.toBuffer();
        }).toThrow();
    });

    it('Request - toBuffer #2', function(){
        var request = new Request();
        request.setBody('body-test');

        expect(function(){
            // ta funkcja dziala tylko z obiektem Response
            request.toBuffer();
        }).toThrow();
    });

    it('Request - toBinaryData #1', function(){
        var request = new Request();
        expect(function(){
            // ta funkcja dziala tylko z obiektem Response
            request.toBinaryData();
        }).toThrow();
    });

    it('Request - setUrl #1', function(){
        var request = new Request();
        request.setUrl('http://www.onet.pl');
        expect(request.getUrl()).toBe('http://www.onet.pl/');
        expect(request.getProto()).toBe('http:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #2', function(){
        var request = new Request();
        request.setUrl('http://www.onet.pl/');
        expect(request.getUrl()).toBe('http://www.onet.pl/');
        expect(request.getProto()).toBe('http:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #3', function(){
        var request = new Request();
        request.setUrl('http://www.onet.pl:80');
        expect(request.getUrl()).toBe('http://www.onet.pl/');
        expect(request.getProto()).toBe('http:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #4', function(){
        var request = new Request();
        request.setUrl('http://www.onet.pl:80/');
        expect(request.getUrl()).toBe('http://www.onet.pl/');
        expect(request.getProto()).toBe('http:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #5', function(){
        var request = new Request();
        request.setUrl('http://www.onet.pl/index.html');
        expect(request.getUrl()).toBe('http://www.onet.pl/index.html');
        expect(request.getProto()).toBe('http:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/index.html');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #6', function(){
        var request = new Request();
        request.setUrl('http://www.onet.pl/path/index.html');
        expect(request.getUrl()).toBe('http://www.onet.pl/path/index.html');
        expect(request.getProto()).toBe('http:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/path/index.html');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #7', function(){
        var request = new Request();
        request.setUrl('https://www.onet.pl:81/path/index.html');
        expect(request.getUrl()).toBe('https://www.onet.pl:81/path/index.html');
        expect(request.getProto()).toBe('https:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/path/index.html');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #8', function(){
        var request = new Request();
        request.setUrl('https://www.onet.pl:81/path/index.html?arg1=5');
        expect(request.getUrl()).toBe('https://www.onet.pl:81/path/index.html?arg1=5');
        expect(request.getProto()).toBe('https:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/path/index.html');
        expect(request.getQuery()).toEqual({arg1:'5'});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #9', function(){
        var request = new Request();
        request.setUrl('https://www.onet.pl:81/path/index.html?arg1=1&arg2=2');
        expect(request.getUrl()).toBe('https://www.onet.pl:81/path/index.html?arg1=1&arg2=2');
        expect(request.getProto()).toBe('https:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/path/index.html');
        expect(request.getQuery()).toEqual({arg1:'1', arg2:'2'});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #10', function(){
        var request = new Request();
        request.setUrl('https://sjanecki:password@www.onet.pl:81/path/index.html?arg1=1&arg2=2');
        expect(request.getUrl()).toBe('https://sjanecki:password@www.onet.pl:81/path/index.html?arg1=1&arg2=2');
        expect(request.getProto()).toBe('https:');
        expect(request.getConnectionHost()).toBe('www.onet.pl');
        expect(request.getPath()).toBe('/path/index.html');
        expect(request.getQuery()).toEqual({arg1:'1', arg2:'2'});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #11', function(){
        var request = new Request();
        expect(function(){
            request.setUrl();
        }).toThrow();
        expect(function(){
            request.setUrl(null);
        }).toThrow();
        expect(function(){
            request.setUrl(undefined);
        }).toThrow();
    });

    it('Request - setUrl #12', function(){
        var request = new Request();
        expect(function(){
             request.setUrl('');
        }).toThrow();
    });

    it('Request - setUrl #13', function(){
        var request = new Request();
        request.setUrl('somestring');
        expect(request.getUrl()).toBe('http://null/somestring');
        expect(request.getProto()).toBe('http:');
        expect(request.getHost()).toBe(null);
        expect(request.getPath()).toBe('/somestring');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #13', function(){
        var request = new Request();
        request.setUrl('somestring/index.txt');
        expect(request.getUrl()).toBe('http://null/somestring/index.txt');
        expect(request.getProto()).toBe('http:');
        expect(request.getHost()).toBe(null);
        expect(request.getPath()).toBe('/somestring/index.txt');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #14', function(){
        var request = new Request();
        request.setUrl('/somestring/index.txt');
        expect(request.getUrl()).toBe('http://null/somestring/index.txt');
        expect(request.getProto()).toBe('http:');
        expect(request.getHost()).toBe(null);
        expect(request.getPath()).toBe('/somestring/index.txt');
        expect(request.getQuery()).toEqual({});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #15', function(){
        var request = new Request();
        request.setUrl('?arg1=1&arg2=2');
        expect(request.getUrl()).toBe('http://null/?arg1=1&arg2=2');
        expect(request.getProto()).toBe('http:');
        expect(request.getHost()).toBe(null);
        expect(request.getPath()).toBe('/');
        expect(request.getQuery()).toEqual({arg1:'1', arg2:'2'});
        expect(Object.keys(request.getHeaders()).length).toBe(0);
    });

    it('Request - setUrl #16', function(){
        var request = new Request();
        request.setUrl('http://emisjawidgeet.onet.pl/quad/xml_spliter/?prid=37&caid=571&cc=4&form=823:4:G1:F1:O4:B1:E0:Y1:A6&content=&iid=-2358884862358101&prefix=ocs&ref=onet.pl&domain_name=onet.pl');
        expect(request.getUrl()).toBe('http://emisjawidgeet.onet.pl/quad/xml_spliter/?prid=37&caid=571&cc=4&form=823%3A4%3AG1%3AF1%3AO4%3AB1%3AE0%3AY1%3AA6&content=&iid=-2358884862358101&prefix=ocs&ref=onet.pl&domain_name=onet.pl');
    });


    it('Request - setUrl #17', function(){
        var request = new Request();
        request.setUrl('http://emisjawidgeet.onet.pl/quad/xml_spliter/?prid=37&caid=571&cc=4&form=823:4:G1:F1:O4:B1:E0:Y1:A6&content=&iid=-2358884862358101&prefix=ocs&ref=onet.pl&domain_name=onet.pl');
        expect(request.getQueryString()).toBe('?prid=37&caid=571&cc=4&form=823%3A4%3AG1%3AF1%3AO4%3AB1%3AE0%3AY1%3AA6&content=&iid=-2358884862358101&prefix=ocs&ref=onet.pl&domain_name=onet.pl');
    });

    it('Request - setQuery #1', function(){
        var request = new Request();
        request.setQuery({arg1: '1', arg2:'2'});
        expect(request.getQuery()).toEqual({arg1:'1', arg2:'2'});
        expect(request.getQueryParam('arg2')).toEqual('2');
        expect(request.getQueryString()).toEqual('?arg1=1&arg2=2');
    });

    it('Request - setQuery #2', function(){
        var request = new Request();
        request.setQuery({});
        expect(request.getQuery()).toEqual({});
        expect(request.getQueryParam('arg2')).toEqual(null);
        expect(request.getQueryString()).toEqual('');
    });

    it('Request - setQuery #3', function(){
        var request = new Request();
        request.setQuery();
        expect(request.getQuery()).toEqual(null);
        expect(request.getQueryParam('arg2')).toEqual(null);
        expect(request.getQueryString()).toEqual('');
    });

    it('Request - setQuery #4', function(){
        var request = new Request();
        request.setQuery('somestring');
        expect(request.getQuery()).toEqual('somestring');
        expect(request.getQueryParam('arg2')).toEqual(null);
        expect(request.getQueryParam(0)).toEqual('s');
        expect(request.getQueryParam(1)).toEqual('o');
        expect(request.getQueryString()).toEqual('?0=s&1=o&2=m&3=e&4=s&5=t&6=r&7=i&8=n&9=g');
    });

    it('Request - setQuery #5', function () {
        var request = new Request();
        request.setQueryParam('a', ['1', '2']);
        expect(request.getQueryParam('a')).toEqual(['1', '2']);
        expect(request.getQueryString()).toEqual('?a%5B%5D=1&a%5B%5D=2');
    });

    it('Request - setMethod #1', function(){
        var request = new Request();
        request.setMethod(Request.GET);
        expect(request.getMethod()).toEqual(Request.GET);
    });

    it('Request - setMethod #1', function(){
        var request = new Request();
        request.setMethod('somestring');
        expect(request.getMethod()).toEqual('somestring');
    });

    it('Request - setHost #1', function(){
        var request = new Request();
        request.setHost('www.onet.pl');
        expect(request.getHost()).toEqual('www.onet.pl');
    });

    it('Request - setHost #2', function(){
        var request = new Request();
        request.setHost();
        expect(request.getHost()).toBe(undefined);
    });

    it('Request - setPort #1', function(){
        var request = new Request();
        request.setPort(8081);
        expect(request.getPort()).toEqual(8081);
    });

    it('Request - setPort #2', function(){
        var request = new Request();
        request.setPort();
        expect(request.getPort()).toBe(undefined);
    });

    it('Request - setPath #1', function(){
        var request = new Request();
        request.setPath('/somepath/index.html');
        expect(request.getPath()).toBe('/somepath/index.html');
    });

    it('Request - setPath #2', function(){
        var request = new Request();
        request.setPath();
        expect(request.getPath()).toBe(undefined);
    });

    it('Request - setProto #1', function(){
        var request = new Request();
        request.setProto('http');
        expect(request.getProto()).toBe('http');
    });

    it('Request - setProto #2', function(){
        var request = new Request();
        request.setProto('http:');
        expect(request.getProto()).toBe('http:');
    });

    it('Request - setProto #3', function(){
        var request = new Request();
        request.setProto('somestring');
        expect(request.getProto()).toBe('somestring');
    });

    it('Request - setProto #4', function(){
        var request = new Request();
        request.setUrl('http://www.onet.pl/index.html');
        request.setProto('somestring');
        expect(request.getProto()).toBe('somestring');
        expect(request.getUrl()).toBe('somestring//www.onet.pl/index.html');
    });

    it('Request - setAuth #1', function(){
        var request = new Request();
        request.setAuth('user:pass');
        expect(request.getAuthUser()).toBe('user');
        expect(request.getAuthPassword()).toBe('pass');
    });

    it('Request - setAuth #2', function(){
        var request = new Request();
        request.setAuth('user-pass');
        expect(request.getAuthUser()).toBe('user-pass');
        expect(request.getAuthPassword()).toBe(undefined);
    });

    it('Request - setBody #1', function(){
        var request = new Request();
        request.setBody('post-data');
        expect(request.getBody().toUTF8String()).toBe('post-data');
    });

    it('Request - setBody #2', function(){
        var request = new Request();
        request.setBody();
        expect(function(){
            request.getBody().toUTF8String();
        }).not.toThrow();
    });

    it('Request - setBody #3', function(){
        var request = new Request();
        expect(function(){
            request.getBody().toUTF8String();
        }).toThrow();
    });

    it('Request - isConditional #1', function(){
        var request = new Request();
        request.setHeader('if-modified-since', Date.now());
        expect(request.isConditional()).toBeTruthy();
    });

    it('Request - isConditional #2', function(){
        var request = new Request();
        expect(request.isConditional()).toBeFalsy();
    });

    it('Request - isCompressedContentAccepted #1', function(){
        var request = new Request();
        request.setHeader('accept-encoding', 'gzip, deflate');
        expect(request.isCompressedContentAccepted()).toBeTruthy();
    });

    it('Request - isCompressedContentAccepted #2', function(){
        var request = new Request();
        expect(request.isCompressedContentAccepted()).toBeFalsy();
    });

    it('Request - isCompressedContentAccepted #3', function(){
        // nie obslugujemy deflate'a ze wzgledu na bledy w IE678
        var request = new Request();
        request.setHeader('accept-encoding', 'deflate');
        expect(request.isCompressedContentAccepted()).toBeFalsy();
    });

    it('Request - isGenerating #1', function(){
        var request = new Request();
        request.setHeader('x-onet-regenerate', 'YES');
        expect(request.isGenerating()).toBeTruthy();
    });

    it('Request - isGenerating #2', function(){
        var request = new Request();
        expect(request.isGenerating()).toBeFalsy();
    });

    it('Copying requests #1', function () {
        var r1 = new Request();
        r1.setUrl("http://www.onet.pl/0");
        r1.setHost("www.onet.pl");
        r1.setConnectionHost("fx.m1r2.onet");

        var r2 = new Request(r1);
        expect(r2.getUrl()).toEqual("http://www.onet.pl/0");
        expect(r2.getHost()).toEqual("www.onet.pl");
        expect(r2.getConnectionHost()).toEqual("fx.m1r2.onet");
    });

    it('toJson #1', function () {
        var data = {
            url :"http://www.onet.pl/",
            method: Request.GET,
            headers: {abc: [123]},
            body: null,
            httpVersion: '1.0'
        };

        var r = new Request(data.url);
        r.setMethod(data.method);
        r.setHeaders(data.headers);

        expect(r.toJson()).toEqual(data);
    });

    it('toJson #2', function () {
        var data = {
            url :"http://www.onet.pl/",
            method: Request.GET,
            headers: {abc: [123]},
            body: "abcdef",
            httpVersion: '1.0'
        };

        var r = new Request(data.url);
        r.setMethod(data.method);
        r.setHeaders(data.headers);
        r.setBody(data.body);

        expect(r.toJson()).toEqual(data);
    });

    it('removeCookie', function () {
        var data = {
            url: 'http://www.onet.pl/',
            method: Request.GET,
            headers: {cookie: 'aaaa=test; bbbb=test2'},
            httpVersion: '1.1'
        };
        var r = new Request(data.url);
        r.setMethod(data.method);
        r.setHeaders(data.headers);

        expect(r.getCookie('aaaa')).toEqual('test');
        expect(r.getCookie('bbbb')).toEqual('test2');
        r.removeCookie('aaaa');
        expect(r.getCookie('aaaa')).toBeFalsy();
        expect(r.getCookie('bbbb')).toEqual('test2');
        expect(r.getHeader('cookie')).toEqual('bbbb=test2');
    });

    it('add and remove cookie', function () {
        var data = {
            url: 'http://www.onet.pl/',
            method: Request.GET,
            headers: {},
            httpVersion: '1.1'
        };
        var r = new Request(data.url);
        r.setMethod(data.method);
        r.setHeaders(data.headers);

        expect(r.getHeader('cookie')).toBeFalsy();
        r.setCookie('aaaa=test');
        expect(r.getCookie('aaaa')).toEqual('test');
    });


    describe('remove cookies', function () {
        beforeEach(function () {
            this.request = new Request();
            this.request.setCookie('testa=value1');
            this.request.setCookie('test=value2');
            this.request.removeCookie('test');
        });

        it('should remove cookie test', function () {
            expect(this.request.getCookie('test')).toEqual(null);
        });

        it('should leave cookie testa', function () {
            expect(this.request.getCookie('testa')).toBeTruthy();
        });
    })


    describe('accept-language', function () {

        it('should return array', function () {
            var request = new Request();
            expect(request.getAcceptLanguages()).toEqual([]);
        });

        it('should return array', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguages()).toEqual([ 'pl-PL', 'pl', 'en-US', 'en' ]);
        });

        it('should return array with one language PL', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL');
            expect(request.getAcceptLanguages()).toEqual([ 'pl-PL' ]);
        });


        it('should return array', function () {
            var request = new Request();
            expect(request.getAcceptLanguage()).toEqual(undefined);
        });

        it('should return array', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage()).toEqual('pl-PL');
        });

        it('should return array with one language PL', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL');
            expect(request.getAcceptLanguage()).toEqual('pl-PL');
        });


        it('should return en', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage(['en'])).toEqual('en');
        });

        it('should return undefined', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage(['cz'])).toEqual(undefined);
        });

        it('should return en-US', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage(['cz', 'en-US'])).toEqual('en-US');
        });

        it('should characted case doesnt matter PL', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage(['pl-Pl', 'pl'])).toEqual('pl');
        });

        it('should characted case doesnt matter US', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage(['en-uS'])).toEqual('en-uS');
        });

        it('should characted case doesnt matter PL 2', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage(['pl-pl'])).toEqual(undefined);
        });

        it('should handle firefox accept-language', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl,en-US;q=0.7,en;q=0.3');
            expect(request.getAcceptLanguage()).toEqual('pl');
        });

        it('should handle firefox accept-language', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl,en-US;q=0.7,en;q=0.3');
            expect(request.getAcceptLanguage(['pl-pl', 'pl'])).toEqual('pl');
        });

        it('should handle firefox accept-language', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl,en-US;q=0.7,en;q=0.3');
            expect(request.getAcceptLanguage(['pl-pl', 'pl', 'en-us', 'en'])).toEqual('pl');
        });

        it('should handle firefox accept-language', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'pl,en-US;q=0.7,en;q=0.3');
            expect(request.getAcceptLanguage(['pl', 'en'])).toEqual('pl');
        });

        it('should handle firefox accept-language', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'sr-RS,sr;q=0.8,en-US;q=0.6,en;q=0.4');
            expect(request.getAcceptLanguage(['pl', 'en', 'sr'])).toEqual('sr');
        });

        it('should handle firefox accept-language', function () {
            var request = new Request();
            request.setHeader('Accept-Language', 'sr-YU');
            expect(request.getAcceptLanguage(['pl', 'en', 'sr'])).toEqual('sr');
        });





    })
});
