package com.ruoyi.app.omgpay;

import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class OmgQueryResponseParserTest {
    private final OmgQueryResponseParser parser = new OmgQueryResponseParser();

    @Test
    void preservesEveryActualFieldIncludingUnknownAndEmptyValues() {
        Map<String, String> fields = parser.parse(
                "MerchantTradeNo=OMG123&PaymentDate=&FutureField=A%26B&");

        assertEquals("OMG123", fields.get("MerchantTradeNo"));
        assertEquals("", fields.get("PaymentDate"));
        assertEquals("A&B", fields.get("FutureField"));
    }

    @Test
    void rejectsDuplicateMalformedAndOversizedResponses() {
        assertThrows(IllegalArgumentException.class,
                () -> parser.parse("TradeStatus=1&TradeStatus=0"));
        assertThrows(IllegalArgumentException.class,
                () -> parser.parse("TradeStatus=1&broken"));
        assertThrows(IllegalArgumentException.class,
                () -> parser.parse("TradeStatus=%ZZ"));
        assertThrows(IllegalArgumentException.class,
                () -> parser.parse("a=" + "x".repeat(OmgQueryResponseParser.MAX_RESPONSE_CHARS)));
    }
}
