WEBVTT

00:00.510 --> 00:03.850
In this lesson we are going to test the logging process.

00:03.870 --> 00:10.280
The first thing we're going to do is create a new test for that logging that Specter Jess.

00:10.430 --> 00:13.730
Next we're going to describe the logging.

00:13.970 --> 00:15.450
Next we'll have an each.

00:16.160 --> 00:20.150
And just so we understand exactly what we are testing.

00:20.150 --> 00:27.690
Let's open up another ball so we know and test out the logging functionality so visit local host port

00:27.690 --> 00:34.010
four thousand and one and here I'm going to register a new account.

00:37.540 --> 00:42.630
And you can see successfully register now signing with the credentials I just registered

00:46.010 --> 00:49.420
and I'll pass in a password and great.

00:49.510 --> 00:56.700
And now after registration and after successfully logging in you can see we had a successfully lasting

00:56.730 --> 00:57.440
message.

00:57.590 --> 01:03.040
We have hey doctor on this up which is the name of the newly signed ing user.

01:03.380 --> 01:08.320
We also have a logout button and a user is redirected to the homepage.

01:08.330 --> 01:11.080
So this is the exact functionality we are going to test.

01:11.090 --> 01:13.520
So I'm just going to close this window.

01:13.520 --> 01:13.990
OK.

01:14.330 --> 01:27.450
So we are going to test should logging a user flash a message and redirect to the home page.

01:27.680 --> 01:32.120
The first and most important thing for us to know is that we are not going to be communicating directly

01:32.120 --> 01:32.960
with our server.

01:32.960 --> 01:35.390
We are going to be mocking out the server.

01:35.390 --> 01:35.750
Why.

01:35.750 --> 01:41.230
Because I believe we already have integration tests testing to make sure that the EPA works correctly.

01:41.390 --> 01:48.650
And instead of sending e-mails in Cyprus yes we can simply directly go ahead and mock how the server

01:48.680 --> 01:53.940
completely and test the client site and interaction of our application.

01:54.050 --> 01:59.590
So to mark our server first we are going to call site server with this.

01:59.620 --> 02:05.470
Cyprus is automatically going to prevents any outgoing ex such our request.

02:05.500 --> 02:09.010
Next we need to register a for this.

02:09.010 --> 02:17.340
We are going to call the site of the world method in this case a Post and The End Point is API version

02:17.340 --> 02:21.460
1 of logging.

02:21.460 --> 02:26.710
This is the vault we are listening to and then here we are going to send the data that should be responded

02:26.710 --> 02:31.240
to when the client makes a call to this end point.

02:31.540 --> 02:34.420
For that we are going to get fixtures and stay with me.

02:34.420 --> 02:34.990
OK.

02:35.110 --> 02:42.850
So in the fixed just folder I'm going to rename this to user Jason and I'm going to paste this fixture

02:43.360 --> 02:50.410
this fixture is simulating the data that we are going to get from an actual API request.

02:50.410 --> 02:57.980
Now in our logging aspect we can load that feature by say inside that fixtures and the name of the fixture

02:58.020 --> 03:05.160
is the user Jason and we have which to call a method called us and this is going to be user.

03:05.250 --> 03:11.870
Now instead of passing in data here we can simply see at user and what does this mean.

03:11.910 --> 03:13.680
First we mark our server.

03:13.860 --> 03:20.340
And what this is going to Tor Cyprus to do is any outgoing API request in our client that we are testing

03:20.550 --> 03:22.400
should not be sent to the server.

03:22.470 --> 03:25.860
Instead they should be intercepted by Cyprus.

03:25.860 --> 03:29.700
Now we need to register the end point that should be intercepted by Cyprus.

03:29.790 --> 03:36.390
So we say Cyprus is not what we are registering a push toward which means any outgoing push to question

03:36.480 --> 03:42.000
this end point from application being tested by Cyprus is going to be intercepted.

03:42.210 --> 03:49.670
And Cyprus is going to respond with a two user and what is at user it's a fixture that we load it so

03:49.950 --> 03:55.650
fixtures is going to load the fixture in this user the Jason file and save it as an instance variable

03:55.650 --> 03:56.960
code user.

