Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shipping carrier data, order status data, and order number gene… #504

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions include/faker-cxx/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,42 @@ class Commerce
static double productRating();

/**

* @brief Returns a random shipping carrier.
*
* @returns shippingCarrier
*
* @code
* Commerce::shippingCarrier() // "UPS"
*
* @endcode
*/
static std::string shippingCarrier();

/**
* @brief Returns a random order status.
*
* @returns orderStatus
*
* @code
* Commerce::orderStatus() // "Shipped"
*
* @endcode
*/
static std::string orderStatus();

/**
* @brief Returns a random order number (7-digit)
*
* @returns orderNumber
*
* @code
* Commerce::shippingCarrier() // "1045823"
*
* @endcode
*/
static std::string orderNumber();

* @brief Returns a random discount type.
*
* @returns discountType.
Expand Down
15 changes: 15 additions & 0 deletions src/modules/commerce/Commerce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,19 @@ double Commerce::discountPercentage() {
return std::ceil(percentageValue * 100) / 100;
}

std::string Commerce::shippingCarrier()
{
return Helper::arrayElement<std::string>(shippingCarriers);
}

std::string Commerce::orderStatus()
{
return Helper::arrayElement<std::string>(orderStatuses);
}

std::string Commerce::orderNumber()
{
return String::numeric(7, true);
}

}
24 changes: 23 additions & 1 deletion src/modules/commerce/CommerceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,29 @@ TEST_F(CommerceTest, shouldGenerateProductRating)
ASSERT_TRUE(0. <= generatedProductRating && generatedProductRating <= 5.);
}

TEST_F(CommerceTest, shouldGenerateShippingCarrier)
{
const auto generatedShippingCarrier = Commerce::shippingCarrier();

ASSERT_TRUE(std::ranges::any_of(shippingCarriers, [generatedShippingCarrier](const std::string& shippingCarrier)
{ return shippingCarrier == generatedShippingCarrier; }));
}

TEST_F(CommerceTest, shouldGenerateOrderStatus)
{
const auto generatedOrderStatus = Commerce::orderStatus();

ASSERT_TRUE(std::ranges::any_of(orderStatuses, [generatedOrderStatus](const std::string& orderStatus)
{ return orderStatus == generatedOrderStatus; }));
}

TEST_F(CommerceTest, shouldGenerateOrderNumber)
{
const auto generatedOrderNumber = Commerce::orderNumber();

ASSERT_TRUE(generatedOrderNumber.size() == 7);
}

TEST_F(CommerceTest, shouldGenerateDiscountType)
{
const auto generatedDiscountType = Commerce::discountType();
Expand Down Expand Up @@ -295,4 +318,3 @@ TEST_F(CommerceTest, shouldGenerateDiscountPercentage)

ASSERT_TRUE(kMinDiscountPercentageValue <= generatedDiscountPercentage && generatedDiscountPercentage <= kMaxDiscountPercentageValue);
}

6 changes: 6 additions & 0 deletions src/modules/commerce/data/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ const std::vector<std::string> productReviews = {
"It's difficult to operate and not user-friendly."
};

const std::vector<std::string> shippingCarriers = {"UPS", "USPS", "FedEx", "DHL", "Amazon", "Ceva"};

const std::vector<std::string> orderStatuses = {"Created", "Processing", "Shipped", "In Transit", "Accepted", "Pickup",
"Delivered", "Pending", "Confirmed", "Awaiting Fulfillment", "Backordered",
"On Hold", "Cancelled", "Refunded", "Returned", "Delayed", "Pending Payment"};

const std::vector<std::string> discountTypes = {"percentage", "value"};

}
Loading