Skip to content

Commit

Permalink
added credit card expiration function to Finance (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-bodhi committed Jan 21, 2024
1 parent fdefa78 commit 4fd32d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 11 additions & 0 deletions include/faker-cxx/Finance.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,16 @@ class Finance
* @endcode
*/
static std::string ethereumAddress();

/**
* Generates a random expiration date.
*
* @returns std::string date.
*
* @code
* Finance::creditCardExpirationDate() // "03/26"
* @endcode
*/
static std::string creditCardExpirationDate();
};
}
6 changes: 6 additions & 0 deletions src/modules/finance/Finance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "data/CreditCardsFormats.h"
#include "data/Currencies.h"
#include "data/IbanFormats.h"
#include "faker-cxx/Date.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Number.h"
#include "faker-cxx/String.h"
Expand Down Expand Up @@ -166,4 +167,9 @@ std::string Finance::ethereumAddress()
return String::hexadecimal(40, HexCasing::Lower);
}

std::string Finance::creditCardExpirationDate()
{
const auto expirationDate = Date::futureDate(3);
return expirationDate.substr(5, 2) + "/" + expirationDate.substr(2, 2);
}
}
14 changes: 10 additions & 4 deletions src/modules/finance/FinanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ TEST_F(FinanceTest, shouldGenerateEthereumAddress)
{ return hexLowerCharacters.find(hexNumberCharacter) != std::string::npos; }));
}

TEST_F(FinanceTest, shouldGenerateExpirationDate)
{
const auto expirationDate = Finance::creditCardExpirationDate();
int tenthPlaceYear = std::stoi(expirationDate.substr(3, 2));
std::cout << expirationDate << " " << tenthPlaceYear << "\n";
ASSERT_TRUE(tenthPlaceYear >= 24);
}

class FinanceBicTest : public TestWithParam<BicCountry>
{
Expand All @@ -399,13 +406,12 @@ TEST_P(FinanceBicTest, CheckBicGenerator)

const auto& bankIdentifiersCodes = bankIdentifiersCodesMapping.at(country);

ASSERT_TRUE(std::ranges::any_of(bankIdentifiersCodes, [bic](const std::string& bankIdentifierCode) {
return bic == bankIdentifierCode;
}));
ASSERT_TRUE(std::ranges::any_of(bankIdentifiersCodes, [bic](const std::string& bankIdentifierCode)
{ return bic == bankIdentifierCode; }));
}

INSTANTIATE_TEST_SUITE_P(TestBicGenerator, FinanceBicTest,
Values(BicCountry::Poland, BicCountry::United_States, BicCountry::United_Kingdom,
BicCountry::Germany, BicCountry::Romania, BicCountry::France, BicCountry::Italy,
BicCountry::Spain, BicCountry::Netherlands, BicCountry::India),
[](const TestParamInfo<BicCountry>& info) { return generatedBicTestName.at(info.param); });
[](const TestParamInfo<BicCountry>& info) { return generatedBicTestName.at(info.param); });

0 comments on commit 4fd32d8

Please sign in to comment.