# Copyright 2026 - Today Criptomart
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests import tagged
from odoo.tests.common import TransactionCase

from ..models.pos_payment_method import CASHDRO_FIELDS


@tagged("post_install", "-at_install")
class TestLoadPosDataFields(TransactionCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.payment_method = cls.env["pos.payment.method"]
        # Nothing dereferences it, but we pass a real config when there's one
        cls.config_id = cls.env["pos.config"].search([], limit=1).id

    def test_cashdro_credentials_are_loaded(self):
        """The front end can't build the CashDro url without them."""
        fields = self.payment_method._load_pos_data_fields(self.config_id)
        for field in CASHDRO_FIELDS:
            self.assertIn(field, fields)

    def test_no_duplicated_fields(self):
        """Once the base module is fixed upstream we must not add them twice."""
        fields = self.payment_method._load_pos_data_fields(self.config_id)
        self.assertEqual(sorted(fields), sorted(set(fields)))

    def test_fields_exist_on_the_model(self):
        """Guard against a rename of the credentials in the base module."""
        for field in CASHDRO_FIELDS:
            self.assertIn(field, self.payment_method._fields)
