package cz.moneta.test.regression.backoffice.exevido.api;

import com.fasterxml.jackson.databind.node.ObjectNode;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import cz.moneta.test.harness.support.rest.RawRestRequest;
import org.junit.jupiter.api.AfterEach;

import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenarioWithOrder(name = "Api Exe Message Search")
public class ApiExeMessageSearch {
    ObjectNode objectNode;
    String inputData;

    @TestCase(name = "exe-message-search", environments = {TST1})
    @JiraTestCase(id = "BOC-T8656")
    public void exeMessageSearch(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromUfo("/t/backoffice.cluster/exe-message-search/v1")
                .withPayloadFromFile("regression/exevido/api/exeMessage.json")
                .post();
        inputData = response.getPayload();
        objectNode = response
                .andAssertStatus(200)
                .andAssertFieldValue("paginate_max", "10")
                .mapResponseIntoObject(ObjectNode.class);
    }

    @AfterEach
    protected void teardown(Harness harness) {
        harness.store(JIRA_COMMENT_STORE_KEY,
                "\nVstup: " + inputData + "\nVýstup: \n " + objectNode.toPrettyString());

    }
}