from db.master_channel_mapping_matrix import _matrix_row


def test_matrix_row_match_flags():
    aliases = {"magento": {}, "shopify": {}, "plytix": {}}
    registry = {
        "magento": {"sku", "name"},
        "shopify": {"shopify_stock_keeping_unit", "title"},
        "plytix": {"sku"},
    }
    row = _matrix_row(
        "sku",
        {
            "master_attribute_code": "sku",
            "magento": "sku",
            "shopify": "shopify_stock_keeping_unit",
            "plytix": "sku",
        },
        aliases,
        registry,
    )
    assert row["master"] == "sku"
    assert row["magento"] == "sku"
    assert row["magento_is_match"] == 1
    assert row["shopify"] == "shopify_stock_keeping_unit"
    assert row["shopify_is_match"] == 1
    assert row["plytix_is_match"] == 1


def test_matrix_row_unmapped_channel_is_zero():
    row = _matrix_row(
        "cabinet_width",
        {"master_attribute_code": "cabinet_width", "magento": "cabinet_width", "shopify": "", "plytix": ""},
        {"magento": {}, "shopify": {}, "plytix": {}},
        {"magento": {"cabinet_width"}, "shopify": set(), "plytix": set()},
    )
    assert row["magento_is_match"] == 1
    assert row["shopify_is_match"] == 0
    assert row["plytix_is_match"] == 0
