From a9636bc477199f7fe35e6a3058887f49c815e3ca Mon Sep 17 00:00:00 2001 From: MichaelLog1 Date: Tue, 6 Feb 2024 22:03:25 -0500 Subject: [PATCH] Added shipping carrier data, order status data, and order number generator with unit tests. --- include/faker-cxx/Commerce.h | 36 +++++++++++++++++++++++++++ src/modules/commerce/Commerce.cpp | 15 +++++++++++ src/modules/commerce/CommerceTest.cpp | 23 +++++++++++++++++ src/modules/commerce/data/Commerce.h | 6 +++++ 4 files changed, 80 insertions(+) diff --git a/include/faker-cxx/Commerce.h b/include/faker-cxx/Commerce.h index b0f861292..34faeb4b5 100644 --- a/include/faker-cxx/Commerce.h +++ b/include/faker-cxx/Commerce.h @@ -207,5 +207,41 @@ 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(); + }; } diff --git a/src/modules/commerce/Commerce.cpp b/src/modules/commerce/Commerce.cpp index 43bf7de12..0b11fab81 100644 --- a/src/modules/commerce/Commerce.cpp +++ b/src/modules/commerce/Commerce.cpp @@ -182,4 +182,19 @@ double Commerce::productRating() { return Number::decimal(5.); } +std::string Commerce::shippingCarrier() +{ + return Helper::arrayElement(shippingCarriers); +} + +std::string Commerce::orderStatus() +{ + return Helper::arrayElement(orderStatuses); +} + +std::string Commerce::orderNumber() +{ + return String::numeric(7, true); +} + } diff --git a/src/modules/commerce/CommerceTest.cpp b/src/modules/commerce/CommerceTest.cpp index df19453e1..74bc86e18 100644 --- a/src/modules/commerce/CommerceTest.cpp +++ b/src/modules/commerce/CommerceTest.cpp @@ -256,3 +256,26 @@ 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); +} diff --git a/src/modules/commerce/data/Commerce.h b/src/modules/commerce/data/Commerce.h index 24964a7cb..e0b81e00e 100644 --- a/src/modules/commerce/data/Commerce.h +++ b/src/modules/commerce/data/Commerce.h @@ -82,4 +82,10 @@ const std::vector productReviews = { "It's difficult to operate and not user-friendly." }; +const std::vector shippingCarriers = {"UPS", "USPS", "FedEx", "DHL", "Amazon", "Ceva"}; + +const std::vector orderStatuses = {"Created", "Processing", "Shipped", "In Transit", "Accepted", "Pickup", + "Delivered", "Pending", "Confirmed", "Awaiting Fulfillment", "Backordered", + "On Hold", "Cancelled", "Refunded", "Returned", "Delayed", "Pending Payment"}; + }