faker icon indicating copy to clipboard operation
faker copied to clipboard

In email functionality : Second name is not appending in email most of the time

Open Pandicool opened this issue 3 years ago • 5 comments

Describe the bug

Trying to create 100 emails with first name, second name, and provider. but generating email doesn't have a second name most of the time.

Reproduction

Code:

const firstName = "groot"; const secondName = "at"; const random = Math.floor(Math.random() *100000); secondName = secondName+random; console.log("First name: ",firstName,"Second name : ",secondName) const email = faker.internet.email(firstName,secondName,provider).replace(/[^a-zA-Z0-9@.]/g, ""); console.log(email);

Response:

[0-0] First name: groot Second name: at29913 [0-0] [email protected] [0-0] First name: groot Second name: at30314 [0-0] [email protected] [0-0] First name: groot Second name: at13277 [0-0] [email protected] [0-0] First name: groot Second name: at60615 [0-0] [email protected] [0-0] First name: groot Second name: at84925 [0-0] [email protected] [0-0] First name: groot Second name: at67487 [0-0] [email protected] [0-0] First name: groot Second name: at1124 [0-0] [email protected] [0-0] First name: groot Second name: at15594 [0-0] [email protected] [0-0] First name: groot Second name: at77943 [0-0] [email protected] [0-0] First name: groot Second name: at66877 [0-0] [email protected] [0-0] First name: groot Second name: at73118 [0-0] [email protected] [0-0] First name: groot Second name: at43517 [0-0] [email protected] [0-0] First name: groot Second name: at66282 [0-0] [email protected] [0-0] First name: groot Second name: at4783 [0-0] [email protected] [0-0] First name: groot Second name: at80369 [0-0] [email protected] [0-0] First name: groot Second name: at98724 [0-0] [email protected] [0-0] First name: groot Second name: at42108 [0-0] [email protected] [0-0] First name: groot Second name: at23822 [0-0] [email protected] [0-0] First name: groot Second name: at75730 [0-0] [email protected] [0-0] First name: groot Second name: at17076 [0-0] [email protected] [0-0] First name: groot Second name: at27913 [0-0] [email protected] [0-0] First name: groot Second name: at6139 [0-0] [email protected] [0-0] First name: groot Second name: at29583 [0-0] [email protected] [0-0] First name: groot Second name: at34788 [0-0] [email protected] [0-0] First name: groot Second name: at53021 [0-0] [email protected] [0-0] First name: groot Second name: at91160 [0-0] [email protected] [0-0] First name: groot Second name: at74768 [0-0] [email protected] [0-0] First name: groot Second name: at41251 [0-0] [email protected]

Additional Info

in above response most of the time second name is not appending please check on that issue

Pandicool avatar May 25 '22 05:05 Pandicool

Shinigami92 could you please confirm this issue is persist

Pandicool avatar May 25 '22 10:05 Pandicool

https://github.com/faker-js/faker/blob/4e38a7083ab02567c019b3078b63801fe73a4333/src/modules/internet/index.ts#L78-L80 https://github.com/faker-js/faker/blob/4e38a7083ab02567c019b3078b63801fe73a4333/src/modules/internet/index.ts#L129-L151

From the code, it looks like this is expected behavior.

ST-DDT avatar May 25 '22 10:05 ST-DDT

This issue appears to have been alluded to in #1044 with reference to unpredictable data in tests.

The behavior is expected, but should it really be desired? It seems to me that if a user provides a last name to userName() and email(), the last name should be included in the username and email. Interested in the reasoning behind the current solution.

Apologies if this is already being addressed!

kris71990 avatar Jun 24 '22 21:06 kris71990

The behavior is expected, but should it really be desired?

IMO If the users wants to have email-adresses that are always [email protected], then they could generate them exactly like that. The email address method adds some variation to the generated email addresses.

Maybe, we could add/change the methods to use an address/name part, that is always used as is.

ST-DDT avatar Jun 24 '22 22:06 ST-DDT

IMO If the users wants to have email-adresses that are always [email protected], then they could generate them exactly like that. The email address method adds some variation to the generated email addresses.

Fair enough; I certainly wouldn't want to sacrifice any variety. Just not sure why the last name couldn't be included every time if provided.

Maybe, we could add/change the methods to use an address/name part, that is always used as is.

I like this idea.

kris71990 avatar Jun 24 '22 23:06 kris71990

Team decision

We should change the email function to take the inputs more into account.

If parameters are passed to the method, then we will specific patterns to use them. If no parameters are passed to the method, then we randomly generate the username using fake patterns.

ST-DDT avatar Jan 19 '23 17:01 ST-DDT

Hi, sorry I'm late to the party I needed some time for my sanity, but anyways

This was always something I had back in my mind I wanted to have changed in faker This is a "left-over" from pre v6 times of faker

I would like to change the behavior of this method alongside with

  • #1349

Then we can re-code it to userName({ firstName, lastName }: { firstName?: string, lastName?: string } = {}): string This has the benefit that you can pass lastName without firstName and vice versa or just both (or non of both) Then the userName method takes everything into account that was passed into it, always, everything $$$ profit

Shinigami92 avatar Jan 20 '23 20:01 Shinigami92

Nice to see this issue bumped, and agree with all the reasoning here.

I would tackle this myself but unfortunately I don't think I can dedicate any time to it very soon.

kris71990 avatar Jan 21 '23 03:01 kris71990

I came here to log this issue as well, hope it gets fixed soon!

R-Strouse avatar Aug 29 '23 23:08 R-Strouse