Skip to content

Commit

Permalink
Feature/product functions (#503)
Browse files Browse the repository at this point in the history
* Added product functions to Commerce module

* Fixed typo
  • Loading branch information
PlungedInCode committed Feb 6, 2024
1 parent a6fa4c5 commit da2c92c
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 0 deletions.
43 changes: 43 additions & 0 deletions include/faker-cxx/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,49 @@ class Commerce
*/
static std::string paymentProvider();

/**
* @brief Returns a random product description.
*
* @returns productDescription.
*
* @code
* Commerce::productDescription() // "Elevate your lifestyle with premium quality product."
* @endcode
*/
static std::string productDescription();

/**
* @brief Returns a random product category.
*
* @returns productCategory.
*
* @code
* Commerce::productCategory() // "Electronics"
* @endcode
*/
static std::string productCategory();

/**
* @brief Returns a random product review.
*
* @returns productReview.
*
* @code
* Commerce::productReview() // "Unfortunately, it broke shortly after I started using it."
* @endcode
*/
static std::string productReview();

/**
* @brief Returns a random product rating (0-5).
*
* @returns productRating.
*
* @code
* Commerce::productRating() // 4.1
* @endcode
*/
static double productRating();

};
}
18 changes: 18 additions & 0 deletions src/modules/commerce/Commerce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,22 @@ std::string Commerce::paymentProvider()
{
return Helper::arrayElement<std::string>(paymentProviders);
}

std::string Commerce::productDescription() {
return Helper::arrayElement<std::string>(productDescriptions);
}

std::string Commerce::productCategory()
{
return Helper::arrayElement<std::string>(productCategoryNames);
}

std::string Commerce::productReview() {
return Helper::arrayElement<std::string>(productReviews);
}

double Commerce::productRating() {
return Number::decimal<double>(5.);
}

}
31 changes: 31 additions & 0 deletions src/modules/commerce/CommerceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,34 @@ TEST_F(CommerceTest, shouldGeneratePaymentProvider)
ASSERT_TRUE(std::ranges::any_of(paymentProviders, [generatedPaymentProvider](const std::string& paymentProvider)
{ return paymentProvider == generatedPaymentProvider; }));
}

TEST_F(CommerceTest, shouldGenerateProductDescription)
{
const auto generatedProductDescription = Commerce::productDescription();

ASSERT_TRUE(std::ranges::any_of(productDescriptions, [generatedProductDescription](const std::string& productDescription)
{ return productDescription == generatedProductDescription; }));
}

TEST_F(CommerceTest, shouldGenerateProductCategory)
{
const auto generatedProductCategory = Commerce::productCategory();

ASSERT_TRUE(std::ranges::any_of(productCategoryNames, [generatedProductCategory](const std::string& productCategory)
{ return productCategory == generatedProductCategory; }));
}

TEST_F(CommerceTest, shouldGenerateProductReview)
{
const auto generatedProductReview = Commerce::productReview();

ASSERT_TRUE(std::ranges::any_of(productReviews, [generatedProductReview](const std::string& productReview)
{ return productReview == generatedProductReview; }));
}

TEST_F(CommerceTest, shouldGenerateProductRating)
{
const auto generatedProductRating = Commerce::productRating();

ASSERT_TRUE(0. <= generatedProductRating && generatedProductRating <= 5.);
}
55 changes: 55 additions & 0 deletions src/modules/commerce/data/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,59 @@ const std::vector<std::string> paymentTypes = {"Credit Card", "Debit Card", "Cas

const std::vector<std::string> paymentProviders = {"Stripe", "Paypal", "Square", "Helcim", "Merchant One",
"Flagship Merchant Services", "Stax"};

const std::vector<std::string> productDescriptions = {
"Experience convenience and efficiency with innovative solution.",
"Elevate your lifestyle with premium quality product.",
"Unlock endless possibilities with versatile tool, offering flexibility and adaptability,",
"Enhance your performance with cutting-edge technology.",
"Discover the perfect balance of style and functionality with sleek design.",
"Embrace comfort and luxury with indulgent product.",
"Achieve peace of mind with reliable solution, providing stability and assurance in every use.",
"Ignite your creativity with versatile accessory.",
"Experience the difference with high-performance product, engineered for superior quality.",
"Simplify your life with user-friendly solution, designed with intuitive features .",
"Upgrade your everyday routine with essential product, adding convenience and efficiency to your tasks.",
"Stay connected and productive with innovative technology, keeping you in control and on top of your game.",
"Make a statement with stylish addition, adding a touch of elegance and sophistication to any setting.",
"Experience reliability like never before with dependable product, ensuring consistent performance day in and day out.",
"Unleash your potential with versatile tool, empowering you to tackle any challenge and achieve your goals.",
"Experience comfort redefined with ergonomic design, prioritizing your well-being and comfort in every use.",
"Optimize your efficiency with streamlined solution, eliminating unnecessary steps and maximizing productivity.",
"Experience durability and longevity with rugged construction, built to withstand the test of time and rigorous use."
};

const std::vector<std::string> productCategoryNames = {
"Art and Craft", "Baby Products", "Beauty Products",
"Board Games and Puzzles", "Books and Stationery", "Clothing, Shoes, and Jewelry",
"Electronics", "Fitness Equipment", "Furniture and Furnishings",
"Health and Wellness", "Home Decor", "Kitchen Appliances",
"Musical Instruments", "Office Supplies", "Outdoor Gear",
"Pet Supplies", "Photography Equipment", "Sporting Goods",
"Tech Gadgets", "Toys"
};

const std::vector<std::string> productReviews = {
"This product exceeded my expectations.",
"I'm thrilled with the quality of this purchase.",
"This product is worth every penny.",
"I'm impressed with how well it performs.",
"I've been using it for a while now, and it hasn't disappointed.",
"It's okay, but nothing special.",
"I'm on the fence about this product.",
"There are pros and cons to this purchase.",
"It's neither good nor bad, just average.",
"I have mixed feelings about this product.",
"It's decent, but there's room for improvement.",
"It meets my basic needs, but there are better options out there.",
"I would consider it if you're on a budget.",
"Not bad, but not great either.",
"It's acceptable, but I expected more for the price.",
"I was disappointed with the overall quality of this product.",
"Unfortunately, it broke shortly after I started using it.",
"I found it to be overpriced for what it offers.",
"It feels cheaply made and lacks durability.",
"It's difficult to operate and not user-friendly."
};

}

0 comments on commit da2c92c

Please sign in to comment.