{"size": 2200, "ext": "js", "max_stars_repo_path": "javascript/components/networking/url.test.js", "max_stars_repo_name": "EPIC-striker/playground", "max_stars_repo_stars_event_min_datetime": "2015-10-17T12:50:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T14:55:32.000Z", "max_issues_repo_path": "javascript/components/networking/url.test.js", "max_issues_repo_name": "EPIC-striker/playground", "max_issues_repo_issues_event_min_datetime": "2015-10-13T19:07:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-23T13:24:42.000Z", "max_forks_repo_path": "javascript/components/networking/url.test.js", "max_forks_repo_name": "EPIC-striker/playground", "max_forks_repo_forks_event_min_datetime": "2015-10-27T11:18:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T14:15:07.000Z"}
{"max_stars_count": 52, "max_issues_count": 752, "max_forks_count": 58, "avg_line_length": 40.7407407407, "max_line_length": 98, "alphanum_fraction": 0.6281818182}
// Copyright 2020 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.

import { URL } from 'components/networking/url.js';

describe('URL', it => {
    it('is able to fully parse both basic and complicated URLs', assert => {
        const basicUrl = new URL('https://sa-mp.nl/file.txt');

        assert.equal(basicUrl.href, 'https://sa-mp.nl/file.txt');
        assert.equal(basicUrl.origin, 'https://sa-mp.nl');
        assert.equal(basicUrl.protocol, 'https');
        assert.equal(basicUrl.username, undefined);
        assert.equal(basicUrl.password, undefined);
        assert.equal(basicUrl.host, 'sa-mp.nl:443');
        assert.equal(basicUrl.hostname, 'sa-mp.nl');
        assert.equal(basicUrl.port, 443);
        assert.equal(basicUrl.pathname, '/file.txt');
        assert.equal(basicUrl.search, undefined);
        assert.equal(basicUrl.hash, undefined);

        const complexUrl = new URL('https://russell:password@sa-mp.nl/api/?version=1&bar=2#help');

        assert.equal(
            complexUrl.href, 'https://russell:password@sa-mp.nl/api/?version=1&bar=2#help');

        assert.equal(complexUrl.origin, 'https://sa-mp.nl');
        assert.equal(complexUrl.protocol, 'https');
        assert.equal(complexUrl.username, 'russell');
        assert.equal(complexUrl.password, 'password');
        assert.equal(complexUrl.host, 'sa-mp.nl:443');
        assert.equal(complexUrl.hostname, 'sa-mp.nl');
        assert.equal(complexUrl.port, 443);
        assert.equal(complexUrl.pathname, '/api/');
        assert.equal(complexUrl.search, 'version=1&bar=2');
        assert.equal(complexUrl.hash, 'help');
    });

    it('is able to serialize even after changing information', assert => {
        const url = new URL('https://sa-mp.nl/foo');

        url.protocol = 'samp';
        url.username = 'russell';
        url.hostname = 'play.sa-mp.nl';
        url.port = 7777;
        url.pathname = '';
        url.searchParams.append('health', 100);
        url.hash = 'spawn';

        assert.equal(String(url), 'samp://russell@play.sa-mp.nl:7777/?health=100#spawn');
    });
});
