Skip to content

Commit

Permalink
productID functionality added
Browse files Browse the repository at this point in the history
  • Loading branch information
srivastava-yash committed Jan 23, 2024
1 parent 4fd32d8 commit fa2c162
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
path = externals/fmt
url = https://github.com/fmtlib/fmt.git

[submodule "externals/faker-cxx"]
path = externals/faker-cxx
url = https://github.com/cieslarmichal/faker-cxx.git
1 change: 1 addition & 0 deletions externals/faker-cxx
Submodule faker-cxx added at 4fd32d
11 changes: 11 additions & 0 deletions include/faker-cxx/Commerce.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,16 @@ class Commerce
* @endcode
*/
static std::string ISBN10();

/**
* @brief Returns a random product ID.
*
* @returns productId.
*
* @code
* Commerce::productId() // "ABCD123456"
* @endcode
*/
static std::string productId();
};
}
5 changes: 5 additions & 0 deletions src/modules/commerce/Commerce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,9 @@ std::string Commerce::ISBN10()

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

std::string Commerce::productId()
{
return String::alphaNumeric(10, StringCasing::Upper, "");
}
}
8 changes: 8 additions & 0 deletions src/modules/commerce/CommerceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ 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); }));
}

0 comments on commit fa2c162

Please sign in to comment.