In this lesson we are going to test the logging process.
The first thing we're going to do is create a new test for that logging that Specter Jess.
Next we're going to describe the logging.
Next we'll have an each.
And just so we understand exactly what we are testing.
Let's open up another ball so we know and test out the logging functionality so visit local host port
four thousand and one and here I'm going to register a new account.
And you can see successfully register now signing with the credentials I just registered
and I'll pass in a password and great.
And now after registration and after successfully logging in you can see we had a successfully lasting
message.
We have hey doctor on this up which is the name of the newly signed ing user.
We also have a logout button and a user is redirected to the homepage.
So this is the exact functionality we are going to test.
So I'm just going to close this window.
OK.
So we are going to test should logging a user flash a message and redirect to the home page.
The first and most important thing for us to know is that we are not going to be communicating directly
with our server.
We are going to be mocking out the server.
Why.
Because I believe we already have integration tests testing to make sure that the EPA works correctly.
And instead of sending e-mails in Cyprus yes we can simply directly go ahead and mock how the server
completely and test the client site and interaction of our application.
So to mark our server first we are going to call site server with this.
Cyprus is automatically going to prevents any outgoing ex such our request.
Next we need to register a for this.
We are going to call the site of the world method in this case a Post and The End Point is API version
1 of logging.
This is the vault we are listening to and then here we are going to send the data that should be responded
to when the client makes a call to this end point.
For that we are going to get fixtures and stay with me.
OK.
So in the fixed just folder I'm going to rename this to user Jason and I'm going to paste this fixture
this fixture is simulating the data that we are going to get from an actual API request.
Now in our logging aspect we can load that feature by say inside that fixtures and the name of the fixture
is the user Jason and we have which to call a method called us and this is going to be user.
Now instead of passing in data here we can simply see at user and what does this mean.
First we mark our server.
And what this is going to Tor Cyprus to do is any outgoing API request in our client that we are testing
should not be sent to the server.
Instead they should be intercepted by Cyprus.
Now we need to register the end point that should be intercepted by Cyprus.
So we say Cyprus is not what we are registering a push toward which means any outgoing push to question
this end point from application being tested by Cyprus is going to be intercepted.
And Cyprus is going to respond with a two user and what is at user it's a fixture that we load it so
fixtures is going to load the fixture in this user the Jason file and save it as an instance variable
code user.
OK.
So now if I save this we have an error that's a site that fix just is not a function.
And that's because it's supposed to be fixed.
Sorry about that.
Now if we check out our logging process you can see that a new order was registered and you can see
stopped us.
Yes so every API call to this end point is going to be intercepted by Cyprus and Cyprus would respond
with issues other Jason data.
Now let's actually take care of the logging process First we'll visit the logging Beach site at visit
slash off slash logging.
Next we need to select the e-mail field so Sy gets.
And we're going to get an input where the name attribute is equal to e-mail and we are going to type
into that e-mail field and the value is going to be an e-mail.
But in this case let's just use the e-mail from our fixture because what we really type in here does
not matter since we've stopped out our server then we are going to CI that gets an image where the name
is password and we're going to type in that period password then sings there's just one button on the
page we can get button and we can click on it now.
I'll save this and as a test one if you watch that's very closely you're going to see that the log in
was successful.
Our log out run the test again and you can see that's where Cyprus types into the input boxes and the
user is successfully locked in.
OK so I'm just going to enlarge this so you can actually see it.
Well then I wonder test
oh ok awesome.
All right.
Now we need to place in our sessions First we need to assert that the user's name matches what we expect
because in our fixture we have a fixed user name so we expect that the text right here should be hey
and the name of the user for that.
I'm going to go to our top but the view and I'm going to add some I.D..
And if you've no you never use view just before don't worry about this just simply go to the turmoil
and add the I.D..
So for example this text that says Please confirm your email address.
I'll give it an idea of confirm e-mail.
Next where we have the user's name.
I'm going to give this an I.D. off of user name.
And finally the logout button.
I'm going to give it an A.G. of off logout OK.
So now in my log in that spec I can sign that gets the element with IDC of
confirmed e-mail
and expect that it should contain a text.
Please confirm your email address next.
I'm going to get the text of off user name
and assert that it should contain that text of hey Dr. and that's because in my fixed job the name of
the user is Dr. next.
I'm going to get the elements of auth logout and expect that it should contain logout.
All right.
So now I will save the G dose my Cyprus test automatically run and now we have a successful test.
If we enlarge this to see our assertions you can see that everything is green and that's exactly what
we want.
All right.
That's all I have for you guys.
Hopefully this is enough information for you to get on testing all other parts of your applications.