Skip to content

Commit

Permalink
Added payment related functionalities to Commerce Module #483 (#495)
Browse files Browse the repository at this point in the history
* productID functionality added

* test passed

* paymentType and paymentProvider added

* minor change

* gitmodules reverted

* unwanted directory removed
  • Loading branch information
srivastava-yash committed Jan 24, 2024
1 parent 892259a commit 40ab414
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
35 changes: 35 additions & 0 deletions include/faker-cxx/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,40 @@ class Commerce
* @endcode
*/
static std::string ISBN10();

/**
* @brief Returns a random product ID.
*
* @returns productId.
*
* @code
* Commerce::productId() // "ABCD123456"
* @endcode
*/
static std::string productId();

/**
* @brief Returns a random payment type.
*
* @returns paymentType.
*
* @code
* Commerce::paymentType() // "Credit Card"
* @endcode
*/
static std::string paymentType();

/**
* @brief Returns a random payment provider.
*
* @returns paymentProvider.
*
* @code
* Commerce::paymentProvider() // "Paypal"
* @endcode
*/
static std::string paymentProvider();


};
}
15 changes: 15 additions & 0 deletions src/modules/commerce/Commerce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,19 @@ std::string Commerce::ISBN10()

return isbn10 + std::to_string(checkDigit);
}

std::string Commerce::productId()
{
return String::alphanumeric(10, StringCasing::Upper, "");
}

std::string Commerce::paymentType()
{
return Helper::arrayElement<std::string>(paymentTypes);
}

std::string Commerce::paymentProvider()
{
return Helper::arrayElement<std::string>(paymentProviders);
}
}
24 changes: 24 additions & 0 deletions src/modules/commerce/CommerceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,27 @@ TEST_F(CommerceTest, shouldGenerateIsbn10)
ASSERT_EQ(generatedIsbn10.size(), 10);
ASSERT_TRUE(sum % 11 == 0);
}

TEST_F(CommerceTest, shouldGenerateProductId)
{
const auto generatedProductId = Commerce::productId();

ASSERT_EQ(generatedProductId.length(), 10);
ASSERT_TRUE(std::ranges::all_of(generatedProductId, [](const char& c) { return std::isalnum(c); }));
}

TEST_F(CommerceTest, shouldGeneratePaymentType)
{
const auto generatedPaymentType = Commerce::paymentType();

ASSERT_TRUE(std::ranges::any_of(paymentTypes, [generatedPaymentType](const std::string& paymentType)
{ return paymentType == generatedPaymentType; }));
}

TEST_F(CommerceTest, shouldGeneratePaymentProvider)
{
const auto generatedPaymentProvider = Commerce::paymentProvider();

ASSERT_TRUE(std::ranges::any_of(paymentProviders, [generatedPaymentProvider](const std::string& paymentProvider)
{ return paymentProvider == generatedPaymentProvider; }));
}
5 changes: 5 additions & 0 deletions src/modules/commerce/data/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ const std::vector<std::string> productNames = {"Chair", "Car", "Computer", "
"Ball", "Gloves", "Pants", "Shirt", "Table", "Shoes",
"Hat", "Towels", "Soap", "Tuna", "Chicken", "Fish",
"Cheese", "Bacon", "Pizza", "Salad", "Sausages", "Chips"};

const std::vector<std::string> paymentTypes = {"Credit Card", "Debit Card", "Cash", "Bank Transfer", "Check"};

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

0 comments on commit 40ab414

Please sign in to comment.