Skip to content

Commit

Permalink
[IMP] shopinvader_api_cart: add GET /current , POST /current/sync and…
Browse files Browse the repository at this point in the history
… /current/update routes

This is done to avoid problems when adding new routes, such as /payable,
that would conflict with /{uuid}.
  • Loading branch information
marielejeune committed Jan 17, 2024
1 parent 5e49856 commit 6e1381f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions shopinvader_api_cart/routers/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


@cart_router.get("/")
@cart_router.get("/current")
@cart_router.get("/{uuid}")
def get(
env: Annotated[api.Environment, Depends(authenticated_partner_env)],
Expand All @@ -39,6 +40,7 @@ def get(


@cart_router.post("/sync", status_code=201)
@cart_router.post("/current/sync", status_code=201)
@cart_router.post("/{uuid}/sync", status_code=201)
@cart_router.post("/sync/{uuid}", status_code=201, deprecated=True)
def sync(
Expand All @@ -55,6 +57,7 @@ def sync(


@cart_router.post("/update")
@cart_router.post("/current/update")
@cart_router.post("/{uuid}/update")
@cart_router.post("/update/{uuid}", deprecated=True)
def update(
Expand Down
51 changes: 50 additions & 1 deletion shopinvader_api_cart/tests/test_shopinvader_api_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def test_get_authenticated_exists_cart_no_uuid(self) -> None:
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json()["id"], so.id)

def test_get_current(self) -> None:
"""
Check that route GET /current is reachable
"""
so = self.env["sale.order"]._create_empty_cart(
self.default_fastapi_authenticated_partner.id
)
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.get("/current")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json()["id"], so.id)

def test_sync_authenticated_no_uuid_one_transactions_no_cart_exists(self) -> None:
"""
Provide no uuid but at least one transaction. Since no cart exists,
Expand All @@ -101,6 +113,21 @@ def test_sync_authenticated_no_uuid_one_transactions_no_cart_exists(self) -> Non
so = self.env["sale.order"].browse(response_json["id"])
self.assertEqual(self.trans_uuid_1, so.applied_cart_api_transaction_uuids)

def test_sync_current_cart(self) -> None:
"""
Check that the route /current/sync is reachable.
"""
data = {
"transactions": [
{"uuid": self.trans_uuid_1, "product_id": self.product_1.id, "qty": 1}
]
}
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.post(
"/current/sync", content=json.dumps(data)
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_sync_authenticated_no_rights(self) -> None:
data = {
"transactions": [
Expand Down Expand Up @@ -430,7 +457,29 @@ def test_update(self) -> None:
self.assertEqual(so.partner_shipping_id, address)
self.assertEqual(so.partner_invoice_id, partner)

def test_deprecated_route_update_uuidq(self) -> None:
def test_route_update_current(self) -> None:
"""
Check that the route /current/update is reachable.
"""
partner = self.default_fastapi_authenticated_partner
address = self.env["res.partner"].create(
{
"name": "Delivery",
"parent_id": partner.id,
"type": "delivery",
}
)
self.env["sale.order"]._create_empty_cart(
self.default_fastapi_authenticated_partner.id
)
data = {"delivery": {"address_id": address.id}}
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.post(
"/current/update", content=json.dumps(data)
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_deprecated_route_update_uuid(self) -> None:
"""
Check that the deprecated /update/{uuid} route is still callable.
"""
Expand Down

0 comments on commit 6e1381f

Please sign in to comment.