package cz.moneta.test.system.aresapi;

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;

@TestScenario
public class AresApiTest {

    @TestCase(name = "Call POST Ares Api and extract random ico from response")
    public void testAresPostApi(Harness harness) {
        JsonNode jsonNode = harness.withAresApi()
                .prepareRequest()
                .withPath("ekonomicke-subjekty/vyhledat")
                .withHeader("Content-Type", "application/json")
                .withPayloadFromFile("regression/aresapi/aresSearch.json")
                .post()
                .andAssertStatus(200)
                .extract("ekonomickeSubjekty");

        int randomIndex = (int) (Math.random() * jsonNode.size());
        String randIco = jsonNode.get(randomIndex).get("ico").toPrettyString().replaceAll("\"", "");
        harness.log("Random ico: " + randIco);
    }
}
