Very new to BDD and TDD.
I have a web api (asp.net core) that allows the user to register via email and password.
On success of that the/my server will email an activation link.
This link contains a guid that is stored in a field against that user's record.
The guid is created automatically on the server.
The user will receive that email, click on that link and activate their account so they can log on.
How can I create an integration test/script for this?
is the solution to hard code the guid just for the purpose of this test? Just seems wrong to adapt the code on the server for this as it looks not like a proper test.
Any guidance on this would be great.
This is a case I would describe as a bit tricky to automate.
You can automate almost all pieces of it, but automating the entire flow would probably mean implementing a mail client. That is probably overdoing it.
I would consider verifying that a mail link is sent. I would automate that the account is activated on correct guid and that it isn't activated when an incorrect guid is presented.
Your guid is created automatically on the server. I would open up so the test script can get hold of the guid. Open up may mean that the test script can read the value from your backend or perhaps even peek into the database to get hold of it.
If you are looking for a BDD approach, almost all of his will be done under the hood. I would probably create a scenario looking something like this for the happy path
Scenario: A new user activates an account
Given that Alice want to sign up for a new account
When she activates her account
Then she is able to login
I avoid talking about technical stuff like guid here. I try to use a language a a non technical person would understand. The technical things are needed, but they can be handled on the steps supporting the automation of a scenario like this.
The sending of the guid can be implemented behind this scenario. It is probably a matter of verifying that the functionality that will do the sending is called.
The verification of the activation link can be verified as well, the support code need to either find a guid or use a hard coded. And then trigger the verification functionality.
Finally, with an activated account, Alice will be able to login.