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 Isds Databox Search")
public class ApiIsdsDataboxSearch {
    ObjectNode objectNode;
    String inputData;

    @TestCase(name = "/public/isds/databox/search", environments = {TST1})
    @JiraTestCase(id = "BOC-T8657")
    public void messagePublicIsdsDataboxSearch(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromUfo("/t/backoffice.cluster/exe-isds-search/v1")
                .withPayloadFromFile("regression/exevido/api/isdsDataboxSearch.json")
                .post();
        inputData = response.getPayload();
        objectNode = response
                .andAssertStatus(200)
                .andAssertFieldValue("isdsStatus", "OK")
                .andAssertFieldValue("isdsStatusMessage", "Provedeno úspěšně.")
                .mapResponseIntoObject(ObjectNode.class);
    }

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

    }
}
