"""Unit tests for pos_excel_parser."""
import pytest
from datetime import date, time
from decimal import Decimal
from app.utils.pos_excel_parser import parse_dispenser, validate_produk_match


class TestParseDispenser:
    def test_pulau_with_mix_suffix(self):
        island, nozzle = parse_dispenser("PULAU 1 - A2 MIX")
        assert island == "PULAU 1"
        assert nozzle == "A2"

    def test_pulau_without_mix_suffix(self):
        island, nozzle = parse_dispenser("PULAU 3 - A1")
        assert island == "PULAU 3"
        assert nozzle == "A1"

    def test_no_dash_returns_raw(self):
        island, nozzle = parse_dispenser("PULAU 1")
        assert island == "PULAU 1"
        assert nozzle is None

    def test_strips_whitespace(self):
        island, nozzle = parse_dispenser("  PULAU 2 - B1 MIX  ")
        assert island == "PULAU 2"
        assert nozzle == "B1"


class TestValidateProdukMatch:
    def test_pertalite_matches_ron90(self):
        assert validate_produk_match("PERTALITE", "RON90") is True

    def test_biosolar_matches_cn48(self):
        assert validate_produk_match("BIO_SOLAR", "CN48") is True

    def test_mismatch_raises(self):
        with pytest.raises(ValueError, match="mismatch"):
            validate_produk_match("PERTALITE", "CN48")

    def test_case_insensitive(self):
        assert validate_produk_match("pertalite", "RON90") is True
