Add end-to-end tests for parent notifications and actions
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 2m35s
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 2m35s
- Implement tests for approving and denying rewards and chores, including token generation and validation. - Create tests for error handling scenarios with expired, tampered, and fake tokens. - Add tests for push subscription registration and user profile notification settings. - Ensure that notifications reflect the correct state of rewards and chores in the UI. - Validate that toggles for email digest and push notifications function correctly based on user permissions and server state.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import os
|
||||
|
||||
from flask import Blueprint, request, jsonify
|
||||
from datetime import datetime, timedelta
|
||||
from tinydb import Query
|
||||
|
||||
from db.db import users_db
|
||||
from models.user import User
|
||||
from api.utils import admin_required
|
||||
from api.utils import admin_required, get_validated_user_id
|
||||
from config.deletion_config import (
|
||||
ACCOUNT_DELETION_THRESHOLD_HOURS,
|
||||
MIN_THRESHOLD_HOURS,
|
||||
@@ -153,3 +155,54 @@ def trigger_deletion_queue():
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e), 'code': 'SERVER_ERROR'}), 500
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Test-only endpoint — active ONLY when DB_ENV=e2e
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@admin_api.route('/admin/test/digest-token', methods=['POST'])
|
||||
def create_test_digest_token():
|
||||
"""Create a valid DigestActionToken for E2E tests.
|
||||
|
||||
Only active when DB_ENV=e2e. Requires authentication.
|
||||
"""
|
||||
if os.environ.get('DB_ENV') != 'e2e':
|
||||
return jsonify({'error': 'Not found', 'code': 'NOT_FOUND'}), 404
|
||||
|
||||
user_id = get_validated_user_id()
|
||||
if not user_id:
|
||||
return jsonify({'error': 'Unauthorized', 'code': 'UNAUTHORIZED'}), 401
|
||||
|
||||
data = request.get_json() or {}
|
||||
child_id = data.get('child_id')
|
||||
entity_id = data.get('entity_id')
|
||||
entity_type = data.get('entity_type')
|
||||
action = data.get('action')
|
||||
expires_in_hours = data.get('expires_in_hours', 24)
|
||||
|
||||
if not all([child_id, entity_id, entity_type, action]):
|
||||
return jsonify({'error': 'child_id, entity_id, entity_type, and action are required',
|
||||
'code': 'MISSING_FIELDS'}), 400
|
||||
|
||||
if entity_type not in ('chore', 'reward'):
|
||||
return jsonify({'error': 'entity_type must be "chore" or "reward"',
|
||||
'code': 'INVALID_ENTITY_TYPE'}), 400
|
||||
|
||||
if action not in ('approve', 'deny'):
|
||||
return jsonify({'error': 'action must be "approve" or "deny"',
|
||||
'code': 'INVALID_ACTION'}), 400
|
||||
|
||||
try:
|
||||
from utils.digest_token import create_action_token
|
||||
token = create_action_token(
|
||||
user_id=user_id,
|
||||
child_id=child_id,
|
||||
entity_id=entity_id,
|
||||
entity_type=entity_type,
|
||||
action=action,
|
||||
expiry_hours=int(expires_in_hours),
|
||||
)
|
||||
return jsonify({'token': token.id}), 200
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e), 'code': 'SERVER_ERROR'}), 500
|
||||
|
||||
Reference in New Issue
Block a user