feat(e2e): #145 Playwright dashboard tests with mock Telegram auth
- Add Playwright-based E2E tests in tests/e2e/dashboard/ - Authenticate via /auth/telegram-webapp using helpers/telegram_init_data.py - Cover dashboard load and session edit flow - Add requirements.txt and package dashboard folder - Update README with setup and test descriptions Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+64
-54
@@ -1,71 +1,81 @@
|
||||
# GmRelay E2E Tests
|
||||
|
||||
This directory contains end-to-end tests that run **locally** against real Telegram infrastructure and the GmRelay Web dashboard. They are intentionally **not part of CI** because they require:
|
||||
This module contains locally-run end-to-end tests for the GmRelay Telegram bot and Blazor/Web dashboard.
|
||||
It is deliberately **not** wired into CI because it requires real Telegram infrastructure (MTProto user client) and a running Web instance.
|
||||
|
||||
- a real Telegram test user account;
|
||||
- `api_id` / `api_hash` from https://my.telegram.org;
|
||||
- a pre-authenticated MTProto session;
|
||||
- a running PostgreSQL, GmRelay.Bot, and GmRelay.Web.
|
||||
## Status
|
||||
|
||||
Tracked as a Gitea milestone: [E2E Automation](https://git.codeanddice.ru/toutsu/GmRelayBot/issues?state=open&milestone=...) <!-- update milestone link manually -->
|
||||
|
||||
| Issue | Title | Status |
|
||||
|-------|-------|--------|
|
||||
| #144 | initData / Login Widget helper for mock Telegram auth | ✅ Done |
|
||||
| #145 | Playwright tests for Blazor dashboard with mocked Telegram auth | 🚧 In progress |
|
||||
| #146 | Telegram user client (MTProto) | ⏳ Planned |
|
||||
| #147 | Automate group creation and bot invitation | ⏳ Planned |
|
||||
| #148 | Scenario: /newsession from creation to publication | ⏳ Planned |
|
||||
| #149 | Join/leave, waitlist, reschedule and notification scenarios | ⏳ Planned |
|
||||
| #150 | Dashboard display and editing verification | ⏳ Planned |
|
||||
| #151 | Console runner and cleanup | ⏳ Planned |
|
||||
|
||||
## Structure
|
||||
|
||||
```text
|
||||
tests/e2e/
|
||||
├── README.md # this file
|
||||
├── README.md
|
||||
├── requirements.txt
|
||||
├── .gitignore
|
||||
├── helpers/
|
||||
│ ├── telegram_init_data.py # generate valid Telegram initData / Login Widget payloads
|
||||
│ └── test_telegram_init_data.py # unit tests for the helper
|
||||
└── ... (runner and scenarios will land here)
|
||||
│ ├── telegram_init_data.py # Build valid Telegram auth payloads
|
||||
│ ├── test_telegram_init_data.py # Self-contained sanity tests for the helper
|
||||
│ └── __init__.py
|
||||
└── dashboard/
|
||||
├── test_dashboard_auth_and_sessions.py # Playwright tests for the Blazor dashboard
|
||||
└── __init__.py
|
||||
```
|
||||
|
||||
## `telegram_init_data.py`
|
||||
|
||||
A small Python helper that produces Telegram Mini App `initData` and Login Widget payloads with valid HMAC-SHA256 signatures. It mirrors `GmRelay.Shared.Telegram.TelegramAuthPayloadBuilder`.
|
||||
|
||||
Use it to open the Blazor/Mini App dashboard in Playwright without logging into Telegram:
|
||||
|
||||
```python
|
||||
from helpers.telegram_init_data import build_mini_app_init_data
|
||||
|
||||
init = build_mini_app_init_data(
|
||||
bot_token="YOUR_BOT_TOKEN",
|
||||
telegram_id=424242,
|
||||
first_name="Test",
|
||||
username="tester")
|
||||
|
||||
await page.goto(f"https://localhost:8080/#tgWebAppData={init.init_data_raw}")
|
||||
```
|
||||
|
||||
## C# equivalent
|
||||
|
||||
For tests inside the solution, use `GmRelay.Shared.Telegram.TelegramAuthPayloadBuilder`:
|
||||
|
||||
```csharp
|
||||
var init = TelegramAuthPayloadBuilder.BuildMiniAppInitData(
|
||||
botToken: "YOUR_BOT_TOKEN",
|
||||
telegramId: 424242L,
|
||||
firstName: "Test",
|
||||
username: "tester");
|
||||
|
||||
// init.InitDataRaw is a valid initData string.
|
||||
```
|
||||
|
||||
## Running the helper tests
|
||||
## Install dependencies
|
||||
|
||||
```bash
|
||||
cd tests/e2e/helpers
|
||||
python -m pytest test_telegram_init_data.py -v
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
||||
pip install -r tests/e2e/requirements.txt
|
||||
playwright install chromium
|
||||
```
|
||||
|
||||
## Roadmap
|
||||
## Run helper tests
|
||||
|
||||
See the Gitea milestone **[Этап — E2E-тестирование Telegram + Web](https://git.codeanddice.ru/Toutsu/GmRelayBot/milestone/13)** and its issues:
|
||||
```bash
|
||||
python tests/e2e/helpers/test_telegram_init_data.py
|
||||
```
|
||||
|
||||
- [#144](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/144) initData helper ✅ (this directory)
|
||||
- [#145](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/145) Playwright dashboard tests
|
||||
- [#146](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/146) MTProto test user client
|
||||
- [#147](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/147) Group creation automation
|
||||
- [#148](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/148) `/newsession` scenario
|
||||
- [#149](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/149) join/leave/waitlist/reschedule scenarios
|
||||
- [#150](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/150) Web dashboard round-trip verification
|
||||
- [#151](https://git.codeanddice.ru/Toutsu/GmRelayBot/issues/151) Console runner + cleanup
|
||||
## Run Playwright dashboard tests
|
||||
|
||||
1. Start the Web dashboard (and PostgreSQL) locally. The fastest way:
|
||||
```bash
|
||||
dotnet run --project src/GmRelay.AppHost/GmRelay.AppHost.csproj
|
||||
```
|
||||
2. Export environment variables that match the running Web instance:
|
||||
```bash
|
||||
export GMRELAY_E2E_BASE_URL="http://localhost:8080"
|
||||
export GMRELAY_E2E_BOT_TOKEN="<same-token-as-web>"
|
||||
export GMRELAY_E2E_TELEGRAM_ID="9000000001"
|
||||
export GMRELAY_E2E_DATABASE_URL="Host=localhost;Database=gmrelay;Username=postgres;Password=<password>"
|
||||
```
|
||||
3. Run the tests:
|
||||
```bash
|
||||
python tests/e2e/dashboard/test_dashboard_auth_and_sessions.py
|
||||
```
|
||||
|
||||
## What the dashboard tests cover
|
||||
|
||||
- `test_dashboard_authenticates_and_shows_groups`
|
||||
Builds a valid Mini App initData payload, posts it to `/auth/telegram-webapp`, and verifies that the Blazor home page renders the authenticated greeting.
|
||||
- `test_dashboard_session_edit_flow`
|
||||
Seeds a player, group, and session directly in PostgreSQL, opens the group details page, clicks through to the session editor, changes the title, and asserts the updated title appears on the page.
|
||||
|
||||
## Notes
|
||||
|
||||
- Authentication is mocked using `helpers/telegram_init_data.py`, which mirrors `GmRelay.Shared.Telegram.TelegramAuthPayloadBuilder`.
|
||||
- The Web instance validates HMAC-SHA256 with the same bot token, so the test payload is indistinguishable from a real Telegram Mini App payload.
|
||||
- For headful debugging, change `headless=True` to `headless=False` in the test file.
|
||||
|
||||
Reference in New Issue
Block a user