"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const test_1 = require("@playwright/test");
const _8_9_1 = require("../../fixtures/8.9");
const constants_1 = require("../../utils/constants");
const apiHelpers_1 = require("../../utils/apiHelpers");
const randomName_1 = require("../../utils/randomName");
_8_9_1.test.describe.configure({ mode: 'parallel' });
_8_9_1.test.describe('API optimize SaaS Tests', () => {
    let optimizeCookie;
    let optimizeBearerToken;
    let collectionIdValue;
    let dashboardIdValue;
    let reportId;
    let baseUrl;
    _8_9_1.test.beforeAll(async ({ browser, request }) => {
        const page = await browser.newPage();
        optimizeCookie = await (0, apiHelpers_1.getOptimizeCoockie)(page);
        await page.close();
        optimizeBearerToken = await (0, apiHelpers_1.authSaasAPI)(process.env.OPTIMIZE_API_TOKEN_AUDIENCE);
        collectionIdValue = await (0, apiHelpers_1.createCollection)(request, {
            name: await (0, randomName_1.randomNameAgregator)('Test Collection'),
            optimizeCookie,
        });
        baseUrl = process.env.CAMUNDA_OPTIMIZE_BASE_URL;
        await (0, apiHelpers_1.updateCollectionScope)(request, {
            optimizeCookie,
            collectionId: collectionIdValue,
            data: [
                {
                    definitionKey: 'customer_onboarding_en',
                    definitionType: 'process',
                    tenants: ['<default>'],
                },
            ],
        });
        dashboardIdValue = await (0, apiHelpers_1.createDashboard)(request, {
            name: await (0, randomName_1.randomNameAgregator)('Test Dashboard'),
            optimizeCookie,
            collectionId: collectionIdValue,
        });
        reportId = await (0, apiHelpers_1.createSingleProcessReport)(request, {
            optimizeCookie,
            collectionId: collectionIdValue,
            name: 'Blank report',
            definitions: [
                {
                    key: 'aProcess',
                    filter: [],
                    groupBy: { type: 'flowNodes', value: null },
                    distributedBy: { type: 'none', value: null },
                    view: { entity: 'flowNode', properties: ['duration'] },
                },
            ],
        });
    });
    _8_9_1.test.afterAll(async ({ request }) => {
        if (collectionIdValue) {
            await request.delete(`${baseUrl}/api/public/collection/${collectionIdValue}`, { headers: { Authorization: optimizeBearerToken } });
        }
    });
    (0, _8_9_1.test)('Get dashboard IDs returns 200 with id array', async ({ request }) => {
        await _8_9_1.test.step('GET /api/public/dashboard?collectionId returns 200', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard?collectionId=${collectionIdValue}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
            (0, test_1.expect)(body.length).toBeGreaterThan(0);
            const dashboard = body[0];
            (0, test_1.expect)(dashboard).toHaveProperty('id');
        });
    });
    (0, _8_9_1.test)('Get dashboards without token returns 401', async ({ request }) => {
        await _8_9_1.test.step('GET /api/public/dashboard without token (401)', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard?collectionId=${collectionIdValue}`);
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Get dashboards with invalid token returns 401', async ({ request }) => {
        await _8_9_1.test.step('GET /api/public/dashboard with invalid token (401)', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard?collectionId=${collectionIdValue}`, { headers: { Authorization: 'Bearer invalid_token' } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('GET /api/public/dashboard/force-internal-error returns 500', async ({ request, }) => {
        await _8_9_1.test.step('Force internal server error (500)', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard/force-internal-error`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)(response.status()).toBe(500);
        });
    });
    (0, _8_9_1.test)('Export dashboard definitions successfully returns 200', async ({ request, }) => {
        await _8_9_1.test.step('POST export dashboard definitions (200)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [dashboardIdValue],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
        });
    });
    (0, _8_9_1.test)('Export dashboards without token returns 401', async ({ request }) => {
        await _8_9_1.test.step('POST export dashboards without token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
                headers: { 'Content-Type': 'application/json' },
                data: [dashboardIdValue],
            });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Export dashboards with invalid token returns 401', async ({ request, }) => {
        await _8_9_1.test.step('POST export dashboards with invalid token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
                headers: {
                    Authorization: 'Bearer invalid_token',
                    'Content-Type': 'application/json',
                },
                data: [dashboardIdValue],
            });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Export dashboard with invalid body returns 400', async ({ request }) => {
        await _8_9_1.test.step('POST export dashboard with invalid body (400)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [{}],
            });
            (0, test_1.expect)(response.status()).toBe(400);
        });
    });
    (0, _8_9_1.test)('Export non-existent dashboard returns 404', async ({ request }) => {
        await _8_9_1.test.step('POST export non-existent dashboard (404)', async () => {
            const fakeDashboardId = 'nonexistent-dashboard-id';
            const response = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [fakeDashboardId],
            });
            (0, test_1.expect)([401, 404]).toContain(response.status());
        });
    });
    (0, _8_9_1.test)('Delete dashboard and verify it is no longer retrievable', async ({ request, }) => {
        const dashboardToDeleteId = await (0, apiHelpers_1.createDashboard)(request, {
            name: await (0, randomName_1.randomNameAgregator)('Dashboard To Delete'),
            optimizeCookie,
            collectionId: collectionIdValue,
        });
        await _8_9_1.test.step('Delete dashboard successfully (200)', async () => {
            const response = await request.delete(`${baseUrl}/api/public/dashboard/${dashboardToDeleteId}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
        });
        await _8_9_1.test.step('Verify dashboard not found after deletion', async () => {
            await (0, test_1.expect)(async () => {
                const response = await request.get(`${baseUrl}/api/public/dashboard/${dashboardToDeleteId}`, { headers: { Authorization: optimizeBearerToken } });
                (0, test_1.expect)([404, 410, 500]).toContain(response.status());
            }).toPass({ ...constants_1.defaultAssertionOptions, timeout: 60000 });
        });
    });
    (0, _8_9_1.test)('Delete dashboard with invalid token returns 401', async ({ request }) => {
        await _8_9_1.test.step('DELETE /api/public/dashboard with invalid token (401)', async () => {
            const response = await request.delete(`${baseUrl}/api/public/dashboard/${dashboardIdValue}`, { headers: { Authorization: 'Bearer invalid_token' } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Delete non-existent dashboard returns 404', async ({ request }) => {
        await _8_9_1.test.step('DELETE non-existent dashboard (404)', async () => {
            const fakeDashboardId = 'nonexistent-dashboard-id';
            const response = await request.delete(`${baseUrl}/api/public/dashboard/${fakeDashboardId}`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)(response.status()).toBe(404);
        });
    });
    (0, _8_9_1.test)('Get report IDs returns 200 with id array', async ({ request }) => {
        await _8_9_1.test.step('GET /api/public/report?collectionId returns 200', async () => {
            const response = await request.get(`${baseUrl}/api/public/report?collectionId=${collectionIdValue}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
        });
    });
    (0, _8_9_1.test)('Get reports with invalid token returns 401', async ({ request }) => {
        await _8_9_1.test.step('GET /api/public/report with invalid token (401)', async () => {
            const response = await request.get(`${baseUrl}/api/public/report?collectionId=${collectionIdValue}`, { headers: { Authorization: 'Bearer invalid_token' } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Export reports successfully returns 200 with full payload', async ({ request, }) => {
        await _8_9_1.test.step('POST export report definitions (200)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [reportId],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
            (0, test_1.expect)(body.length).toBeGreaterThan(0);
            (0, test_1.expect)(body[0]).toHaveProperty('id');
            (0, test_1.expect)(body[0]).toHaveProperty('exportEntityType');
            (0, test_1.expect)(body[0]).toHaveProperty('name');
            (0, test_1.expect)(body[0]).toHaveProperty('collectionId');
        });
    });
    (0, _8_9_1.test)('Export reports with invalid token returns 401', async ({ request }) => {
        await _8_9_1.test.step('POST export reports with invalid token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: {
                    Authorization: 'Bearer invalid_token',
                    'Content-Type': 'application/json',
                },
                data: [reportId],
            });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Export non-existent report returns 404', async ({ request }) => {
        await _8_9_1.test.step('POST export non-existent report (404)', async () => {
            const invalidReportId = '11111111-1111-1111-1111-111111111111';
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [invalidReportId],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 404);
        });
    });
    (0, _8_9_1.test)('Delete report and verify it is no longer retrievable', async ({ request, }) => {
        const reportToDeleteId = await (0, apiHelpers_1.createSingleProcessReport)(request, {
            optimizeCookie,
            collectionId: collectionIdValue,
            name: await (0, randomName_1.randomNameAgregator)('Report To Delete'),
            definitions: [
                {
                    key: 'aProcess',
                    filter: [],
                    groupBy: { type: 'flowNodes', value: null },
                    distributedBy: { type: 'none', value: null },
                    view: { entity: 'flowNode', properties: ['duration'] },
                },
            ],
        });
        await _8_9_1.test.step('Delete report successfully (200)', async () => {
            const response = await request.delete(`${baseUrl}/api/public/report/${reportToDeleteId}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
        });
        await _8_9_1.test.step('Verify deleted report is no longer retrievable (404 or 500)', async () => {
            const response = await request.get(`${baseUrl}/api/public/report/${reportToDeleteId}`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)([404, 500]).toContain(response.status());
        });
    });
    (0, _8_9_1.test)('Import entities successfully (200)', async ({ request }) => {
        const exportResponse = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
            headers: {
                Authorization: optimizeBearerToken,
                'Content-Type': 'application/json',
            },
            data: [dashboardIdValue],
        });
        await (0, apiHelpers_1.assertResponseStatus)(exportResponse, 200);
        const entitiesToImport = await exportResponse.json();
        const response = await request.post(`${baseUrl}/api/public/import?collectionId=${collectionIdValue}`, {
            headers: {
                Authorization: optimizeBearerToken,
                'Content-Type': 'application/json',
            },
            data: entitiesToImport,
        });
        await (0, apiHelpers_1.assertResponseStatus)(response, 200);
    });
    (0, _8_9_1.test)('Import without token or invalid token returns 401', async ({ request, }) => {
        const exportResponse = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
            headers: {
                Authorization: optimizeBearerToken,
                'Content-Type': 'application/json',
            },
            data: [dashboardIdValue],
        });
        await (0, apiHelpers_1.assertResponseStatus)(exportResponse, 200);
        const entitiesToImport = await exportResponse.json();
        const response = await request.post(`${baseUrl}/api/public/import?collectionId=${collectionIdValue}`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: entitiesToImport,
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    // Skipped due to bug 40497: https://github.com/camunda/camunda/issues/40497
    _8_9_1.test.skip('Import to non-existent collection (404)', async ({ request }) => {
        const exportResponse = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
            headers: {
                Authorization: optimizeBearerToken,
                'Content-Type': 'application/json',
            },
            data: [dashboardIdValue],
        });
        await (0, apiHelpers_1.assertResponseStatus)(exportResponse, 200);
        const entitiesToImport = await exportResponse.json();
        const fakeCollectionId = 'nonexistent-collection-id';
        const response = await request.post(`${baseUrl}/api/public/import?collectionId=${fakeCollectionId}`, {
            headers: {
                Authorization: optimizeBearerToken,
                'Content-Type': 'application/json',
            },
            data: entitiesToImport,
        });
        (0, test_1.expect)(response.status()).toBe(404);
    });
});
_8_9_1.test.describe('API optimize SaaS Tests - Conditional Events', () => {
    let optimizeCookie;
    let optimizeBearerToken;
    let conditionalEventsCollectionId;
    let conditionalEventsReportId;
    let baseUrl;
    const CONDITIONAL_EVENTS_PROCESS_KEY = 'conditional-events-auto-process';
    _8_9_1.test.beforeAll(async ({ browser, request }) => {
        const page = await browser.newPage();
        optimizeCookie = await (0, apiHelpers_1.getOptimizeCoockie)(page);
        await page.close();
        optimizeBearerToken = await (0, apiHelpers_1.authSaasAPI)(process.env.OPTIMIZE_API_TOKEN_AUDIENCE);
        conditionalEventsCollectionId = await (0, apiHelpers_1.createCollection)(request, {
            name: await (0, randomName_1.randomNameAgregator)('Conditional Events Collection'),
            optimizeCookie,
        });
        await (0, apiHelpers_1.updateCollectionScope)(request, {
            optimizeCookie,
            collectionId: conditionalEventsCollectionId,
            data: [
                {
                    definitionKey: CONDITIONAL_EVENTS_PROCESS_KEY,
                    definitionType: 'process',
                    tenants: ['<default>'],
                },
            ],
        });
        conditionalEventsReportId = await (0, apiHelpers_1.createSingleProcessReport)(request, {
            optimizeCookie,
            collectionId: conditionalEventsCollectionId,
            name: await (0, randomName_1.randomNameAgregator)('Conditional Events Report'),
            definitions: [
                {
                    key: CONDITIONAL_EVENTS_PROCESS_KEY,
                    filter: [],
                    groupBy: { type: 'none', value: null },
                    distributedBy: { type: 'none', value: null },
                    view: { entity: 'processInstance', properties: ['frequency'] },
                },
            ],
        });
        baseUrl = process.env.CAMUNDA_OPTIMIZE_BASE_URL;
    });
    _8_9_1.test.afterAll(async ({ request }) => {
        if (conditionalEventsCollectionId) {
            await request.delete(`${baseUrl}/api/public/collection/${conditionalEventsCollectionId}`, { headers: { Authorization: optimizeBearerToken } });
        }
    });
    (0, _8_9_1.test)('CE-OPT-09: Creating a Process Report for Conditional Events via API returns HTTP 200', async ({ request, }) => {
        await _8_9_1.test.step('Create a process report for conditional-events-auto-process (200)', async () => {
            const response = await request.post(`${baseUrl}/api/report/process/single`, {
                headers: {
                    Cookie: optimizeCookie,
                    'Content-Type': 'application/json',
                },
                data: {
                    collectionId: conditionalEventsCollectionId,
                    name: await (0, randomName_1.randomNameAgregator)('CE Report Inline'),
                    description: null,
                    data: {},
                    configuration: {
                        definitions: [
                            {
                                key: CONDITIONAL_EVENTS_PROCESS_KEY,
                                filter: [],
                                groupBy: { type: 'none', value: null },
                                distributedBy: { type: 'none', value: null },
                                view: {
                                    entity: 'processInstance',
                                    properties: ['frequency'],
                                },
                            },
                        ],
                        visualization: null,
                    },
                },
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('id');
            (0, test_1.expect)(body.id).toBeTruthy();
        });
    });
    (0, _8_9_1.test)('CE-OPT-10: Exporting the Conditional Events report definition via API returns the full report payload', async ({ request, }) => {
        await _8_9_1.test.step('Export report definition successfully (200)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [conditionalEventsReportId],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
            (0, test_1.expect)(body.length).toBeGreaterThan(0);
            (0, test_1.expect)(body[0]).toHaveProperty('id');
            (0, test_1.expect)(body[0]).toHaveProperty('exportEntityType');
            (0, test_1.expect)(body[0]).toHaveProperty('name');
            (0, test_1.expect)(body[0]).toHaveProperty('collectionId');
        });
    });
    (0, _8_9_1.test)('CE-OPT-11: Exporting the Conditional Events report without a token returns 401', async ({ request, }) => {
        await _8_9_1.test.step('Export report definition without Authorization header (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: { 'Content-Type': 'application/json' },
                data: [conditionalEventsReportId],
            });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('CE-OPT-12: Exporting the Conditional Events report with an invalid token returns 401', async ({ request, }) => {
        await _8_9_1.test.step('Export report definition with invalid token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: {
                    Authorization: 'Bearer invalid_token',
                    'Content-Type': 'application/json',
                },
                data: [conditionalEventsReportId],
            });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('CE-OPT-13: Deleting the Conditional Events report via API succeeds with HTTP 200', async ({ request, }) => {
        const reportToDeleteId = await (0, apiHelpers_1.createSingleProcessReport)(request, {
            optimizeCookie,
            collectionId: conditionalEventsCollectionId,
            name: await (0, randomName_1.randomNameAgregator)('CE Report To Delete'),
            definitions: [
                {
                    key: CONDITIONAL_EVENTS_PROCESS_KEY,
                    filter: [],
                    groupBy: { type: 'none', value: null },
                    distributedBy: { type: 'none', value: null },
                    view: { entity: 'processInstance', properties: ['frequency'] },
                },
            ],
        });
        await _8_9_1.test.step('Delete report successfully (200)', async () => {
            const response = await request.delete(`${baseUrl}/api/public/report/${reportToDeleteId}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
        });
    });
    (0, _8_9_1.test)('CE-OPT-14: A deleted Conditional Events report is no longer retrievable via the API', async ({ request, }) => {
        const reportToDeleteId = await (0, apiHelpers_1.createSingleProcessReport)(request, {
            optimizeCookie,
            collectionId: conditionalEventsCollectionId,
            name: await (0, randomName_1.randomNameAgregator)('CE Report Delete Verify'),
            definitions: [
                {
                    key: CONDITIONAL_EVENTS_PROCESS_KEY,
                    filter: [],
                    groupBy: { type: 'none', value: null },
                    distributedBy: { type: 'none', value: null },
                    view: { entity: 'processInstance', properties: ['frequency'] },
                },
            ],
        });
        await _8_9_1.test.step('Delete the report', async () => {
            const deleteResponse = await request.delete(`${baseUrl}/api/public/report/${reportToDeleteId}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(deleteResponse, 200);
        });
        await _8_9_1.test.step('Verify deleted report is no longer retrievable (404 or 500)', async () => {
            const getResponse = await request.get(`${baseUrl}/api/public/report/${reportToDeleteId}`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)([404, 500]).toContain(getResponse.status());
        });
    });
    (0, _8_9_1.test)('CE-OPT-15: Attempting to delete the Conditional Events report with an invalid token returns 401', async ({ request, }) => {
        await _8_9_1.test.step('Delete report with invalid token (401)', async () => {
            const response = await request.delete(`${baseUrl}/api/public/report/${conditionalEventsReportId}`, { headers: { Authorization: 'Bearer invalid_token' } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
});
_8_9_1.test.describe('API optimize SaaS Tests - Health Readiness', () => {
    let baseUrl;
    _8_9_1.test.beforeAll(async () => {
        baseUrl = process.env.CAMUNDA_OPTIMIZE_BASE_URL;
    });
    (0, _8_9_1.test)('Health readiness returns 200 when Optimize is ready', async ({ request, }) => {
        await _8_9_1.test.step('GET /api/readyz returns 200 (no auth required)', async () => {
            const response = await request.get(`${baseUrl}/api/readyz`);
            (0, test_1.expect)(response.status()).toBe(200);
        });
    });
    (0, _8_9_1.test)('Health readiness rejects requests that include an Authorization header', async ({ request, }) => {
        await _8_9_1.test.step('GET /api/readyz with Authorization header should be rejected', async () => {
            const token = await (0, apiHelpers_1.authSaasAPI)(process.env.OPTIMIZE_API_TOKEN_AUDIENCE);
            const response = await request.get(`${baseUrl}/api/readyz`, {
                headers: { Authorization: token },
            });
            (0, test_1.expect)([400, 401, 403]).toContain(response.status());
        });
    });
});
_8_9_1.test.describe('API optimize SaaS Tests - Sharing', () => {
    let optimizeBearerToken;
    let baseUrl;
    _8_9_1.test.beforeAll(async () => {
        optimizeBearerToken = await (0, apiHelpers_1.authSaasAPI)(process.env.OPTIMIZE_API_TOKEN_AUDIENCE);
        baseUrl = process.env.CAMUNDA_OPTIMIZE_BASE_URL;
    });
    (0, _8_9_1.test)('Enable sharing with valid token returns 200 or 204', async ({ request, }) => {
        await _8_9_1.test.step('POST /api/public/share/enable with valid token (200 or 204)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/enable`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)([200, 204]).toContain(response.status());
        });
    });
    (0, _8_9_1.test)('Enable sharing without token returns 401', async ({ request }) => {
        await _8_9_1.test.step('POST /api/public/share/enable without token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/enable`);
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Enable sharing with invalid token returns 401', async ({ request }) => {
        await _8_9_1.test.step('POST /api/public/share/enable with invalid token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/enable`, { headers: { Authorization: 'Bearer invalid_token' } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Disable sharing with valid token returns 200 or 204', async ({ request, }) => {
        await _8_9_1.test.step('POST /api/public/share/disable with valid token (200 or 204)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/disable`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)([200, 204]).toContain(response.status());
        });
    });
    (0, _8_9_1.test)('Disable sharing without token returns 401', async ({ request }) => {
        await _8_9_1.test.step('POST /api/public/share/disable without token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/disable`);
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Disable sharing with invalid token returns 401', async ({ request }) => {
        await _8_9_1.test.step('POST /api/public/share/disable with invalid token (401)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/disable`, { headers: { Authorization: 'Bearer invalid_token' } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Sharing toggle cycle: enable then disable is idempotent', async ({ request, }) => {
        await _8_9_1.test.step('Enable sharing (200 or 204)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/enable`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)([200, 204]).toContain(response.status());
        });
        await _8_9_1.test.step('Disable sharing (200 or 204)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/disable`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)([200, 204]).toContain(response.status());
        });
        await _8_9_1.test.step('Re-enable sharing returns 200 or 204 (idempotent)', async () => {
            const response = await request.post(`${baseUrl}/api/public/share/enable`, { headers: { Authorization: optimizeBearerToken } });
            (0, test_1.expect)([200, 204]).toContain(response.status());
        });
    });
});
_8_9_1.test.describe('API optimize SaaS Tests - Dashboard and Report GET edge cases', () => {
    let optimizeBearerToken;
    let optimizeCookie;
    let collectionId;
    let baseUrl;
    _8_9_1.test.beforeAll(async ({ browser, request }) => {
        const page = await browser.newPage();
        optimizeCookie = await (0, apiHelpers_1.getOptimizeCoockie)(page);
        await page.close();
        optimizeBearerToken = await (0, apiHelpers_1.authSaasAPI)(process.env.OPTIMIZE_API_TOKEN_AUDIENCE);
        baseUrl = process.env.CAMUNDA_OPTIMIZE_BASE_URL;
        collectionId = await (0, apiHelpers_1.createCollection)(request, {
            name: await (0, randomName_1.randomNameAgregator)('GET Edge Cases Collection'),
            optimizeCookie,
        });
    });
    _8_9_1.test.afterAll(async ({ request }) => {
        if (collectionId) {
            await request.delete(`${baseUrl}/api/public/collection/${collectionId}`, {
                headers: { Authorization: optimizeBearerToken },
            });
        }
    });
    (0, _8_9_1.test)('GET dashboards with valid token and collectionId returns 200 with id array', async ({ request, }) => {
        await _8_9_1.test.step('GET /api/public/dashboard?collectionId returns 200', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard?collectionId=${collectionId}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
        });
    });
    (0, _8_9_1.test)('GET dashboards without collectionId param returns 400 or 500', async ({ request, }) => {
        await _8_9_1.test.step('GET /api/public/dashboard without collectionId', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard`, {
                headers: { Authorization: optimizeBearerToken },
            });
            (0, test_1.expect)([400, 500]).toContain(response.status());
        });
    });
    (0, _8_9_1.test)('GET reports with valid token and collectionId returns 200 with id array', async ({ request, }) => {
        await _8_9_1.test.step('GET /api/public/report?collectionId returns 200', async () => {
            const response = await request.get(`${baseUrl}/api/public/report?collectionId=${collectionId}`, { headers: { Authorization: optimizeBearerToken } });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
        });
    });
    (0, _8_9_1.test)('GET reports without collectionId param returns 400 or 500', async ({ request, }) => {
        await _8_9_1.test.step('GET /api/public/report without collectionId', async () => {
            const response = await request.get(`${baseUrl}/api/public/report`, {
                headers: { Authorization: optimizeBearerToken },
            });
            (0, test_1.expect)([400, 500]).toContain(response.status());
        });
    });
});
_8_9_1.test.describe('API optimize SaaS Tests - Export edge cases', () => {
    let optimizeBearerToken;
    let optimizeCookie;
    let collectionId;
    let dashboardId1;
    let dashboardId2;
    let reportId1;
    let reportId2;
    let baseUrl;
    _8_9_1.test.beforeAll(async ({ browser, request }) => {
        const page = await browser.newPage();
        optimizeCookie = await (0, apiHelpers_1.getOptimizeCoockie)(page);
        await page.close();
        optimizeBearerToken = await (0, apiHelpers_1.authSaasAPI)(process.env.OPTIMIZE_API_TOKEN_AUDIENCE);
        baseUrl = process.env.CAMUNDA_OPTIMIZE_BASE_URL;
        collectionId = await (0, apiHelpers_1.createCollection)(request, {
            name: await (0, randomName_1.randomNameAgregator)('Export Edge Cases Collection'),
            optimizeCookie,
        });
        dashboardId1 = await (0, apiHelpers_1.createDashboard)(request, {
            name: await (0, randomName_1.randomNameAgregator)('Export Dashboard 1'),
            optimizeCookie,
            collectionId,
        });
        dashboardId2 = await (0, apiHelpers_1.createDashboard)(request, {
            name: await (0, randomName_1.randomNameAgregator)('Export Dashboard 2'),
            optimizeCookie,
            collectionId,
        });
        reportId1 = await (0, apiHelpers_1.createSingleProcessReport)(request, {
            optimizeCookie,
            collectionId,
            name: await (0, randomName_1.randomNameAgregator)('Export Report 1'),
            definitions: [
                {
                    key: 'aProcess',
                    filter: [],
                    groupBy: { type: 'none', value: null },
                    distributedBy: { type: 'none', value: null },
                    view: { entity: 'processInstance', properties: ['frequency'] },
                },
            ],
        });
        reportId2 = await (0, apiHelpers_1.createSingleProcessReport)(request, {
            optimizeCookie,
            collectionId,
            name: await (0, randomName_1.randomNameAgregator)('Export Report 2'),
            definitions: [
                {
                    key: 'aProcess',
                    filter: [],
                    groupBy: { type: 'none', value: null },
                    distributedBy: { type: 'none', value: null },
                    view: { entity: 'processInstance', properties: ['frequency'] },
                },
            ],
        });
    });
    _8_9_1.test.afterAll(async ({ request }) => {
        if (collectionId) {
            await request.delete(`${baseUrl}/api/public/collection/${collectionId}`, {
                headers: { Authorization: optimizeBearerToken },
            });
        }
    });
    (0, _8_9_1.test)('Export multiple dashboards in a single call returns 200 with all definitions', async ({ request, }) => {
        await _8_9_1.test.step('POST export with two dashboard IDs returns array of 2', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [dashboardId1, dashboardId2],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
            (0, test_1.expect)(body.length).toBeGreaterThanOrEqual(2);
        });
    });
    (0, _8_9_1.test)('Export multiple reports in a single call returns 200 with all definitions', async ({ request, }) => {
        await _8_9_1.test.step('POST export with two report IDs returns array of 2', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [reportId1, reportId2],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
            (0, test_1.expect)(body.length).toBeGreaterThanOrEqual(2);
        });
    });
    (0, _8_9_1.test)('Export reports with empty array body returns 200 with empty array', async ({ request, }) => {
        await _8_9_1.test.step('POST export/report with empty array body returns 200 []', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/report/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
            (0, test_1.expect)(body.length).toBe(0);
        });
    });
    (0, _8_9_1.test)('Export dashboards with empty array body returns 200 with empty array', async ({ request, }) => {
        await _8_9_1.test.step('POST export/dashboard with empty array body returns 200 []', async () => {
            const response = await request.post(`${baseUrl}/api/public/export/dashboard/definition/json`, {
                headers: {
                    Authorization: optimizeBearerToken,
                    'Content-Type': 'application/json',
                },
                data: [],
            });
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            const body = await response.json();
            (0, test_1.expect)(Array.isArray(body)).toBeTruthy();
            (0, test_1.expect)(body.length).toBe(0);
        });
    });
});
_8_9_1.test.describe('API optimize SaaS Tests - Auth edge cases', () => {
    let baseUrl;
    _8_9_1.test.beforeAll(async () => {
        baseUrl = process.env.CAMUNDA_OPTIMIZE_BASE_URL;
    });
    (0, _8_9_1.test)('Expired JWT token returns 401 on dashboard endpoint', async ({ request, }) => {
        const expiredToken = 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.' +
            'eyJzdWIiOiJ0ZXN0IiwiZXhwIjoxfQ.' +
            'invalidsignature';
        await _8_9_1.test.step('GET /api/public/dashboard with expired token returns 401', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard?collectionId=any`, { headers: { Authorization: expiredToken } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Malformed Bearer value (empty string) returns 401 on dashboard endpoint', async ({ request, }) => {
        await _8_9_1.test.step('GET /api/public/dashboard with empty Bearer value returns 401', async () => {
            const response = await request.get(`${baseUrl}/api/public/dashboard?collectionId=any`, { headers: { Authorization: 'Bearer ' } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
    (0, _8_9_1.test)('Token with wrong audience returns 401 on dashboard endpoint', async ({ request, }) => {
        await _8_9_1.test.step('Use a Zeebe-audience token against Optimize API and expect 401', async () => {
            const wrongAudienceToken = await (0, apiHelpers_1.authSaasAPI)();
            const response = await request.get(`${baseUrl}/api/public/dashboard?collectionId=any`, { headers: { Authorization: wrongAudienceToken } });
            (0, test_1.expect)(response.status()).toBe(401);
        });
    });
});
_8_9_1.test.describe('API V2 tests on SaaS cluster', () => {
    let bearerToken;
    const apiUrl = () => process.env.ZEEBE_API_URL;
    _8_9_1.test.beforeAll(async () => {
        bearerToken = await (0, apiHelpers_1.authSaasAPI)();
    });
    (0, _8_9_1.test)('GET /v2/topology returns 200', async ({ request }) => {
        const response = await request.get(`${apiUrl()}/v2/topology`, {
            headers: { Authorization: bearerToken, 'Content-Type': 'application/json' },
        });
        await (0, apiHelpers_1.assertResponseStatus)(response, 200);
    });
    (0, _8_9_1.test)('GET /v2/topology without token returns 401', async ({ request }) => {
        const response = await request.get(`${apiUrl()}/v2/topology`, {
            headers: { 'Content-Type': 'application/json' },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/process-definitions/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-definitions/search`, {
            headers: {
                Authorization: bearerToken,
                'Content-Type': 'application/json',
            },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/process-definitions/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-definitions/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/process-definitions/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-definitions/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/process-definitions/search with size 1 returns pagination cursor', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-definitions/search`, {
            headers: {
                Authorization: bearerToken,
                'Content-Type': 'application/json',
            },
            data: { filter: {}, page: { limit: 1 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(body.items.length).toBeLessThanOrEqual(1);
            if (body.page?.totalItems > 1) {
                (0, test_1.expect)(body).toHaveProperty('page');
            }
        }
    });
    (0, _8_9_1.test)('POST /v2/process-instances/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-instances/search`, {
            headers: {
                Authorization: bearerToken,
                'Content-Type': 'application/json',
            },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/process-instances/search filtered by state ACTIVE returns 200', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-instances/search`, {
            headers: {
                Authorization: bearerToken,
                'Content-Type': 'application/json',
            },
            data: { filter: { state: 'ACTIVE' }, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
        }
    });
    (0, _8_9_1.test)('POST /v2/process-instances/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-instances/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/process-instances/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/process-instances/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/user-tasks/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/user-tasks/search`, {
            headers: { Authorization: bearerToken, 'Content-Type': 'application/json' },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/user-tasks/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/user-tasks/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/user-tasks/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/user-tasks/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/variables/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/variables/search`, {
            headers: { Authorization: bearerToken, 'Content-Type': 'application/json' },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/variables/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/variables/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/variables/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/variables/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/incidents/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/incidents/search`, {
            headers: { Authorization: bearerToken, 'Content-Type': 'application/json' },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/incidents/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/incidents/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/incidents/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/incidents/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/decision-definitions/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/decision-definitions/search`, {
            headers: {
                Authorization: bearerToken,
                'Content-Type': 'application/json',
            },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/decision-definitions/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/decision-definitions/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/decision-definitions/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/decision-definitions/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/decision-instances/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/decision-instances/search`, {
            headers: {
                Authorization: bearerToken,
                'Content-Type': 'application/json',
            },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 400, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/decision-instances/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/decision-instances/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/decision-instances/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/decision-instances/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/flownode-instances/search returns 200 with items array', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/flownode-instances/search`, {
            headers: {
                Authorization: bearerToken,
                'Content-Type': 'application/json',
            },
            data: { filter: {}, page: { limit: 10 } },
        });
        (0, test_1.expect)([200, 404, 405]).toContain(response.status());
        if (response.status() === 200) {
            const body = await response.json();
            (0, test_1.expect)(body).toHaveProperty('items');
            (0, test_1.expect)(Array.isArray(body.items)).toBeTruthy();
        }
    });
    (0, _8_9_1.test)('POST /v2/flownode-instances/search without token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/flownode-instances/search`, {
            headers: { 'Content-Type': 'application/json' },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
    (0, _8_9_1.test)('POST /v2/flownode-instances/search with invalid token returns 401', async ({ request, }) => {
        const response = await request.post(`${apiUrl()}/v2/flownode-instances/search`, {
            headers: {
                Authorization: 'Bearer invalid_token',
                'Content-Type': 'application/json',
            },
            data: { filter: {}, size: 10 },
        });
        (0, test_1.expect)(response.status()).toBe(401);
    });
});
