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 cz.moneta.test.harness.support.rest.RawRestRequest;
import org.junit.jupiter.api.Assertions;

import java.util.List;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Call API RTRD_SMS_Response to WSO2 and assert response parameters")
public class ApiRtrdSmsResponse {

    @TestCase(name = "Call API RTRD_SMS_Response to WSO2", environments = {TST1, PPE})
    public void postRtrdSmsResponse(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCvm(
                "cvm.cluster/RTRD_SMS_Response/001", false,
                "{\n" +
                        "    \"phoneNumber\": \"123454321\",\n" +
                        "    \"smsText\": \"zprava dne4\"\n" +
                        "}")
                .postExtended()
                .andAssertStatus(200);

        JsonNode result = response.extract("result");
        List<Object> activityIds = response.getHeader("activityId");

        Assertions.assertNotNull(result, "Not found result in response");
        Assertions.assertEquals("OK", result.textValue(), "Not found OK in result in response");
        Assertions.assertEquals(1, activityIds.size(), "API should return activityId header");

    }
}