winofy-backend/apps/stores/tests/test_seller_store.py
Ali Asadi 5117fe9b05 Add Store.max_delivery_time_minutes, return it wherever store info appears
Seller sets this at registration (default 60 min). Exposed on store
list/detail, the seller's own store, cart groups (GET /api/v1/cart/),
and order/order-group responses, so the checkout page's estimated
delivery time no longer needs a frontend mock.

Also document CartSerializer's groups/grand_total for swagger (were
untyped SerializerMethodFields showing as opaque strings) since that's
the endpoint carrying this new field to the checkout page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-02 14:15:19 +03:30

56 lines
2.4 KiB
Python

import uuid
from apps.locations.models import City
from apps.stores.models import Store, StoreCategory
from apps.users.models import User
from apps.orders.tests.base import OrdersTestCase
class SellerStoreTests(OrdersTestCase):
def setUp(self):
self.new_seller = User.objects.create_user(pk=uuid.uuid4(), username='new_seller')
self.category = StoreCategory.objects.create(name='کافه')
def test_seller_can_create_their_store(self):
self.client.force_authenticate(user=self.new_seller)
response = self.client.post('/api/v1/seller/store/', {
'name': 'کافه من',
'category_uuid': str(self.category.uuid),
'city_uuid': str(self.city.uuid),
'address': 'خیابان ولیعصر',
'latitude': 35.75,
'longitude': 51.4,
'max_delivery_time_minutes': 40,
})
self.assertEqual(response.status_code, 201, response.data)
self.assertTrue(Store.objects.filter(owner=self.new_seller).exists())
self.assertAlmostEqual(response.data['latitude'], 35.75)
self.assertAlmostEqual(response.data['longitude'], 51.4)
self.assertEqual(response.data['max_delivery_time_minutes'], 40)
def test_max_delivery_time_minutes_defaults_when_not_provided(self):
self.client.force_authenticate(user=self.new_seller)
response = self.client.post('/api/v1/seller/store/', {
'name': 'کافه من',
'category_uuid': str(self.category.uuid),
'city_uuid': str(self.city.uuid),
'address': 'خیابان ولیعصر',
})
self.assertEqual(response.status_code, 201, response.data)
self.assertEqual(response.data['max_delivery_time_minutes'], 60)
def test_seller_cannot_create_a_second_store(self):
self.client.force_authenticate(user=self.seller1)
response = self.client.post('/api/v1/seller/store/', {
'name': 'فروشگاه دوم',
'category_uuid': str(self.category.uuid),
'city_uuid': str(self.city.uuid),
'address': 'خیابان دیگر',
})
self.assertEqual(response.status_code, 409)
def test_non_seller_cannot_access_seller_endpoints(self):
self.client.force_authenticate(user=self.customer)
response = self.client.get('/api/v1/seller/store/')
self.assertEqual(response.status_code, 404) # no store yet -> get_object_or_404