added fixes for bug plan 1.0.6RC01
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 5m43s
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 5m43s
This commit is contained in:
@@ -6,9 +6,10 @@ from werkzeug.security import generate_password_hash
|
||||
from flask import Flask
|
||||
from api.reward_api import reward_api
|
||||
from api.auth_api import auth_api
|
||||
from db.db import reward_db, child_db, users_db
|
||||
from db.db import reward_db, child_db, users_db, pending_confirmations_db
|
||||
from tinydb import Query
|
||||
from models.reward import Reward
|
||||
from models.pending_confirmation import PendingConfirmation
|
||||
import jwt
|
||||
|
||||
|
||||
@@ -126,4 +127,59 @@ def test_delete_assigned_reward_removes_from_child(client):
|
||||
resp2 = client.delete('/reward/r_user_owned')
|
||||
assert resp2.status_code == 200
|
||||
child2 = child_db.search(ChildQuery.id == 'child_for_user_reward')[0]
|
||||
assert 'r_user_owned' not in child2.get('rewards', [])
|
||||
assert 'r_user_owned' not in child2.get('rewards', [])
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Bug #10: Editing reward cost resets pending reward requests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_edit_reward_cost_resets_pending_requests(client):
|
||||
"""Changing a reward's cost should remove all pending reward requests for that reward."""
|
||||
reward_db.truncate()
|
||||
child_db.truncate()
|
||||
pending_confirmations_db.truncate()
|
||||
|
||||
reward_db.insert({'id': 'r_pending', 'name': 'Prize', 'cost': 50, 'user_id': 'testuserid'})
|
||||
child_db.insert({
|
||||
'id': 'c1', 'name': 'Alice', 'age': 8, 'points': 100,
|
||||
'tasks': [], 'rewards': ['r_pending'], 'user_id': 'testuserid'
|
||||
})
|
||||
pending_confirmations_db.insert(PendingConfirmation(
|
||||
child_id='c1', entity_id='r_pending', entity_type='reward', user_id='testuserid'
|
||||
).to_dict())
|
||||
|
||||
resp = client.put('/reward/r_pending/edit', json={'cost': 75})
|
||||
assert resp.status_code == 200
|
||||
|
||||
PQ = Query()
|
||||
conf = pending_confirmations_db.get(
|
||||
(PQ.child_id == 'c1') & (PQ.entity_id == 'r_pending') & (PQ.entity_type == 'reward')
|
||||
)
|
||||
assert conf is None
|
||||
|
||||
|
||||
def test_edit_reward_name_only_keeps_pending(client):
|
||||
"""Changing only the reward name should not reset pending requests."""
|
||||
reward_db.truncate()
|
||||
child_db.truncate()
|
||||
pending_confirmations_db.truncate()
|
||||
|
||||
reward_db.insert({'id': 'r_name', 'name': 'Old Prize', 'cost': 50, 'user_id': 'testuserid'})
|
||||
child_db.insert({
|
||||
'id': 'c2', 'name': 'Bob', 'age': 7, 'points': 100,
|
||||
'tasks': [], 'rewards': ['r_name'], 'user_id': 'testuserid'
|
||||
})
|
||||
pending_confirmations_db.insert(PendingConfirmation(
|
||||
child_id='c2', entity_id='r_name', entity_type='reward', user_id='testuserid'
|
||||
).to_dict())
|
||||
|
||||
resp = client.put('/reward/r_name/edit', json={'name': 'New Prize'})
|
||||
assert resp.status_code == 200
|
||||
|
||||
PQ = Query()
|
||||
conf = pending_confirmations_db.get(
|
||||
(PQ.child_id == 'c2') & (PQ.entity_id == 'r_name') & (PQ.entity_type == 'reward')
|
||||
)
|
||||
assert conf is not None
|
||||
assert conf['status'] == 'pending'
|
||||
Reference in New Issue
Block a user