"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const c8Run_8_7_1 = require("../../fixtures/c8Run-8.7");
const UtilitiesPage_1 = require("../../pages/c8Run-8.7/UtilitiesPage");
const _setup_1 = require("../../test-setup.js");
const zeebeClient_1 = require("../../utils/zeebeClient");
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
const constants_1 = require("../../utils/constants");
c8Run_8_7_1.test.beforeAll(async () => {
    await Promise.all([
        (0, zeebeClient_1.deploy)('./resources/Basic_Auth_REST_Connector.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/Intermediate_Event_Webhook_Connector_No_Auth_Process.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/Start_Event_Webhook_Connector_No_Auth_Process.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/REST_Connector_Bearer_Auth_Process.bpmn'),
        (0, zeebeClient_1.deploy)('./resources/REST_Connector_No_Auth_Process.bpmn'),
    ]);
    await Promise.all([
        (0, zeebeClient_1.createInstances)('REST_Connector_Basic_Auth_Process', 1, 1),
        (0, zeebeClient_1.createInstances)('Intermediate_Event_Webhook_Connector_No_Auth_Process', 1, 1),
        (0, zeebeClient_1.createInstances)('REST_Connector_No_Auth_Process', 1, 1),
        (0, zeebeClient_1.createInstances)('REST_Connector_Bearer_Auth_Process', 1, 1),
    ]);
});
c8Run_8_7_1.test.beforeEach(async ({ page, operateLoginPage, operateHomePage }) => {
    await (0, UtilitiesPage_1.navigateToApp)(page, 'operate');
    await operateLoginPage.login('demo', 'demo');
    await operateHomePage.operateBannerIsVisible();
});
c8Run_8_7_1.test.describe('Connectors User Flow Tests', () => {
    c8Run_8_7_1.test.afterEach(async ({ page }, testInfo) => {
        await (0, _setup_1.captureScreenshot)(page, testInfo);
        await (0, _setup_1.captureFailureVideo)(page, testInfo);
    });
    (0, c8Run_8_7_1.test)('REST Connector No Auth User Flow', async ({ operateHomePage, operateProcessInstancePage, operateProcessesPage, }) => {
        await c8Run_8_7_1.test.step('View Process Instance in Operate, assert it completes and assert result expression', async () => {
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 180000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink('REST_Connector_No_Auth_Process');
            await operateProcessInstancePage.completedIconAssertion();
            await (0, test_1.expect)(operateProcessInstancePage.statusVariable).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(operateProcessInstancePage.statusVariable.getByText('"Awesome!"')).toBeVisible({
                timeout: 60000,
            });
        });
    });
    (0, c8Run_8_7_1.test)('REST Connector Basic Auth User Flow', async ({ operateHomePage, operateProcessesPage, operateProcessInstancePage, }) => {
        await c8Run_8_7_1.test.step('View Process Instance in Operate, assert it completes and assert result expression', async () => {
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 180000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink('REST_Connector_Basic_Auth_Process');
            await operateProcessInstancePage.completedIconAssertion();
            await (0, test_1.expect)(operateProcessInstancePage.variablesList).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(operateProcessInstancePage.messageVariable.getByText('"Awesome!"')).toBeVisible({
                timeout: 60000,
            });
        });
    });
    (0, c8Run_8_7_1.test)('REST Connector Bearer Token Auth User Flow', async ({ operateHomePage, operateProcessInstancePage, operateProcessesPage, }) => {
        await c8Run_8_7_1.test.step('View Process Instance in Operate, assert it completes and assert result expression', async () => {
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 180000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink('REST_Connector_Bearer_Auth_Process');
            await operateProcessInstancePage.completedIconAssertion();
            await (0, test_1.expect)(operateProcessInstancePage.variablesList).toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(operateProcessInstancePage.messageVariable.getByText('"Awesome!"')).toBeVisible({
                timeout: 60000,
            });
        });
    });
    (0, c8Run_8_7_1.test)('Start Event Webhook Connector No Auth User Flow', async ({ request, operateHomePage, operateProcessInstancePage, operateProcessesPage, }) => {
        await c8Run_8_7_1.test.step('Make Authorization Request', async () => {
            await (0, sleep_1.sleep)(300000);
            await (0, test_1.expect)(async () => {
                const response = await request.get(process.env.C8RUN_CONNECTORS_API_URL + '/inbound/test-webhook-id');
                await (0, test_1.expect)(response.status()).toBe(200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
        await c8Run_8_7_1.test.step('Assert Diagram Has Successfully Completed in Operate', async () => {
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 120000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink('Start_Event_Webhook_Connector_No_Auth_Process');
            await operateProcessInstancePage.completedIconAssertion();
        });
    });
    (0, c8Run_8_7_1.test)('Intermediate Event Webhook Connector No Auth User Flow', async ({ request, operateHomePage, operateProcessInstancePage, operateProcessesPage, }) => {
        const postWebhook = async () => {
            const response = await request.post(process.env.C8RUN_CONNECTORS_API_URL +
                '/inbound/test-webhook-intermediate', {
                data: {
                    test: 'test',
                },
            });
            await (0, test_1.expect)(response.status()).toBe(200);
        };
        await c8Run_8_7_1.test.step('Make Authorization Request', async () => {
            await (0, sleep_1.sleep)(60000);
            await (0, test_1.expect)(postWebhook).toPass(constants_1.defaultAssertionOptions);
        });
        await c8Run_8_7_1.test.step('Assert Diagram Has Successfully Completed in Operate', async () => {
            await (0, test_1.expect)(operateHomePage.processesTab).toBeVisible({ timeout: 120000 });
            await operateHomePage.clickProcessesTab();
            await operateProcessesPage.clickProcessCompletedCheckbox();
            await operateProcessesPage.clickProcessInstanceLink('Intermediate_Event_Webhook_Connector_No_Auth_Process');
            await operateProcessInstancePage.completedIconAssertion(postWebhook);
        });
    });
});
