6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""Behavior guard for the insufficient-credits notification handler."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.db import User, Workspace
|
|
from app.notifications.service import NotificationService
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
handler = NotificationService.insufficient_credits
|
|
|
|
|
|
async def test_insufficient_credits_message_and_action(
|
|
db_session: AsyncSession, db_user: User, db_workspace: Workspace
|
|
):
|
|
"""An insufficient-credits notification states cost and carries a buy-credits link."""
|
|
notification = await handler.notify_insufficient_credits(
|
|
session=db_session,
|
|
user_id=db_user.id,
|
|
document_name="short.pdf",
|
|
document_type="FILE",
|
|
workspace_id=db_workspace.id,
|
|
balance_micros=250_000,
|
|
required_micros=1_000_000,
|
|
)
|
|
|
|
assert notification.type == "insufficient_credits"
|
|
assert notification.title == "Insufficient credits: short.pdf"
|
|
assert notification.message == (
|
|
"This document costs about $1.00 to process but you have "
|
|
"$0.25 of credit left. Add more credits to continue."
|
|
)
|
|
assert notification.notification_metadata["status"] == "failed"
|
|
assert notification.notification_metadata["action_label"] == "Buy credits"
|
|
assert notification.notification_metadata["action_url"] == (
|
|
f"/dashboard/{db_workspace.id}/buy-more"
|
|
)
|
|
|
|
|
|
async def test_insufficient_credits_truncates_long_name(
|
|
db_session: AsyncSession, db_user: User, db_workspace: Workspace
|
|
):
|
|
"""A long document name is truncated in the notification title."""
|
|
long_name = "a" * 50
|
|
|
|
notification = await handler.notify_insufficient_credits(
|
|
session=db_session,
|
|
user_id=db_user.id,
|
|
document_name=long_name,
|
|
document_type="FILE",
|
|
workspace_id=db_workspace.id,
|
|
balance_micros=250_000,
|
|
required_micros=1_000_000,
|
|
)
|
|
|
|
assert notification.title == f"Insufficient credits: {'a' * 40}..."
|