56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
from apps.tickets.models import Ticket, TicketEvent
|
|
|
|
|
|
def test_create_ticket_returns_ticket_detail(admin_client, db):
|
|
response = admin_client.post(
|
|
"/api/tickets",
|
|
data={
|
|
"title": "Payment callback fails",
|
|
"description": "Callback returns HTTP 500 in production",
|
|
"priority": "high",
|
|
"impact_scope": "payment users",
|
|
"environment": "production",
|
|
"related_system": "payment",
|
|
},
|
|
content_type="application/json",
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload["ticket_no"].startswith("TK")
|
|
assert payload["title"] == "Payment callback fails"
|
|
assert payload["status"] == "pending"
|
|
assert TicketEvent.objects.filter(ticket_id=payload["id"], event_type="created").exists()
|
|
|
|
|
|
def test_list_tickets_filters_by_status(admin_client, db):
|
|
Ticket.objects.create(ticket_no="TK202606300001", title="A", description="A", status="pending")
|
|
Ticket.objects.create(ticket_no="TK202606300002", title="B", description="B", status="resolved")
|
|
|
|
response = admin_client.get("/api/tickets?status=pending")
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert len(payload) == 1
|
|
assert payload[0]["ticket_no"] == "TK202606300001"
|
|
|
|
|
|
def test_transition_ticket_status_creates_event(admin_client, db):
|
|
ticket = Ticket.objects.create(
|
|
ticket_no="TK202606300003",
|
|
title="A",
|
|
description="A",
|
|
status="pending",
|
|
)
|
|
|
|
response = admin_client.post(
|
|
f"/api/tickets/{ticket.id}/status",
|
|
data={"status": "in_progress", "remark": "Start handling"},
|
|
content_type="application/json",
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
ticket.refresh_from_db()
|
|
assert ticket.status == "in_progress"
|
|
assert ticket.events.filter(event_type="status_change").exists()
|