"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const c8Run_8_9_1 = require("../../fixtures/c8Run-8.9");
const apiHelpers_1 = require("../../utils/apiHelpers");
const sleep_1 = require("../../utils/sleep");
const zeebeClient_1 = require("../../utils/zeebeClient");
const test_1 = require("@playwright/test");
const constants_1 = require("../../utils/constants");
if (process.env.DATABASE != 'RDBMS') {
    c8Run_8_9_1.test.beforeAll(async () => {
        await Promise.all([
            (0, zeebeClient_1.deploy)('./resources/User_Task_Process_With_Form.bpmn'),
            (0, zeebeClient_1.deploy)('./resources/New Form.form'),
            (0, zeebeClient_1.deploy)('./resources/User_Task_Process_With_Form.bpmn'),
            (0, zeebeClient_1.deploy)('./resources/Start_Form_Process.bpmn'),
        ]);
        await Promise.all([
            (0, zeebeClient_1.createInstances)('Form_User_Task', 1, 3),
            (0, zeebeClient_1.createInstances)('Start_Form_Process', 1, 1),
        ]);
        await (0, sleep_1.sleep)(10000);
    });
    c8Run_8_9_1.test.describe('API tests for v1', () => {
        const auth = Buffer.from(`demo:demo`).toString('base64');
        const requestHeaders = {
            headers: {
                'Content-Type': 'application/json',
                Authorization: `Basic ${auth}`,
            },
        };
        (0, c8Run_8_9_1.test)('Search for process definitions @tasklistV2', async ({ request }) => {
            const processDefinitionsList = await request.post('/v1/process-definitions/search', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(processDefinitionsList, 200);
        });
        (0, c8Run_8_9_1.test)('Get a process definition via key @tasklistV2', async ({ request }) => {
            await (0, test_1.expect)(async () => {
                const searchProcessDefinitions = await request.post(`/v1/process-definitions/search`, requestHeaders);
                const processKey = await searchProcessDefinitions.json();
                (0, test_1.expect)(processKey.items.length).toBeGreaterThan(0);
                const response = await request.get(`/v1/process-definitions/` + processKey.items[0].key, requestHeaders);
                await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
        (0, c8Run_8_9_1.test)('Search for process instances @tasklistV2', async ({ request }) => {
            const processInstancesList = await request.post('/v1/process-instances/search', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(processInstancesList, 200);
        });
        (0, c8Run_8_9_1.test)('Search for flownode-instances @tasklistV2', async ({ request }) => {
            const flowNodeInstancesList = await request.post('/v1/flownode-instances/search', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(flowNodeInstancesList, 200);
        });
        (0, c8Run_8_9_1.test)('Search for variables for process instances @tasklistV2', async ({ request, }) => {
            const variablesInstancesList = await request.post('/v1/variables/search', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(variablesInstancesList, 200);
        });
        (0, c8Run_8_9_1.test)('Search for incidents @tasklistV2', async ({ request }) => {
            const incidentsList = await request.post('/v1/incidents/search', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(incidentsList, 200);
        });
        (0, c8Run_8_9_1.test)('Get connectors status @tasklistV2', async ({ request }) => {
            await (0, sleep_1.sleep)(10000);
            const connectorsStatus = await request.get(process.env.C8RUN_CONNECTORS_API_URL_LATEST + '/actuator/health', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(connectorsStatus, 200);
        });
        (0, c8Run_8_9_1.test)('Get a inbound connectors list @tasklistV2', async ({ request }) => {
            const connectorsInboundList = await request.get(process.env.C8RUN_CONNECTORS_API_URL_LATEST + '/inbound', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(connectorsInboundList, 200);
        });
        (0, c8Run_8_9_1.test)('Search for tasks', async ({ request }) => {
            const taskList = await request.post('/v1/tasks/search', requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(taskList, 200);
        });
        (0, c8Run_8_9_1.test)('Get a task via ID', async ({ request }) => {
            const searchTasks = await request.post(`/v1/tasks/search`, requestHeaders);
            const taskID = await searchTasks.json();
            const response = await request.get('/v1/tasks/' + taskID[0].id, requestHeaders);
            await (0, apiHelpers_1.assertResponseStatus)(response, 200);
        });
    });
}
