package cz.moneta.test.regression.cvm.api.cvm;

import com.fasterxml.jackson.databind.JsonNode;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;

import java.util.UUID;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@TestScenario(name = "Call API error-not-found-trigger to WSO2 and assert response parameters")
public class ApiErrorNotFoundTrigger {

    public static final String ERROR_NOT_FOUND_TRIGGER_PATH = "cvm.cluster/error-not-found-trigger/1.0.0";

    @TestCase(name = "Call API error-not-found-trigger to WSO2", environments = {TST1, PPE})
    public void postErrorNotFoundTrigger(Harness harness) {
        JsonNode message = harness.tasks().wso2().restRequest().prepareRequestFromCvm(ERROR_NOT_FOUND_TRIGGER_PATH, false,
                "{\n" +
                        "    \"version\": 1,\n" +
                        "    \"clientTimeZone\": \"Europe/Prague\",\n" +
                        "    \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                        "    \"inputs\": {\n" +
                        "    }\n" +
                        "}")
                .post()
                .andAssertStatus(404)
                .extract("message");

        assertNotNull(message);
        assertEquals("No decision definition with id \"ErrorNotFoundTrigger\" found. Please ensure a decision flow associated with the " +
                "decision definition \"ErrorNotFoundTrigger\" is active.", message.asText());
    }

}

