Skip to content

Commit

Permalink
feat: fixed BDD and added create a shopcart endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
whykay-01 committed Apr 25, 2024
1 parent cce3460 commit f3905ce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
File renamed without changes.
32 changes: 32 additions & 0 deletions features/shopcarts.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

Feature: The shopcarts service back-end
As a Shopcarts Service Owner
I need a RESTful catalog service
So that I can keep track of all my shopcarts

Background:
Given the following shopcarts
| user_id |
| 1 |
| 2 |
| 3 |
And the following items
| user_id | product_name | product_id | product_price | quantity |
| 1 | MacBook 13 Pro | 1 | 1500.0 | 2 |
| 2 | MacBook 13 Air | 2 | 1000.0 | 1 |
| 2 | MacBook 13 Pro | 1 | 1500.0 | 1 |
| 1 | MacBook 15 Air | 3 | 1200.0 | 3 |
| 3 | MacBook 15 Pro | 4 | 2700.0 | 1 |


Scenario: The server is running
When I visit the "Home Page"
Then I should see "Shopcart Demo RESTful Service" in the title
And I should not see "404 Not Found"

Scenario: Create a shopcart
When I visit the "Home Page"
And I set the "Shopcart User ID" to "10"
And I press the "Create Shopcart" button
Then I should see the message "Success"

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ def step_impl(context):

# Load the database with new shopcarts
for row in context.table:
payload = {"user_id": row["user_id"]}

payload = {"user_id": row["user_id"], "items": []}
context.resp = requests.post(rest_endpoint, json=payload)
assert context.resp.status_code == HTTP_201_CREATED


@given("the following cartitems")
@given("the following items")
def step_impl(context):
"""Delete all cart items and load new ones"""

Expand All @@ -51,12 +50,13 @@ def step_impl(context):
# Load the database with new shopcarts
for row in context.table:
user_id = row["user_id"]
shopcart_id = shopcarts.get(int(user_id), None)
shopcart_id = int(shopcarts[user_id])
payload = {
"product_price": row["product_price"],
"cart_id": shopcart_id,
"product_name": row["product_name"],
"product_id": row["product_id"],
"product_price": row["product_price"],
"quantity": row["quantity"],
"shopcart_id": shopcart_id,
}

rest_endpoint = f"{context.base_url}/shopcarts/{shopcart_id}/items"
Expand Down
3 changes: 2 additions & 1 deletion features/steps/web_steps → features/steps/web_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions
import requests

# ID_PREFIX = "pet_"

Expand Down Expand Up @@ -48,7 +49,7 @@ def step_impl(context, message):
@when('I press the "{button}" button')
def step_impl(context, button):
"""Presses button on the UI"""
button_id = button.lower() + "-btn"
button_id = button.replace(" ", "-").lower() + "-btn"
context.driver.find_element(By.ID, button_id).click()


Expand Down

0 comments on commit f3905ce

Please sign in to comment.