"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const index_js_1 = require("../types/index.js");
const url_1 = require("./url");
(0, vitest_1.describe)('make curl string', () => {
    const reqMethod = 'POST';
    const reqUrl = 'https://foo.bar.baz/api/v1/path';
    const reqHeaders = [
        {
            key: 'header1',
            value: 'value1'
        },
        {
            key: 'header2',
            value: 'value2'
        }
    ];
    const reqParams = [
        {
            key: 'param1',
            value: 'value1'
        },
        {
            key: 'param2',
            value: 'value2'
        }
    ];
    const reqBody = '{"just": "some-data", "and": {"some": "nested-data"}}';
    const reqFormData = [
        {
            key: 'form1',
            value: 'value1'
        },
        {
            key: 'form2',
            value: 'value2'
        }
    ];
    const reqFileName = 'file1.txt';
    const reqFileFormKey = 'file';
    (0, vitest_1.test)('renders with form data', () => {
        const reqBodyType = index_js_1.RestApiBodyDataType.FORM;
        const expectedCurlCommand = `curl --location --request POST 'https://foo.bar.baz/api/v1/path?param1=value1&param2=value2' \\
\t--header 'header1: value1' \\
\t--header 'header2: value2' \\
\t--form 'form1="value1"' \\
\t--form 'form2="value2"'`;
        (0, vitest_1.expect)((0, url_1.makeCurlString)({
            reqMethod: reqMethod,
            reqUrl: reqUrl,
            reqHeaders: reqHeaders,
            reqParams: reqParams,
            reqBody: reqBody,
            reqFormData: reqFormData,
            reqBodyType: reqBodyType,
            reqFileName: reqFileName,
            reqFileFormKey: reqFileFormKey
        })).toBe(expectedCurlCommand);
    });
    (0, vitest_1.test)('renders with json data', () => {
        const reqBodyType = index_js_1.RestApiBodyDataType.JSON;
        const expectedCurlCommand = `curl --location --request POST 'https://foo.bar.baz/api/v1/path?param1=value1&param2=value2' \\
\t--header 'header1: value1' \\
\t--header 'header2: value2' \\
\t--data-raw '{
    "just": "some-data",
    "and": {
        "some": "nested-data"
    }
}'`;
        (0, vitest_1.expect)((0, url_1.makeCurlString)({
            reqMethod: reqMethod,
            reqUrl: reqUrl,
            reqHeaders: reqHeaders,
            reqParams: reqParams,
            reqBody: reqBody,
            reqFormData: reqFormData,
            reqBodyType: reqBodyType,
            reqFileName: reqFileName,
            reqFileFormKey: reqFileFormKey
        })).toBe(expectedCurlCommand);
    });
    (0, vitest_1.test)('renders with file form', () => {
        const reqBodyType = index_js_1.RestApiBodyDataType.FILE_FORM;
        const expectedCurlCommand = `curl --location --request POST 'https://foo.bar.baz/api/v1/path' \\
\t--form 'file="@file1.txt"'`;
        (0, vitest_1.expect)((0, url_1.makeCurlString)({
            reqMethod: reqMethod,
            reqUrl: reqUrl,
            reqHeaders: [],
            reqParams: [],
            reqBody: reqBody,
            reqFormData: reqFormData,
            reqBodyType: reqBodyType,
            reqFileName: reqFileName,
            reqFileFormKey: reqFileFormKey
        })).toBe(expectedCurlCommand);
    });
    (0, vitest_1.test)('renders with file form', () => {
        const reqBodyType = index_js_1.RestApiBodyDataType.RAW;
        const reqBody = 'test-raw-body-text';
        const expectedCurlCommand = `curl --location --request POST 'https://foo.bar.baz/api/v1/path' \\
\t--data-raw 'test-raw-body-text'`;
        (0, vitest_1.expect)((0, url_1.makeCurlString)({
            reqMethod: reqMethod,
            reqUrl: reqUrl,
            reqHeaders: [],
            reqParams: [],
            reqBody: reqBody,
            reqFormData: reqFormData,
            reqBodyType: reqBodyType,
            reqFileName: reqFileName,
            reqFileFormKey: reqFileFormKey
        })).toBe(expectedCurlCommand);
    });
});
(0, vitest_1.describe)('check param key value', () => {
    (0, vitest_1.test)('returns true if has key and value', () => {
        const property = {
            key: 'test-key',
            value: 'test-value'
        };
        (0, vitest_1.expect)((0, url_1.paramHasKeyValue)(property)).toBe(true);
    });
    (0, vitest_1.test)('returns false if has a key but no value', () => {
        const property = {
            key: 'abc',
            value: undefined
        };
        (0, vitest_1.expect)((0, url_1.paramHasKeyValue)(property)).toBe(false);
    });
    (0, vitest_1.test)('handles empty string value', () => {
        const property = {
            key: 'test-key',
            value: ''
        };
        (0, vitest_1.expect)((0, url_1.paramHasKeyValue)(property)).toBe(false);
    });
    (0, vitest_1.test)('handles undefined value', () => {
        const property = {
            key: 'test-key',
            value: undefined
        };
        (0, vitest_1.expect)((0, url_1.paramHasKeyValue)(property)).toBe(false);
    });
    (0, vitest_1.test)('handles undefined', () => {
        (0, vitest_1.expect)((0, url_1.paramHasKeyValue)(undefined)).toBe(false);
    });
});
(0, vitest_1.describe)('url matchers', () => {
    (0, vitest_1.test)('can match application urls', () => {
        const validUrl = 'https://example.com/api/v1/applications/foo';
        (0, vitest_1.expect)((0, url_1.isApplicationUrl)(validUrl)).toBe(true);
        const invalidUrl = 'https://example.com/api/v1/some-path';
        (0, vitest_1.expect)((0, url_1.isApplicationUrl)(invalidUrl)).toBe(false);
    });
    (0, vitest_1.test)('can match application edit urls', () => {
        const validUrl = 'https://example.com/api/v1/applications/foo/bar/baz/edit';
        (0, vitest_1.expect)((0, url_1.isApplicationEditUrl)(validUrl)).toBe(true);
        const invalidUrl = 'https://example.com/api/v1/applications/foo/bar/baz/view';
        (0, vitest_1.expect)((0, url_1.isApplicationEditUrl)(invalidUrl)).toBe(false);
    });
    (0, vitest_1.test)('can match workflow urls', () => {
        const validUrl = 'https://example.com/api/v1/workflows/foo/bar/baz';
        (0, vitest_1.expect)((0, url_1.isWorkflowUrl)(validUrl)).toBe(true);
        const invalidUrl = 'https://example.com/api/v1/applications/foo/bar/baz/view';
        (0, vitest_1.expect)((0, url_1.isWorkflowUrl)(invalidUrl)).toBe(false);
    });
    (0, vitest_1.test)('can match scheduled jobs urls', () => {
        const validUrl = 'https://example.com/api/v1/scheduled_jobs/foo/bar/baz';
        (0, vitest_1.expect)((0, url_1.isScheduledJobUrl)(validUrl)).toBe(true);
        const invalidUrl = 'https://example.com/api/v1/applications/foo/bar/baz/view';
        (0, vitest_1.expect)((0, url_1.isScheduledJobUrl)(invalidUrl)).toBe(false);
    });
    (0, vitest_1.test)('can fetch application id from url', () => {
        const url = 'https://example.com/api/v1/applications/test-application-id/';
        (0, vitest_1.expect)((0, url_1.getApplicationIdFromUrl)(url)).toBe('test-application-id');
    });
    (0, vitest_1.test)('can fetch workflow id from url', () => {
        const url = 'https://example.com/api/v1/workflows/test-workflow-id/';
        (0, vitest_1.expect)((0, url_1.getWorkflowIdFromUrl)(url)).toBe('test-workflow-id');
    });
    (0, vitest_1.test)('can fetch scheduled job id from url', () => {
        const url = 'https://example.com/api/v1/scheduled_jobs/test-scheduled-jobs-id/';
        (0, vitest_1.expect)((0, url_1.getScheduledJobIdFromUrl)(url)).toBe('test-scheduled-jobs-id');
    });
});
(0, vitest_1.describe)('append param', () => {
    (0, vitest_1.test)('can append to url without existing params', () => {
        const url = 'https://example.com/path';
        const expected = 'https://example.com/path?key=value';
        (0, vitest_1.expect)((0, url_1.appendParam)(url, 'key', 'value')).toBe(expected);
    });
    (0, vitest_1.test)('can append to url with existing params', () => {
        const url = 'https://example.com/path?key1=value1';
        const expected = 'https://example.com/path?key1=value1&key2=value2';
        (0, vitest_1.expect)((0, url_1.appendParam)(url, 'key2', 'value2')).toBe(expected);
    });
    (0, vitest_1.test)('can append multiple to url without existing params', () => {
        const url = 'https://example.com/path';
        const expected = 'https://example.com/path?key1=value1&key2=value2';
        (0, vitest_1.expect)((0, url_1.appendParams)(url, { key1: 'value1', key2: 'value2' })).toBe(expected);
    });
    (0, vitest_1.test)('can append multiple to url with existing params', () => {
        const url = 'https://example.com/path?key1=value1';
        const expected = 'https://example.com/path?key1=value1&key2=value2&key3=value3';
        (0, vitest_1.expect)((0, url_1.appendParams)(url, { key2: 'value2', key3: 'value3' })).toBe(expected);
    });
});
(0, vitest_1.describe)('extract params', () => {
    (0, vitest_1.test)('can extract prefix with params', () => {
        const params = {
            key1: 'value1',
            key2: 'value2',
            key3: 'value3',
            key4: 'value4',
            ignored1: 'value5',
            ignored2: 'value6'
        };
        const expected = {
            key1: 'value1',
            key2: 'value2',
            key3: 'value3',
            key4: 'value4'
        };
        (0, vitest_1.expect)((0, url_1.extractParamsWithPrefix)(params, 'key')).toEqual(expected);
    });
});
//# sourceMappingURL=url.test.js.map