03:57.240 --> 03:57.940
OK.

03:58.230 --> 04:04.970
So now if I save this we have an error that's a site that fix just is not a function.

04:04.970 --> 04:06.780
And that's because it's supposed to be fixed.

04:07.230 --> 04:08.130
Sorry about that.

04:09.570 --> 04:14.520
Now if we check out our logging process you can see that a new order was registered and you can see

04:14.520 --> 04:15.510
stopped us.

04:15.540 --> 04:22.280
Yes so every API call to this end point is going to be intercepted by Cyprus and Cyprus would respond

04:22.280 --> 04:24.240
with issues other Jason data.

04:24.260 --> 04:31.730
Now let's actually take care of the logging process First we'll visit the logging Beach site at visit

04:31.940 --> 04:34.340
slash off slash logging.

04:34.340 --> 04:41.260
Next we need to select the e-mail field so Sy gets.

04:41.370 --> 04:50.870
And we're going to get an input where the name attribute is equal to e-mail and we are going to type

04:50.870 --> 04:55.660
into that e-mail field and the value is going to be an e-mail.

04:55.720 --> 05:01.450
But in this case let's just use the e-mail from our fixture because what we really type in here does

05:01.450 --> 05:11.400
not matter since we've stopped out our server then we are going to CI that gets an image where the name

05:12.120 --> 05:22.030
is password and we're going to type in that period password then sings there's just one button on the

05:22.480 --> 05:28.080
page we can get button and we can click on it now.

05:28.170 --> 05:36.650
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

05:36.650 --> 05:37.870
was successful.

05:38.000 --> 05:47.570
Our log out run the test again and you can see that's where Cyprus types into the input boxes and the

05:47.570 --> 05:50.750
user is successfully locked in.

05:50.750 --> 05:53.540
OK so I'm just going to enlarge this so you can actually see it.

05:53.540 --> 05:55.220
Well then I wonder test

05:58.420 --> 06:00.740
oh ok awesome.

06:00.790 --> 06:01.390
All right.

06:01.420 --> 06:08.500
Now we need to place in our sessions First we need to assert that the user's name matches what we expect

06:08.530 --> 06:16.610
because in our fixture we have a fixed user name so we expect that the text right here should be hey

06:16.910 --> 06:20.080
and the name of the user for that.

06:20.200 --> 06:24.770
I'm going to go to our top but the view and I'm going to add some I.D..

06:24.790 --> 06:29.900
And if you've no you never use view just before don't worry about this just simply go to the turmoil

06:30.280 --> 06:31.930
and add the I.D..

06:32.050 --> 06:37.000
So for example this text that says Please confirm your email address.

06:37.000 --> 06:40.710
I'll give it an idea of confirm e-mail.

06:40.990 --> 06:44.750
Next where we have the user's name.

06:44.750 --> 06:49.650
I'm going to give this an I.D. off of user name.

06:49.880 --> 06:51.670
And finally the logout button.

06:51.680 --> 06:57.450
I'm going to give it an A.G. of off logout OK.

06:57.450 --> 07:04.850
So now in my log in that spec I can sign that gets the element with IDC of

07:07.440 --> 07:08.580
confirmed e-mail

07:12.480 --> 07:16.880
and expect that it should contain a text.

07:16.980 --> 07:24.840
Please confirm your email address next.

07:25.170 --> 07:28.830
I'm going to get the text of off user name

07:31.990 --> 07:42.370
and assert that it should contain that text of hey Dr. and that's because in my fixed job the name of

07:42.370 --> 07:45.780
the user is Dr. next.

07:45.930 --> 07:58.430
I'm going to get the elements of auth logout and expect that it should contain logout.

07:58.450 --> 07:59.460
All right.

07:59.530 --> 08:09.560
So now I will save the G dose my Cyprus test automatically run and now we have a successful test.

08:09.710 --> 08:16.760
If we enlarge this to see our assertions you can see that everything is green and that's exactly what

08:16.760 --> 08:17.770
we want.

08:17.780 --> 08:18.420
All right.

08:18.500 --> 08:19.970
That's all I have for you guys.

08:20.030 --> 08:25.820
Hopefully this is enough information for you to get on testing all other parts of your applications.
