from app_new import db
from app_new.core.models.equipment import Equipment
from app_new.core.services.equipment_creation import create_equipment


def test_equipment_creation_accepts_missing_lot_and_preserves_identity(app):
    with app.app_context():
        equipment = create_equipment(
            name="TEST_UI_020_EQUIPMENT_NO_LOT",
            quantity=12,
            is_group=True,
            create_schedule=False,
        )
        db.session.commit()
        assert equipment.id is not None
        assert equipment.lot_id is None
        assert equipment.quantity == 12
        assert db.session.get(Equipment, equipment.id) is equipment


def test_equipment_creation_returns_distinct_objects_for_duplicate_names(app):
    with app.app_context():
        first = create_equipment(name="TEST_UI_020_DUPLICATE", create_schedule=False)
        second = create_equipment(name="TEST_UI_020_DUPLICATE", create_schedule=False)
        db.session.commit()
        assert first.id != second.id
