Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a679ca4e77 | ||
|
|
871d7167e2 | ||
|
|
8fce00f1e1 | ||
|
|
17f7ed7370 | ||
|
|
361e2d9b61 | ||
|
|
73c88678dc | ||
|
|
e8a8d9f11e | ||
|
|
7d52b0232b | ||
|
|
95058b2d3c | ||
|
|
8a78368458 |
+1
-1
@@ -283,7 +283,7 @@
|
|||||||
| wrong_because | character varying | YES | |
|
| wrong_because | character varying | YES | |
|
||||||
| edited_at | timestamp without time zone | YES | |
|
| edited_at | timestamp without time zone | YES | |
|
||||||
|
|
||||||
## sentence_hints_used
|
## sentence_hints_used ⚠️ устаревшая (не используется)
|
||||||
|
|
||||||
| Колонка | Тип | NULL | Default |
|
| Колонка | Тип | NULL | Default |
|
||||||
|---------|-----|------|---------|
|
|---------|-----|------|---------|
|
||||||
|
|||||||
+12
-12
@@ -341,10 +341,10 @@ ACHIEVEMENTS_DATA = [
|
|||||||
"desc_pl": "Ukończ poziom bez podpowiedzi", "desc_ru": "Пройти уровень без подсказок", "desc_uk": "Пройти рівень без підказок", "desc_en": "Complete a level without hints",
|
"desc_pl": "Ukończ poziom bez podpowiedzi", "desc_ru": "Пройти уровень без подсказок", "desc_uk": "Пройти рівень без підказок", "desc_en": "Complete a level without hints",
|
||||||
"type": "bubble_no_hints", "value": 1},
|
"type": "bubble_no_hints", "value": 1},
|
||||||
|
|
||||||
{"code": "bubble_perfect", "category": "bubblewords", "icon": "✨",
|
{"code": "bubble_streak_25", "category": "bubblewords", "icon": "🔥",
|
||||||
"name_pl": "Perfekcyjny", "name_ru": "Идеальный", "name_uk": "Ідеальний", "name_en": "Perfect",
|
"name_pl": "Dwadzieścia pięć z rzędu", "name_ru": "Двадцать пять подряд", "name_uk": "Двадцять п'ять поспіль", "name_en": "Twenty-Five in a Row",
|
||||||
"desc_pl": "Ukończ poziom z maksymalną punktacją (100)", "desc_ru": "Пройти уровень с максимальным счётом (100)", "desc_uk": "Пройти рівень з максимальним рахунком (100)", "desc_en": "Complete a level with maximum score (100)",
|
"desc_pl": "Ukończ 25 poziomów z rzędu bez podpowiedzi", "desc_ru": "Пройти 25 уровней подряд без подсказок", "desc_uk": "Пройти 25 рівнів поспіль без підказок", "desc_en": "Complete 25 levels in a row without hints",
|
||||||
"type": "bubble_perfect", "value": 1},
|
"type": "bubble_streak", "value": 25},
|
||||||
|
|
||||||
{"code": "bubble_speed", "category": "bubblewords", "icon": "🚀",
|
{"code": "bubble_speed", "category": "bubblewords", "icon": "🚀",
|
||||||
"name_pl": "Szybki bańki", "name_ru": "Быстрые пузыри", "name_uk": "Швидкі бульбашки", "name_en": "Fast Bubbles",
|
"name_pl": "Szybki bańki", "name_ru": "Быстрые пузыри", "name_uk": "Швидкі бульбашки", "name_en": "Fast Bubbles",
|
||||||
@@ -371,10 +371,10 @@ ACHIEVEMENTS_DATA = [
|
|||||||
"desc_pl": "Zbierz 25 słów", "desc_ru": "Собрать 25 слов", "desc_uk": "Зібрати 25 слів", "desc_en": "Collect 25 words",
|
"desc_pl": "Zbierz 25 słów", "desc_ru": "Собрать 25 слов", "desc_uk": "Зібрати 25 слів", "desc_en": "Collect 25 words",
|
||||||
"type": "bubble_words", "value": 25},
|
"type": "bubble_words", "value": 25},
|
||||||
|
|
||||||
{"code": "bubble_no_mistakes", "category": "bubblewords", "icon": "✨",
|
{"code": "bubble_words_1000", "category": "bubblewords", "icon": "📚",
|
||||||
"name_pl": "Bezbłędny", "name_ru": "Без ошибок", "name_uk": "Без помилок", "name_en": "No Mistakes",
|
"name_pl": "Tysiąc słów", "name_ru": "Тысяча слов", "name_uk": "Тисяча слів", "name_en": "Thousand Words",
|
||||||
"desc_pl": "Ukończ poziom bez żadnej pomyłki", "desc_ru": "Пройти уровень без единой ошибки", "desc_uk": "Пройти рівень без жодної помилки", "desc_en": "Complete a level without any mistakes",
|
"desc_pl": "Zbierz 1000 słów", "desc_ru": "Собрать 1000 слов", "desc_uk": "Зібрати 1000 слів", "desc_en": "Collect 1000 words",
|
||||||
"type": "bubble_no_mistakes", "value": 1},
|
"type": "bubble_words", "value": 1000},
|
||||||
|
|
||||||
{"code": "bubble_streak_3", "category": "bubblewords", "icon": "🔥",
|
{"code": "bubble_streak_3", "category": "bubblewords", "icon": "🔥",
|
||||||
"name_pl": "Seria", "name_ru": "Серия", "name_uk": "Серія", "name_en": "Streak",
|
"name_pl": "Seria", "name_ru": "Серия", "name_uk": "Серія", "name_en": "Streak",
|
||||||
@@ -406,10 +406,10 @@ ACHIEVEMENTS_DATA = [
|
|||||||
"desc_pl": "Ukończ poziom w mniej niż 15 sekund", "desc_ru": "Пройти уровень быстрее 15 секунд", "desc_uk": "Пройти рівень швидше 15 секунд", "desc_en": "Complete a level in under 15 seconds",
|
"desc_pl": "Ukończ poziom w mniej niż 15 sekund", "desc_ru": "Пройти уровень быстрее 15 секунд", "desc_uk": "Пройти рівень швидше 15 секунд", "desc_en": "Complete a level in under 15 seconds",
|
||||||
"type": "bubble_speed_15", "value": 15},
|
"type": "bubble_speed_15", "value": 15},
|
||||||
|
|
||||||
{"code": "bubble_perfect_10", "category": "bubblewords", "icon": "🌟",
|
{"code": "bubble_speed_10", "category": "bubblewords", "icon": "⚡",
|
||||||
"name_pl": "Perfekcyjna seria", "name_ru": "Идеальная серия", "name_uk": "Ідеальна серія", "name_en": "Perfect Streak",
|
"name_pl": "Mgnienie", "name_ru": "Мгновение", "name_uk": "Миттєвість", "name_en": "Blink",
|
||||||
"desc_pl": "Ukończ 10 idealnych poziomów z rzędu", "desc_ru": "Пройти 10 идеальных уровней подряд", "desc_uk": "Пройти 10 ідеальних рівнів поспіль", "desc_en": "Complete 10 perfect levels in a row",
|
"desc_pl": "Ukończ poziom w mniej niż 10 sekund", "desc_ru": "Пройти уровень быстрее 10 секунд", "desc_uk": "Пройти рівень швидше 10 секунд", "desc_en": "Complete a level in under 10 seconds",
|
||||||
"type": "bubble_perfect_streak", "value": 10},
|
"type": "bubble_speed_10", "value": 10},
|
||||||
|
|
||||||
{"code": "bubble_words_500", "category": "bubblewords", "icon": "🏆",
|
{"code": "bubble_words_500", "category": "bubblewords", "icon": "🏆",
|
||||||
"name_pl": "Pięćset słów", "name_ru": "Пятьсот слов", "name_uk": "П'ятсот слів", "name_en": "Five Hundred Words",
|
"name_pl": "Pięćset słów", "name_ru": "Пятьсот слов", "name_uk": "П'ятсот слів", "name_en": "Five Hundred Words",
|
||||||
|
|||||||
@@ -436,8 +436,6 @@ async def complete_bubble_level(request: Request):
|
|||||||
]
|
]
|
||||||
if hints_used == 0:
|
if hints_used == 0:
|
||||||
achievements_to_check.append(("bubble_no_hints", 1))
|
achievements_to_check.append(("bubble_no_hints", 1))
|
||||||
if hints_used == 0 and not list_opened and wrong_words == 0:
|
|
||||||
achievements_to_check.append(("bubble_perfect", 1))
|
|
||||||
if completion_time is not None and 0 < completion_time <= 45:
|
if completion_time is not None and 0 < completion_time <= 45:
|
||||||
achievements_to_check.append(("bubble_speed_45", 45))
|
achievements_to_check.append(("bubble_speed_45", 45))
|
||||||
if completion_time is not None and 0 < completion_time <= 30:
|
if completion_time is not None and 0 < completion_time <= 30:
|
||||||
@@ -447,10 +445,6 @@ async def complete_bubble_level(request: Request):
|
|||||||
# bubble_words — всего слов собрано
|
# bubble_words — всего слов собрано
|
||||||
achievements_to_check.append(("bubble_words", words_collected))
|
achievements_to_check.append(("bubble_words", words_collected))
|
||||||
|
|
||||||
# bubble_no_mistakes — уровень без ошибок
|
|
||||||
if wrong_words == 0:
|
|
||||||
achievements_to_check.append(("bubble_no_mistakes", 1))
|
|
||||||
|
|
||||||
# bubble_streak — серия без подсказок (если > 0)
|
# bubble_streak — серия без подсказок (если > 0)
|
||||||
if no_hints_streak > 0:
|
if no_hints_streak > 0:
|
||||||
achievements_to_check.append(("bubble_streak", no_hints_streak))
|
achievements_to_check.append(("bubble_streak", no_hints_streak))
|
||||||
@@ -462,9 +456,9 @@ async def complete_bubble_level(request: Request):
|
|||||||
if completion_time is not None and 0 < completion_time <= 15:
|
if completion_time is not None and 0 < completion_time <= 15:
|
||||||
achievements_to_check.append(("bubble_speed_15", 15))
|
achievements_to_check.append(("bubble_speed_15", 15))
|
||||||
|
|
||||||
# bubble_perfect_streak — серия идеальных (если > 0)
|
# bubble_speed_10 — быстрее 10 сек
|
||||||
if perfect_streak > 0:
|
if completion_time is not None and 0 < completion_time <= 10:
|
||||||
achievements_to_check.append(("bubble_perfect_streak", perfect_streak))
|
achievements_to_check.append(("bubble_speed_10", 10))
|
||||||
|
|
||||||
# Достижения — вне транзакции
|
# Достижения — вне транзакции
|
||||||
from routers.achievements import check_and_award_achievements
|
from routers.achievements import check_and_award_achievements
|
||||||
|
|||||||
@@ -7,39 +7,6 @@ from database import get_pool
|
|||||||
router = APIRouter(prefix="/sentences", tags=["sentences"])
|
router = APIRouter(prefix="/sentences", tags=["sentences"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{sentence_id}/hint")
|
|
||||||
async def get_sentence_hint(sentence_id: int, request: Request):
|
|
||||||
"""Получить правильное предложение в качестве подсказки (одноразово)"""
|
|
||||||
telegram_id, _ = await require_auth(request)
|
|
||||||
|
|
||||||
pool = await get_pool()
|
|
||||||
async with pool.acquire() as conn:
|
|
||||||
row = await conn.fetchrow(
|
|
||||||
"SELECT sentence_pl FROM sentences WHERE id = $1", sentence_id
|
|
||||||
)
|
|
||||||
if not row:
|
|
||||||
raise HTTPException(404, "Sentence not found")
|
|
||||||
|
|
||||||
# 🔧 ФИКС (24.09.2026): sentence_hint_no_limit — лимит 1 раз на предложение.
|
|
||||||
already_used = await conn.fetchval(
|
|
||||||
"SELECT 1 FROM sentence_hints_used WHERE user_id = $1 AND sentence_id = $2",
|
|
||||||
telegram_id, sentence_id
|
|
||||||
)
|
|
||||||
if already_used:
|
|
||||||
raise HTTPException(403, "Hint already used for this sentence")
|
|
||||||
|
|
||||||
# Записываем использование
|
|
||||||
await conn.execute("""
|
|
||||||
INSERT INTO sentence_hints_used (user_id, sentence_id)
|
|
||||||
VALUES ($1, $2)
|
|
||||||
ON CONFLICT (user_id, sentence_id) DO NOTHING
|
|
||||||
""", telegram_id, sentence_id)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"sentence_pl": row["sentence_pl"],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def load_sentences_from_csv(filename):
|
def load_sentences_from_csv(filename):
|
||||||
"""Загружает предложения из CSV файла (формат: polish,english,russian,ukrainian)."""
|
"""Загружает предложения из CSV файла (формат: polish,english,russian,ukrainian)."""
|
||||||
sentences = []
|
sentences = []
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ USER_TABLES = [
|
|||||||
"user_seen_bubble_levels",
|
"user_seen_bubble_levels",
|
||||||
"user_word_stats",
|
"user_word_stats",
|
||||||
"xp_log",
|
"xp_log",
|
||||||
"sentence_hints_used",
|
|
||||||
"typing_hints_used",
|
"typing_hints_used",
|
||||||
"chat_history",
|
"chat_history",
|
||||||
"chat_usage",
|
"chat_usage",
|
||||||
|
|||||||
+69
-28
@@ -1966,44 +1966,85 @@ async def test_sentences_stats(smoke_user):
|
|||||||
assert passed
|
assert passed
|
||||||
|
|
||||||
|
|
||||||
async def test_sentences_hint(smoke_user, smoke_conn):
|
async def test_sentences_show_answer_medium(smoke_user, smoke_conn):
|
||||||
"""GET /sentences/{id}/hint → sentence_pl, лимит 1 раз."""
|
"""POST /sentences/show-answer — Medium: лимит 2 (200, 200, 403)."""
|
||||||
client = smoke_user
|
client = smoke_user
|
||||||
|
|
||||||
# Берём предложение, которое юзер ещё НЕ проходил и НЕ брал подсказку
|
await smoke_conn.execute(
|
||||||
sentence_id = await smoke_conn.fetchval("""
|
"UPDATE users SET difficulty = 'medium' WHERE telegram_id = $1", SMOKE_USER_ID
|
||||||
SELECT id FROM sentences
|
)
|
||||||
WHERE id NOT IN (
|
|
||||||
SELECT sentence_id FROM sentence_hints_used WHERE user_id = $1
|
|
||||||
)
|
|
||||||
ORDER BY id LIMIT 1
|
|
||||||
""", SMOKE_USER_ID)
|
|
||||||
|
|
||||||
|
sentence_id = await smoke_conn.fetchval("SELECT id FROM sentences ORDER BY id LIMIT 1")
|
||||||
if not sentence_id:
|
if not sentence_id:
|
||||||
pytest.skip("Нет предложений для hint-теста")
|
pytest.skip("Нет предложений для show-answer теста")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 1. Первый запрос — 200
|
# Чистим list_opened, чтобы начать с 0
|
||||||
resp1 = await client.get(f"/sentences/{sentence_id}/hint")
|
await smoke_conn.execute(
|
||||||
ok1 = resp1.status_code == 200
|
"DELETE FROM sentence_progress WHERE user_id = $1 AND sentence_id = $2",
|
||||||
body1 = resp1.json() if ok1 else {}
|
|
||||||
has_sentence = bool(body1.get("sentence_pl"))
|
|
||||||
|
|
||||||
# 2. Проверка в БД
|
|
||||||
recorded = await smoke_conn.fetchval(
|
|
||||||
"SELECT 1 FROM sentence_hints_used WHERE user_id = $1 AND sentence_id = $2",
|
|
||||||
SMOKE_USER_ID, sentence_id,
|
SMOKE_USER_ID, sentence_id,
|
||||||
) is not None
|
)
|
||||||
|
|
||||||
# 3. Второй запрос — 403 (лимит)
|
resp1 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
|
||||||
resp2 = await client.get(f"/sentences/{sentence_id}/hint")
|
resp2 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
|
||||||
limit_ok = resp2.status_code == 403
|
resp3 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
|
||||||
|
|
||||||
passed = ok1 and has_sentence and recorded and limit_ok
|
passed = resp1.status_code == 200 and resp2.status_code == 200 and resp3.status_code == 403
|
||||||
RESULTS.append(ScenarioResult(
|
RESULTS.append(ScenarioResult(
|
||||||
"sentences_hint", "sentences", passed,
|
"sentences_show_answer_medium", "sentences", passed,
|
||||||
f"first={resp1.status_code}, recorded={recorded}, second={resp2.status_code} (ожидали 403)",
|
f"medium: 1={resp1.status_code}, 2={resp2.status_code}, 3={resp3.status_code} (ожидали 200/200/403)",
|
||||||
{"first_status": resp1.status_code, "recorded": recorded, "second_status": resp2.status_code},
|
{"first": resp1.status_code, "second": resp2.status_code, "third": resp3.status_code},
|
||||||
|
))
|
||||||
|
assert passed
|
||||||
|
|
||||||
|
|
||||||
|
async def test_sentences_show_answer_hard(smoke_user, smoke_conn):
|
||||||
|
"""POST /sentences/show-answer — Hard: сразу 403."""
|
||||||
|
client = smoke_user
|
||||||
|
|
||||||
|
await smoke_conn.execute(
|
||||||
|
"UPDATE users SET difficulty = 'hard' WHERE telegram_id = $1", SMOKE_USER_ID
|
||||||
|
)
|
||||||
|
|
||||||
|
sentence_id = await smoke_conn.fetchval("SELECT id FROM sentences ORDER BY id LIMIT 1")
|
||||||
|
if not sentence_id:
|
||||||
|
pytest.skip("Нет предложений для show-answer теста")
|
||||||
|
return
|
||||||
|
|
||||||
|
resp = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
|
||||||
|
|
||||||
|
passed = resp.status_code == 403
|
||||||
|
RESULTS.append(ScenarioResult(
|
||||||
|
"sentences_show_answer_hard", "sentences", passed,
|
||||||
|
f"hard: status={resp.status_code} (ожидали 403)",
|
||||||
|
{"status": resp.status_code},
|
||||||
|
))
|
||||||
|
assert passed
|
||||||
|
|
||||||
|
|
||||||
|
async def test_sentences_show_answer_easy(smoke_user, smoke_conn):
|
||||||
|
"""POST /sentences/show-answer — Easy: без лимита (несколько 200)."""
|
||||||
|
client = smoke_user
|
||||||
|
|
||||||
|
await smoke_conn.execute(
|
||||||
|
"UPDATE users SET difficulty = 'easy' WHERE telegram_id = $1", SMOKE_USER_ID
|
||||||
|
)
|
||||||
|
|
||||||
|
sentence_id = await smoke_conn.fetchval("SELECT id FROM sentences ORDER BY id LIMIT 1")
|
||||||
|
if not sentence_id:
|
||||||
|
pytest.skip("Нет предложений для show-answer теста")
|
||||||
|
return
|
||||||
|
|
||||||
|
statuses = []
|
||||||
|
for _ in range(3):
|
||||||
|
r = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
|
||||||
|
statuses.append(r.status_code)
|
||||||
|
|
||||||
|
passed = all(s == 200 for s in statuses)
|
||||||
|
RESULTS.append(ScenarioResult(
|
||||||
|
"sentences_show_answer_easy", "sentences", passed,
|
||||||
|
f"easy: statuses={statuses} (ожидали все 200)",
|
||||||
|
{"statuses": statuses},
|
||||||
))
|
))
|
||||||
assert passed
|
assert passed
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user