from django.urls import reverse
from django.contrib.auth import get_user_model
from rest_framework import status
from rest_framework.test import APITestCase
from your_app.models import Suggestion

User = get_user_model()

class SuggestionTests(APITestCase):
    def setUp(self):
        self.user = User.objects.create_user(username='testuser', password='testpassword123')
        self.client.force_authenticate(user=self.user)

    def test_create_suggestion(self):
        url = reverse('suggestion-list-create')
        data = {
            'url': 'https://example.com',
            'description': 'This is a test suggestion'
        }
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Suggestion.objects.count(), 1)
        self.assertEqual(Suggestion.objects.get().url, 'https://example.com')

    def test_list_suggestions(self):
        Suggestion.objects.create(url='https://example.com', suggested_by=self.user)
        url = reverse('suggestion-list-create')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)