import csv
import io

from fastapi import status
from fastapi.testclient import TestClient


class TestUsersImportTemplateGet:
    PATH = "/v1/users/import/template"

    def test_returns_csv_template(self, test_client: TestClient) -> None:
        """テンプレートCSVをダウンロードできることを確認する。"""
        response = test_client.get(url=self.PATH)

        assert response.status_code == status.HTTP_200_OK
        assert response.headers["content-type"] == "text/csv; charset=utf-8"
        assert 'filename="user_import_template.csv"' in response.headers["content-disposition"]

        rows = list(csv.reader(io.StringIO(response.text.removeprefix("\ufeff"))))
        assert rows == [["ID", "名称", "メールアドレス"]]
