Skip to content

Commit c881b26

Browse files
committed
add extra test for verification code
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
1 parent 28938fb commit c881b26

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/unit/test_auth_manager.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,25 @@ async def test_verify_user_expired_token(self, test_db) -> None:
300300
await AuthManager.verify(expired_verify, test_db)
301301
assert exc_info.value.status_code == status.HTTP_401_UNAUTHORIZED
302302
assert exc_info.value.detail == ResponseMessages.EXPIRED_TOKEN
303+
304+
@pytest.mark.asyncio
305+
async def test_verify_updates_database(self, test_db) -> None:
306+
"""Test that verify() successfully updates the database."""
307+
# Register a new user (defaults to verified=False)
308+
background_tasks = BackgroundTasks()
309+
await UserManager.register(self.test_user, test_db, background_tasks)
310+
311+
# Get initial user state and verify it's not verified
312+
user_before = await UserManager.get_user_by_id(1, test_db)
313+
assert user_before.verified is False
314+
315+
# Create and use a verification token
316+
verify_token = AuthManager.encode_verify_token(User(id=1))
317+
with pytest.raises(HTTPException) as exc_info:
318+
await AuthManager.verify(verify_token, test_db)
319+
assert exc_info.value.status_code == status.HTTP_200_OK
320+
assert exc_info.value.detail == ResponseMessages.VERIFICATION_SUCCESS
321+
322+
# Get updated user state and verify the field was updated
323+
user_after = await UserManager.get_user_by_id(1, test_db)
324+
assert user_after.verified is True

0 commit comments

Comments
 (0)