feat(api): implemented create sale as api endpoint.

This commit is contained in:
2024-09-07 21:33:49 -05:00
parent 02fbf51659
commit eaa856e9da
6 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import json
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from ..models import Sale, Product, Customer
class TestAPI(APITestCase):
def setUp(self):
self.product = Product.objects.create(
name='Panela',
price=5000,
measuring_unit='UNIT'
)
self.customer = Customer.objects.create(
name='Camilo'
)
def test_create_sale(self):
url = '/don_confiao/api/sales/'
data = {
'customer': self.customer.id,
'date': '2024-09-02',
'lines': [
{'product': self.product.id, 'quantity': 2, 'unit_price': 3000},
{'product': self.product.id, 'quantity': 3, 'unit_price': 5000}
],
}
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Sale.objects.count(), 1)
self.assertEqual(Sale.objects.all()[0].customer.name, self.customer.name)