Skip to content

Commit

Permalink
paymentType and paymentProvider added
Browse files Browse the repository at this point in the history
  • Loading branch information
srivastava-yash committed Jan 24, 2024
1 parent 2ba4cec commit 4ce61a1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
24 changes: 24 additions & 0 deletions include/faker-cxx/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,29 @@ class Commerce
* @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();


};
}
10 changes: 10 additions & 0 deletions src/modules/commerce/Commerce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,14 @@ 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);
}
}
16 changes: 16 additions & 0 deletions src/modules/commerce/CommerceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,19 @@ TEST_F(CommerceTest, shouldGenerateProductId)
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 4ce61a1

Please sign in to comment.