All checks were successful
Build and Push Docker Image / build (push) Successful in 4m14s
Reference numbers (unified scheme PREFIX-YYYYMM-HOSP-NNNN, e.g. CMP-202606-HHN-0001): - new ReferenceSequence model + generate_reference() helper (apps/core) - Complaint/Inquiry/Observation/Appreciation/Suggestion emit unified refs via save() - prefix-based auto-routing in public track API (CMP/INQ/OBS trackable; APR/SGT internal-only) - removed legacy CMP-/INQ- generators in ui_views, integrations, px_sources - migrations: core.0003_referencesequence, appreciation.0006, feedback.0008, observations.0012 - unit tests (format, sanitization, monthly reset, 40-thread concurrency) QA audit: - isolated E2E hospital sandbox mirroring HH-N + 10 role users (create_e2e_isolated_env) - feedback-modules-audit.spec.ts + audit helper (headed, run-to-completion) - reports/feedback-modules-qa-report.md Also bundles accumulated in-progress work across complaints, observations, organizations, templates, and other modules.
234 lines
7.9 KiB
Python
234 lines
7.9 KiB
Python
"""
|
|
Tests for public inquiry form and view (both complaints and core app handlers).
|
|
"""
|
|
from datetime import date
|
|
|
|
from django.test import Client, TestCase
|
|
from django.urls import reverse
|
|
|
|
from apps.complaints.models import Inquiry
|
|
from apps.organizations.models import Area, Department, Hospital, LocationType, Section
|
|
|
|
|
|
class PublicInquiryViewTests(TestCase):
|
|
def setUp(self):
|
|
self.client = Client()
|
|
self.hospital = Hospital.objects.create(
|
|
name="Test Hospital",
|
|
code="TEST",
|
|
status="active",
|
|
)
|
|
self.department = Department.objects.create(
|
|
hospital=self.hospital,
|
|
name="Reception",
|
|
name_en="Reception",
|
|
code="test_recv",
|
|
status="active",
|
|
)
|
|
self.section = Section.objects.create(
|
|
department=self.department,
|
|
name_en="Front Desk",
|
|
code="test_recv_fd",
|
|
status="active",
|
|
)
|
|
|
|
def test_public_inquiry_form_get(self):
|
|
response = self.client.get(reverse("inquiries:public_inquiry_submit"))
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
def test_public_inquiry_post_saves_location_type(self):
|
|
data = {
|
|
"name": "Jane Doe",
|
|
"phone": "0598765432",
|
|
"email": "jane@example.com",
|
|
"hospital": str(self.hospital.id),
|
|
"location_type": "OP",
|
|
"category": "general",
|
|
"subject": "Test Inquiry",
|
|
"message": "This is a test inquiry message.",
|
|
}
|
|
response = self.client.post(
|
|
reverse("inquiries:public_inquiry_submit"),
|
|
data,
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
result = response.json()
|
|
self.assertTrue(result["success"])
|
|
|
|
inquiry = Inquiry.objects.first()
|
|
self.assertIsNotNone(inquiry)
|
|
self.assertEqual(inquiry.location_type, "OP")
|
|
self.assertEqual(inquiry.hospital_id, self.hospital.id)
|
|
|
|
def test_public_inquiry_post_with_dept_and_section(self):
|
|
data = {
|
|
"name": "Jane Doe",
|
|
"phone": "0598765432",
|
|
"email": "",
|
|
"hospital": str(self.hospital.id),
|
|
"location_type": "IP",
|
|
"department": str(self.department.id),
|
|
"section": str(self.section.id),
|
|
"category": "billing",
|
|
"subject": "Billing Question",
|
|
"message": "I have a question about my bill.",
|
|
}
|
|
response = self.client.post(
|
|
reverse("inquiries:public_inquiry_submit"),
|
|
data,
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
|
)
|
|
self.assertEqual(response.status_code, 200)
|
|
inquiry = Inquiry.objects.first()
|
|
self.assertEqual(inquiry.location_type, "IP")
|
|
self.assertEqual(inquiry.department_id, self.department.id)
|
|
self.assertEqual(inquiry.section_id, self.section.id)
|
|
|
|
def test_public_inquiry_post_missing_required_fields(self):
|
|
data = {
|
|
"name": "",
|
|
"phone": "",
|
|
"message": "",
|
|
}
|
|
response = self.client.post(
|
|
reverse("inquiries:public_inquiry_submit"),
|
|
data,
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
|
)
|
|
self.assertEqual(response.status_code, 400)
|
|
result = response.json()
|
|
self.assertFalse(result["success"])
|
|
|
|
def test_public_inquiry_post_invalid_hospital(self):
|
|
data = {
|
|
"name": "Jane",
|
|
"phone": "0598765432",
|
|
"hospital": "00000000-0000-0000-0000-000000000000",
|
|
"subject": "Test",
|
|
"message": "Test message.",
|
|
}
|
|
response = self.client.post(
|
|
reverse("inquiries:public_inquiry_submit"),
|
|
data,
|
|
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
|
|
)
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
class CoreInquiryViewTests(TestCase):
|
|
def setUp(self):
|
|
self.client = Client()
|
|
self.hospital = Hospital.objects.create(
|
|
name="Core Test Hospital",
|
|
code="CORE",
|
|
status="active",
|
|
)
|
|
self.department = Department.objects.create(
|
|
hospital=self.hospital,
|
|
name="Admin",
|
|
name_en="Admin",
|
|
code="core_admin",
|
|
status="active",
|
|
)
|
|
self.section = Section.objects.create(
|
|
department=self.department,
|
|
name_en="HR Section",
|
|
code="core_admin_hr",
|
|
status="active",
|
|
)
|
|
|
|
def test_core_inquiry_post_saves_location_type(self):
|
|
data = {
|
|
"name": "Alice Smith",
|
|
"phone": "0511122233",
|
|
"email": "alice@example.com",
|
|
"hospital": str(self.hospital.id),
|
|
"location_type": "ER",
|
|
"category": "appointment",
|
|
"subject": "Appointment Inquiry",
|
|
"message": "When is my appointment?",
|
|
"department": str(self.department.id),
|
|
"section": str(self.section.id),
|
|
}
|
|
response = self.client.post(reverse("core:public_inquiry_submit"), data)
|
|
self.assertEqual(response.status_code, 200)
|
|
result = response.json()
|
|
self.assertTrue(result["success"])
|
|
|
|
inquiry = Inquiry.objects.first()
|
|
self.assertIsNotNone(inquiry)
|
|
self.assertEqual(inquiry.location_type, "ER")
|
|
self.assertEqual(inquiry.department_id, self.department.id)
|
|
self.assertEqual(inquiry.section_id, self.section.id)
|
|
|
|
def test_core_inquiry_post_without_location_type(self):
|
|
data = {
|
|
"name": "Bob Jones",
|
|
"phone": "0544455566",
|
|
"email": "",
|
|
"hospital": str(self.hospital.id),
|
|
"location_type": "",
|
|
"subject": "General Question",
|
|
"message": "Just wondering about something.",
|
|
}
|
|
response = self.client.post(reverse("core:public_inquiry_submit"), data)
|
|
self.assertEqual(response.status_code, 200)
|
|
inquiry = Inquiry.objects.first()
|
|
self.assertEqual(inquiry.location_type, "")
|
|
|
|
def test_core_inquiry_post_missing_name(self):
|
|
data = {
|
|
"name": "",
|
|
"phone": "0544455566",
|
|
"hospital": str(self.hospital.id),
|
|
"message": "Test.",
|
|
}
|
|
response = self.client.post(reverse("core:public_inquiry_submit"), data)
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
class CoreObservationViewTests(TestCase):
|
|
def setUp(self):
|
|
self.client = Client()
|
|
self.hospital = Hospital.objects.create(
|
|
name="Obs Test Hospital",
|
|
code="OBS",
|
|
status="active",
|
|
)
|
|
self.department = Department.objects.create(
|
|
hospital=self.hospital,
|
|
name="Lab",
|
|
name_en="Lab",
|
|
code="obs_lab",
|
|
status="active",
|
|
)
|
|
self.section = Section.objects.create(
|
|
department=self.department,
|
|
name_en="Blood Draw",
|
|
code="obs_lab_bd",
|
|
status="active",
|
|
)
|
|
|
|
def test_core_observation_post_saves_location_type(self):
|
|
data = {
|
|
"hospital": str(self.hospital.id),
|
|
"location_type": "OP",
|
|
"description": "I noticed something wrong in the lab area.",
|
|
"severity": "medium",
|
|
"department": str(self.department.id),
|
|
"section": str(self.section.id),
|
|
}
|
|
response = self.client.post(reverse("core:public_observation_submit"), data)
|
|
self.assertEqual(response.status_code, 200)
|
|
result = response.json()
|
|
self.assertTrue(result["success"])
|
|
|
|
from apps.observations.models import Observation
|
|
|
|
obs = Observation.objects.first()
|
|
self.assertIsNotNone(obs)
|
|
self.assertEqual(obs.location_type, "OP")
|
|
self.assertEqual(obs.assigned_department_id, self.department.id)
|
|
self.assertEqual(obs.section_id, self.section.id)
|