@@ -272,6 +272,40 @@ def test_fetch_service_list_for_staff(self):
272
272
[{"id" : service .id , "name" : service .name } for service in staff_member_services ]
273
273
)
274
274
275
+ def test_fetch_service_list_for_staff_no_staff_member_instance (self ):
276
+ """Test that a superuser without a StaffMember instance receives an appropriate error message."""
277
+ self .need_superuser_login ()
278
+
279
+ # Ensure the superuser does not have a StaffMember instance
280
+ StaffMember .objects .filter (user = self .user1 ).delete ()
281
+
282
+ url = reverse ('appointment:fetch_service_list_for_staff' )
283
+ response = self .client .get (url , HTTP_X_REQUESTED_WITH = 'XMLHttpRequest' )
284
+
285
+ # Check the response status code and content
286
+ self .assertEqual (response .status_code , 400 )
287
+ response_data = response .json ()
288
+ self .assertIn ('message' , response_data )
289
+ self .assertEqual (response_data ['message' ], _ ("You're not a staff member. Can't perform this action !" ))
290
+ self .assertFalse (response_data ['success' ])
291
+
292
+ def test_fetch_service_list_for_staff_no_services_offered (self ):
293
+ """Test fetching services for a staff member who offers no services."""
294
+ self .need_staff_login ()
295
+
296
+ # Assuming self.staff_member1 offers no services
297
+ self .staff_member1 .services_offered .clear ()
298
+
299
+ url = reverse ('appointment:fetch_service_list_for_staff' )
300
+ response = self .client .get (url , HTTP_X_REQUESTED_WITH = 'XMLHttpRequest' )
301
+
302
+ # Check response status code and content
303
+ self .assertEqual (response .status_code , 404 )
304
+ response_data = response .json ()
305
+ self .assertIn ('message' , response_data )
306
+ self .assertEqual (response_data ['message' ], _ ("No services offered by this staff member." ))
307
+ self .assertFalse (response_data ['success' ])
308
+
275
309
def test_update_appt_min_info_create (self ):
276
310
self .need_staff_login ()
277
311
@@ -441,3 +475,36 @@ def test_make_staff_member_without_superuser(self):
441
475
442
476
# Check for a forbidden status code, as only superusers should be able to create staff members
443
477
self .assertEqual (response .status_code , 403 )
478
+
479
+ def test_is_user_staff_admin_with_staff_member (self ):
480
+ """Test that a user with a StaffMember instance is identified as a staff admin."""
481
+ self .need_staff_login ()
482
+
483
+ # Ensure the user has a StaffMember instance
484
+ if not StaffMember .objects .filter (user = self .user1 ).exists ():
485
+ StaffMember .objects .create (user = self .user1 )
486
+
487
+ url = reverse ('appointment:is_user_staff_admin' )
488
+ response = self .client .get (url , HTTP_X_REQUESTED_WITH = 'XMLHttpRequest' )
489
+
490
+ # Check the response status code and content
491
+ self .assertEqual (response .status_code , 200 )
492
+ response_data = response .json ()
493
+ self .assertIn ('message' , response_data )
494
+ self .assertEqual (response_data ['message' ], _ ("User is a staff member." ))
495
+
496
+ def test_is_user_staff_admin_without_staff_member (self ):
497
+ """Test that a user without a StaffMember instance is not identified as a staff admin."""
498
+ self .need_staff_login ()
499
+
500
+ # Ensure the user does not have a StaffMember instance
501
+ StaffMember .objects .filter (user = self .user1 ).delete ()
502
+
503
+ url = reverse ('appointment:is_user_staff_admin' )
504
+ response = self .client .get (url , HTTP_X_REQUESTED_WITH = 'XMLHttpRequest' )
505
+
506
+ # Check the response status code and content
507
+ self .assertEqual (response .status_code , 200 )
508
+ response_data = response .json ()
509
+ self .assertIn ('message' , response_data )
510
+ self .assertEqual (response_data ['message' ], _ ("User is not a staff member." ))
0 commit comments