Changed to show filament price if no spool price set and added tests
This commit is contained in:
@@ -52,6 +52,9 @@ function collapseSpool(element: ISpool): ISpoolCollapsed {
|
|||||||
} else {
|
} else {
|
||||||
filament_name = element.filament.name ?? element.filament.id.toString();
|
filament_name = element.filament.name ?? element.filament.id.toString();
|
||||||
}
|
}
|
||||||
|
if (!element.price){
|
||||||
|
element.price = element.filament.price;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...element,
|
...element,
|
||||||
combined_name: filament_name,
|
combined_name: filament_name,
|
||||||
|
|||||||
@@ -185,3 +185,15 @@ def test_add_spool_both_used_and_remaining_weight(random_filament: dict[str, Any
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result.status_code == 400 # Cannot set both used and remaining weight
|
assert result.status_code == 400 # Cannot set both used and remaining weight
|
||||||
|
|
||||||
|
def test_add_spool_price(random_filament: dict[str, Any]):
|
||||||
|
"""Test adding a spool to the database."""
|
||||||
|
# Execute
|
||||||
|
result = httpx.post(
|
||||||
|
f"{URL}/api/v1/spool",
|
||||||
|
json={
|
||||||
|
"filament_id": random_filament["id"],
|
||||||
|
"price": 25,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert result.status_code == 400 # Cannot set price
|
||||||
@@ -16,6 +16,7 @@ def test_get_spool(random_filament: dict[str, Any]):
|
|||||||
location = "The Pantry"
|
location = "The Pantry"
|
||||||
lot_nr = "123456789"
|
lot_nr = "123456789"
|
||||||
comment = "abcdefghåäö"
|
comment = "abcdefghåäö"
|
||||||
|
price = 25
|
||||||
archived = True
|
archived = True
|
||||||
result = httpx.post(
|
result = httpx.post(
|
||||||
f"{URL}/api/v1/spool",
|
f"{URL}/api/v1/spool",
|
||||||
@@ -27,6 +28,7 @@ def test_get_spool(random_filament: dict[str, Any]):
|
|||||||
"location": location,
|
"location": location,
|
||||||
"lot_nr": lot_nr,
|
"lot_nr": lot_nr,
|
||||||
"comment": comment,
|
"comment": comment,
|
||||||
|
"price": price,
|
||||||
"archived": archived,
|
"archived": archived,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -99,6 +99,27 @@ def test_update_spool_both_used_and_remaining_weight(random_filament: dict[str,
|
|||||||
# Clean up
|
# Clean up
|
||||||
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
||||||
|
|
||||||
|
def test_update_spool_price(random_filament: dict[str, Any]):
|
||||||
|
"""Test updating a spool in the database."""
|
||||||
|
# Setup
|
||||||
|
result = httpx.post(
|
||||||
|
f"{URL}/api/v1/spool",
|
||||||
|
json={"filament_id": random_filament["id"]},
|
||||||
|
)
|
||||||
|
result.raise_for_status()
|
||||||
|
spool = result.json()
|
||||||
|
|
||||||
|
# Execute
|
||||||
|
result = httpx.patch(
|
||||||
|
f"{URL}/api/v1/spool/{spool['id']}",
|
||||||
|
json={
|
||||||
|
"price": 750,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert result.status_code == 400 # Cannot update both used and remaining weight
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
httpx.delete(f"{URL}/api/v1/spool/{spool['id']}").raise_for_status()
|
||||||
|
|
||||||
def test_update_spool_not_found(random_filament: dict[str, Any]):
|
def test_update_spool_not_found(random_filament: dict[str, Any]):
|
||||||
"""Test updating a spool that does not exist."""
|
"""Test updating a spool that does not exist."""
|
||||||
|
|||||||
Reference in New Issue
Block a user