"use strict";
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const c8Run_8_7_1 = require("../../fixtures/c8Run-8.7");
const apiHelpers_1 = require("../../utils/apiHelpers");
const zeebeClient_1 = require("../../utils/zeebeClient");
const test_1 = require("@playwright/test");
const UtilitiesPage_1 = require("../../pages/c8Run-8.7/UtilitiesPage");
const sleep_1 = require("../../utils/sleep");
const constants_1 = require("../../utils/constants");
const _setup_1 = require("../../test-setup.js");
const operateBaseURL = (0, UtilitiesPage_1.getBaseAppUrl)('operate');
if (process.env.RUN_AS_DOCKER_COMPOSE == 'true') {
    c8Run_8_7_1.test.beforeAll(async () => {
        await Promise.all([
            (0, zeebeClient_1.deploy)('./resources/User_Task_Process_With_Form_API.bpmn'),
            (0, zeebeClient_1.deploy)('./resources/New Form.form'),
        ]);
        await Promise.all([(0, zeebeClient_1.createInstances)('Form_User_Task_API', 1, 3)]);
        await (0, sleep_1.sleep)(5000);
    });
    let operateToken = '';
    c8Run_8_7_1.test.describe('Operate API tests', () => {
        c8Run_8_7_1.test.use({
            baseURL: operateBaseURL,
        });
        c8Run_8_7_1.test.beforeEach(async ({ page, identityLoginPage, identityHomePage, request }) => {
            await (0, UtilitiesPage_1.navigateToApp)(page, 'identity');
            await identityLoginPage.login('demo', 'demo');
            await identityHomePage.assignPermissionToOperateAPI();
            operateToken = await (0, UtilitiesPage_1.getAccessTokenFor)(request, 'operate');
        });
        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)('Search for process definitions', async ({ request }) => {
            await (0, test_1.expect)(async () => {
                const response = await request.post('/v1/process-definitions/search', {
                    headers: {
                        Authorization: `Bearer ${operateToken}`,
                        'Content-Type': 'application/json',
                    },
                });
                await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
        (0, c8Run_8_7_1.test)('Get a process definition via key', async ({ request }) => {
            await (0, test_1.expect)(async () => {
                const searchResponse = await request.post('/v1/process-definitions/search', {
                    headers: {
                        Authorization: `Bearer ${operateToken}`,
                        'Content-Type': 'application/json',
                    },
                });
                await (0, apiHelpers_1.assertResponseStatus)(searchResponse, 200);
                const processKey = await searchResponse.json();
                const response = await request.get('/v1/process-definitions/' + processKey.items[0].key, {
                    headers: {
                        Authorization: `Bearer ${operateToken}`,
                        'Content-Type': 'application/json',
                    },
                });
                await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
        (0, c8Run_8_7_1.test)('Search for process instances', async ({ request }) => {
            await (0, test_1.expect)(async () => {
                const response = await request.post('/v1/process-instances/search', {
                    headers: {
                        Authorization: `Bearer ${operateToken}`,
                        'Content-Type': 'application/json',
                    },
                });
                await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
        (0, c8Run_8_7_1.test)('Search for flownode-instances', async ({ request }) => {
            await (0, test_1.expect)(async () => {
                const response = await request.post('/v1/flownode-instances/search', {
                    headers: {
                        Authorization: `Bearer ${operateToken}`,
                        'Content-Type': 'application/json',
                    },
                });
                await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
        (0, c8Run_8_7_1.test)('Search for variables for process instancess', async ({ request }) => {
            await (0, test_1.expect)(async () => {
                const response = await request.post('/v1/variables/search', {
                    headers: {
                        Authorization: `Bearer ${operateToken}`,
                        'Content-Type': 'application/json',
                    },
                });
                await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
        (0, c8Run_8_7_1.test)('Search for incidents', async ({ request }) => {
            await (0, test_1.expect)(async () => {
                const response = await request.post('/v1/incidents/search', {
                    headers: {
                        Authorization: `Bearer ${operateToken}`,
                        'Content-Type': 'application/json',
                    },
                });
                await (0, apiHelpers_1.assertResponseStatus)(response, 200);
            }).toPass(constants_1.defaultAssertionOptions);
        });
    });
}
