package com.fiuu.xdk.reactnative;

import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 28)
public class PaymentModeHandlerTest {

    @Test
    public void validate_acceptsStandardMode() throws Exception {
        JSONObject obj = new JSONObject("{\"mp_payment_mode\":\"standard\"}");
        assertNull(PaymentModeHandler.validate(obj));
        assertFalse(PaymentModeHandler.isGooglePay("standard"));
    }

    @Test
    public void validate_acceptsGooglePayMode() throws Exception {
        JSONObject obj = new JSONObject("{\"mp_payment_mode\":\"google_pay\"}");
        assertNull(PaymentModeHandler.validate(obj));
        assertTrue(PaymentModeHandler.isGooglePay("google_pay"));
    }

    @Test
    public void validate_rejectsMissingMode() throws Exception {
        JSONObject obj = new JSONObject("{}");
        assertEquals(
                "Missing or invalid payment mode: mp_payment_mode must be \"standard\" or \"google_pay\".",
                PaymentModeHandler.validate(obj)
        );
    }

    @Test
    public void validate_rejectsUnsupportedMode() throws Exception {
        JSONObject obj = new JSONObject("{\"mp_payment_mode\":\"apple_pay\"}");
        assertEquals(
                "Unsupported payment mode \"apple_pay\". Use \"standard\" or \"google_pay\".",
                PaymentModeHandler.validate(obj)
        );
    }
}
