"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const c8Run_8_6_1 = require("../../fixtures/c8Run-8.6");
const apiHelpers_1 = require("../../utils/apiHelpers");
const sleep_1 = require("../../utils/sleep");
const zeebeClient_1 = require("../../utils/zeebeClient");
c8Run_8_6_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, apiHelpers_1.authC8runAPI)('demo', 'demo');
    await (0, sleep_1.sleep)(5000);
});
c8Run_8_6_1.test.describe('API tests', () => {
    c8Run_8_6_1.test.use({ storageState: 'utils/.auth' });
    (0, c8Run_8_6_1.test)('Search for process definitions', async ({ request }) => {
        const processDefinitionsList = await request.post('/v1/process-definitions/search');
        await (0, apiHelpers_1.assertResponseStatus)(processDefinitionsList, 200);
    });
    (0, c8Run_8_6_1.test)('Get a process definition via key', async ({ request }) => {
        const searchProcessDefinitions = await request.post('/v1/process-definitions/search');
        const processKey = await searchProcessDefinitions.json();
        const response = await request.get('/v1/process-definitions/' + processKey.items[1].key);
        await (0, apiHelpers_1.assertResponseStatus)(response, 200);
    });
    (0, c8Run_8_6_1.test)('Search for process instances', async ({ request }) => {
        const processInstancesList = await request.post('/v1/process-instances/search');
        await (0, apiHelpers_1.assertResponseStatus)(processInstancesList, 200);
    });
    (0, c8Run_8_6_1.test)('Search for flownode-instances', async ({ request }) => {
        const flowNodeInstancesList = await request.post('/v1/flownode-instances/search');
        await (0, apiHelpers_1.assertResponseStatus)(flowNodeInstancesList, 200);
    });
    (0, c8Run_8_6_1.test)('Search for variables for process instancess', async ({ request }) => {
        const variablesInstancesList = await request.post('/v1/variables/search');
        await (0, apiHelpers_1.assertResponseStatus)(variablesInstancesList, 200);
    });
    (0, c8Run_8_6_1.test)('Search for incidents', async ({ request }) => {
        const incidentsList = await request.post('/v1/incidents/search');
        await (0, apiHelpers_1.assertResponseStatus)(incidentsList, 200);
    });
    (0, c8Run_8_6_1.test)('Get connectors status', async ({ request }) => {
        const connectorsStatus = await request.get(process.env.C8RUN_CONNECTORS_API_URL + '/actuator/health');
        await (0, apiHelpers_1.assertResponseStatus)(connectorsStatus, 200);
    });
    (0, c8Run_8_6_1.test)('Get a inbound connectors list', async ({ request }) => {
        const connectorsInboundList = await request.get(process.env.C8RUN_CONNECTORS_API_URL + '/inbound');
        await (0, apiHelpers_1.assertResponseStatus)(connectorsInboundList, 200);
    });
    (0, c8Run_8_6_1.test)('Search for tasks', async ({ request }) => {
        const taskList = await request.post('/v1/tasks/search');
        await (0, apiHelpers_1.assertResponseStatus)(taskList, 200);
    });
    (0, c8Run_8_6_1.test)('Get a task via ID', async ({ request }) => {
        const searchTasks = await request.post('/v1/tasks/search');
        const taskID = await searchTasks.json();
        const response = await request.get('/v1/tasks/' + taskID[1].id);
        await (0, apiHelpers_1.assertResponseStatus)(response, 200);
    });
});
