import unittest
from app import app
import json

class NotificationServiceTestCase(unittest.TestCase):
    def setUp(self):
        self.app = app.test_client()
        self.app.testing = True

    def test_send_notification_success(self):
        data = {"userId": "123", "message": "Test notification"}
        response = self.app.post('/notifications/send',
                                 data=json.dumps(data),
                                 content_type='application/json')
        self.assertEqual(response.status_code, 200)
        self.assertIn("Notification sent successfully", response.json['message'])

    def test_send_notification_missing_data(self):
        data = {"userId": "123"} # Missing message
        response = self.app.post('/notifications/send',
                                 data=json.dumps(data),
                                 content_type='application/json')
        self.assertEqual(response.status_code, 400)
        self.assertIn("user_id and message are required", response.json['error'])

if __name__ == '__main__':
    unittest.main()
