from services.staff_credit_html_export_service import StaffCreditHtmlExportService


class FakeStaffRepository:
    def select_active_staff_identities(self):
        return [
            {"staff_name": "张三", "staff_id_card": "110101199001010011"},
            {"staff_name": "李四", "staff_id_card": "110101199202023456"},
        ]


def test_export_should_write_one_html_per_staff(tmp_path):
    service = StaffCreditHtmlExportService(FakeStaffRepository())

    generated_files = service.export(tmp_path)

    assert len(generated_files) == 2
    first_html = generated_files[0].read_text(encoding="utf-8")
    second_html = generated_files[1].read_text(encoding="utf-8")

    assert generated_files[0].name == "0001_张三_0011.html"
    assert generated_files[1].name == "0002_李四_3456.html"
    assert 'meta name="ccdi-staff-name" content="张三"' in first_html
    assert 'meta name="ccdi-staff-id-card" content="110101199001010011"' in first_html
    assert "姓名：李四" in second_html
    assert "身份证号：110101199202023456" in second_html
