Fix new services implementation 3

This commit is contained in:
Urtzi Alfaro
2025-08-14 16:47:34 +02:00
parent 0951547e92
commit 03737430ee
51 changed files with 657 additions and 982 deletions

View File

@@ -26,7 +26,7 @@ class TestSalesRepository:
assert record is not None
assert record.id is not None
assert record.tenant_id == sample_tenant_id
assert record.product_name == sample_sales_data.product_name
assert record.inventory_product_id == sample_sales_data.inventory_product_id
assert record.quantity_sold == sample_sales_data.quantity_sold
assert record.revenue == sample_sales_data.revenue
@@ -42,7 +42,7 @@ class TestSalesRepository:
assert retrieved_record is not None
assert retrieved_record.id == created_record.id
assert retrieved_record.product_name == created_record.product_name
assert retrieved_record.inventory_product_id == created_record.inventory_product_id
async def test_get_by_tenant(self, populated_db, sample_tenant_id):
"""Test getting records by tenant"""
@@ -57,10 +57,12 @@ class TestSalesRepository:
"""Test getting records by product"""
repository = SalesRepository(populated_db)
records = await repository.get_by_product(sample_tenant_id, "Croissant")
# Get by inventory_product_id instead of product name
test_product_id = "550e8400-e29b-41d4-a716-446655440001"
records = await repository.get_by_inventory_product_id(sample_tenant_id, test_product_id)
assert len(records) == 1
assert records[0].product_name == "Croissant"
assert records[0].inventory_product_id == test_product_id
async def test_update_record(self, test_db_session, sample_tenant_id, sample_sales_data):
"""Test updating a sales record"""
@@ -71,6 +73,7 @@ class TestSalesRepository:
# Update record
update_data = SalesDataUpdate(
inventory_product_id="550e8400-e29b-41d4-a716-446655440999",
product_name="Updated Product",
quantity_sold=10,
revenue=Decimal("25.00")
@@ -78,7 +81,7 @@ class TestSalesRepository:
updated_record = await repository.update(created_record.id, update_data.model_dump(exclude_unset=True))
assert updated_record.product_name == "Updated Product"
assert updated_record.inventory_product_id == "550e8400-e29b-41d4-a716-446655440999"
assert updated_record.quantity_sold == 10
assert updated_record.revenue == Decimal("25.00")
@@ -137,7 +140,7 @@ class TestSalesRepository:
repository = SalesRepository(populated_db)
query = SalesDataQuery(
product_name="Croissant",
inventory_product_id="550e8400-e29b-41d4-a716-446655440001",
limit=10,
offset=0
)
@@ -145,7 +148,7 @@ class TestSalesRepository:
records = await repository.get_by_tenant(sample_tenant_id, query)
assert len(records) == 1
assert records[0].product_name == "Croissant"
assert records[0].inventory_product_id == "550e8400-e29b-41d4-a716-446655440001"
async def test_bulk_create(self, test_db_session, sample_tenant_id):
"""Test bulk creating records"""
@@ -155,6 +158,7 @@ class TestSalesRepository:
bulk_data = [
{
"date": datetime.now(timezone.utc),
"inventory_product_id": f"550e8400-e29b-41d4-a716-{i+100:012x}",
"product_name": f"Product {i}",
"quantity_sold": i + 1,
"revenue": Decimal(str((i + 1) * 2.5)),