package cz.moneta.test.sanity.transactional.cards.firstvision;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.Environment;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.rest.RawRestRequest;
import cz.moneta.test.sanity.transactional.SmokeData;

import static cz.moneta.test.sanity.transactional.cards.firstvision.MESSAGE.*;

@TestScenario(name = "R3 VMX.EMB.CARDACTION.UPD E8V4")
public class ActionUpd {

    @TestCase(environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    @JiraTestCase(id = "FVP-T1920")
    public void VMX_EMB_CARDACTION_UPD(Harness harness) {
        String card = SmokeData.getInstance(harness).getCreditData().getCard();
        RawRestRequest.Response response = harness.withWso2()
                .prepareRequest()
                .withPath(FV)
                .withPojoPayload(new MESSAGE("VMX.EMB.CARDACTION.UPD", "E8V4"))
                .addField(VMX_MSGIN, "CRD_NBR", card)
                .addField(VMX_MSGIN, "ACTN", "0")
                .postExtended()
                .andAssertStatus(200);
        if ("P".equals(response.extract(SVC_RETURN).textValue())) {
            response.andAssertFieldValue(VMX_MSGOUT + ".CRD_NBR", card);
        } else {  //in case if test is run more times before ATRF batch
            response.andAssertFieldValue(VMX_MSGOUT + ".RC_DATA.RETURN_DESC",
                    "CARD ACTION CHANGE NOT ALLOWED DUE TO PENDING CARD ACTION");
        }
    }
}
