38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[4]
|
|
BACKEND_ROOT = REPO_ROOT / "apps" / "backend"
|
|
sys.path.insert(0, str(BACKEND_ROOT))
|
|
|
|
from src.presentation.main import app # noqa: E402
|
|
|
|
|
|
class GeneratedContractArtifactsTest(unittest.TestCase):
|
|
def test_openapi_snapshot_matches_backend_openapi(self) -> None:
|
|
snapshot_path = REPO_ROOT / "packages" / "shared" / "openapi.json"
|
|
snapshot = json.loads(snapshot_path.read_text(encoding="utf-8"))
|
|
|
|
self.assertEqual(app.openapi(), snapshot)
|
|
|
|
def test_typescript_types_are_marked_generated(self) -> None:
|
|
types_path = REPO_ROOT / "packages" / "shared" / "src" / "api-types.ts"
|
|
content = types_path.read_text(encoding="utf-8")
|
|
|
|
self.assertTrue(
|
|
content.startswith(
|
|
"// Generated from backend OpenAPI by "
|
|
"scripts/generate_openapi_contracts.py."
|
|
)
|
|
)
|
|
self.assertIn("export type ArticleCreateRequest", content)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|