from pathlib import Path


LISTING = Path("frontend/src/views/dataGovernance/dataSource/index.vue")
EDITOR = Path(
    "frontend/src/views/dataGovernance/dataSource/components/edit.vue"
)
API = Path("frontend/src/api/dataOrigin.js")


def test_datasource_ui_does_not_render_or_replay_stored_credentials():
    listing = LISTING.read_text(encoding="utf-8")
    editor = EDITOR.read_text(encoding="utf-8")

    assert "value: 'username'" not in listing
    assert "value: 'param'" not in listing
    assert "credential_configured" in listing
    assert "Object.assign(this.formValues, this.itemData)" not in editor
    assert "datasourceParse" not in editor
    assert "key: 'param'" not in editor
    assert "value: 'postgresql'" in editor
    assert "value: 'mysql'" in editor


def test_datasource_ui_uses_uid_and_omits_blank_credentials():
    listing = LISTING.read_text(encoding="utf-8")
    editor = EDITOR.read_text(encoding="utf-8")
    api = API.read_text(encoding="utf-8")

    assert "handleDelete(item.uid)" in listing
    assert "data.uid = this.itemData.uid" in listing
    assert "delete payload.username" in editor
    assert "delete payload.password" in editor
    assert "datasourceParse" not in api
