1
00:00:01,530 --> 00:00:06,180
So let's have a look at our tests, which we haven't looked at in a while, so things probably won't

2
00:00:06,180 --> 00:00:08,310
work as expected, but we can resolve that.

3
00:00:08,820 --> 00:00:14,100
So I've opened a terminal window and I'm in the correct directory because I'm testing my handlers.

4
00:00:14,430 --> 00:00:16,540
So let's run the tests and see what happens.

5
00:00:16,590 --> 00:00:27,240
Go, go test dash the current directory and immediately it says can't find the function human date.

6
00:00:27,360 --> 00:00:31,410
And that makes sense because we've made some changes to our code.

7
00:00:32,220 --> 00:00:38,190
So in our setup test go, which is in Setar Handler's folder, inside her internals folder, there's

8
00:00:38,190 --> 00:00:39,730
a few changes I need to make right away.

9
00:00:40,140 --> 00:00:45,640
So right away, you see that I have this function, this variable functions, which is of template fungimap

10
00:00:45,690 --> 00:00:46,440
and that's empty.

11
00:00:46,800 --> 00:00:52,020
And if you look at our render package where that function is actually defined, we actually have, you

12
00:00:52,020 --> 00:00:53,060
know, some functions now.

13
00:00:53,070 --> 00:00:54,120
So let's copy those.

14
00:00:54,240 --> 00:00:59,190
I'll just copy this whole variable and then modify it as necessary.

15
00:01:00,210 --> 00:01:05,490
So in our setup test, I'm going to replace this one, which doesn't work with this one.

16
00:01:06,000 --> 00:01:09,300
And of course, I need to actually point to the render package.

17
00:01:09,690 --> 00:01:14,040
So I'll put render there and copy and paste it in front of all of these.

18
00:01:15,610 --> 00:01:20,870
And while I'm at it and see that I have ghab register here, but I know I've added more things.

19
00:01:20,910 --> 00:01:24,570
Let's go back to Minogue, go and see what we have in our gub register a bit.

20
00:01:25,080 --> 00:01:30,420
We have all of this, so I'll copy those because I know that's going to have to be there and replace

21
00:01:30,420 --> 00:01:31,910
what's in here with that.

22
00:01:32,250 --> 00:01:34,240
And let's try our tests again and see what happens.

23
00:01:34,650 --> 00:01:35,730
So clear the screen.

24
00:01:37,100 --> 00:01:41,090
Cancel go test Dash V..

25
00:01:44,230 --> 00:01:49,780
All right, so there's some fails there and the fails are all got three 07 wanted 303.

26
00:01:50,170 --> 00:01:51,220
Well, that's kind of strange.

27
00:01:51,220 --> 00:01:52,090
What's going on there?

28
00:01:52,870 --> 00:01:59,380
Well, it turns out and I do this all the time in my handlers, I have often put this status temporary

29
00:01:59,380 --> 00:02:01,840
redirect, which is not the right status for some reason.

30
00:02:01,840 --> 00:02:04,330
I always confuse that with status.

31
00:02:04,330 --> 00:02:10,840
See other if you look at the redirect, it actually says redirect replies to the request with a redirect

32
00:02:10,840 --> 00:02:13,380
to your URL, which may be a path relative, blah, blah, blah.

33
00:02:13,660 --> 00:02:19,120
The provided status code should be in the 300 range and is usually status move permanently, status

34
00:02:19,120 --> 00:02:21,520
not found or status C other.

35
00:02:22,180 --> 00:02:26,590
So I'm going to fix that and I'm going to fix it by doing a global search and replace in my handler's

36
00:02:26,590 --> 00:02:27,130
package.

37
00:02:28,360 --> 00:02:41,350
I will find and replace this which is active status, temporary redirect with HTP status C other.

38
00:02:41,560 --> 00:02:44,080
Let's replace all and see how that's working.

39
00:02:45,670 --> 00:02:46,960
All right, so let's try that.

40
00:02:47,140 --> 00:02:51,550
Go back here, clear the screen and run that test again and see what else is failing.

41
00:02:53,910 --> 00:02:59,610
So everything, everything past except for internal handlers, so where's the fail test repository,

42
00:02:59,610 --> 00:03:04,350
post reservation and return the wrong response code invalid got three or three, one or 200.

43
00:03:04,830 --> 00:03:05,910
So let's see where that is.

44
00:03:05,910 --> 00:03:11,070
That is under handlers test line 238.

45
00:03:11,070 --> 00:03:13,320
So let's go to line 238 of handlers test.

46
00:03:14,870 --> 00:03:22,100
238, and we're saying we should be getting status, OK, and we got what do we get instead?

47
00:03:24,050 --> 00:03:30,230
Got three or three wanted 200 for post reservation handler handlers, test line 238.

48
00:03:30,830 --> 00:03:36,580
So let's find our handlers and find post reservation.

49
00:03:37,910 --> 00:03:41,720
And where is this feeling it after we call post reservation?

50
00:03:41,720 --> 00:03:52,330
And the case here is a test for invalid remedy, start date and date, first date time invalid remedy.

51
00:03:52,550 --> 00:04:01,430
So when I get an invalid remedy in the handlers, that's after a validation and it's returning us to

52
00:04:01,460 --> 00:04:03,770
invalid data status c other.

53
00:04:05,360 --> 00:04:07,220
So it's redirecting us with status.

54
00:04:07,220 --> 00:04:07,940
C other.

55
00:04:13,740 --> 00:04:17,700
It's after the form valid, aha, so first of all, let's get rid of this error message.

56
00:04:17,710 --> 00:04:24,520
I don't need that anymore and this is actually going to render 200, so that should be status, OK?

57
00:04:24,540 --> 00:04:26,540
So here I have the wrong status.

58
00:04:26,550 --> 00:04:27,630
There should be status.

59
00:04:27,660 --> 00:04:28,170
OK.

60
00:04:30,590 --> 00:04:35,750
Because it's actually rendering the page, the status is OK, it's rendering the page with our invalid

61
00:04:35,750 --> 00:04:36,470
form data.

62
00:04:36,620 --> 00:04:38,040
Let's see what happens now.

63
00:04:39,020 --> 00:04:40,400
Go test.

64
00:04:44,270 --> 00:04:47,210
And one more Faile got three or three wanted 303.

65
00:04:47,240 --> 00:04:55,100
That makes no sense, 214, my global search and replace may have not been ideal line 214.

66
00:04:58,150 --> 00:05:07,750
So this is calling for what case now test for invalid remedies if our code is not status, OK, wanted.

67
00:05:09,260 --> 00:05:14,480
This budget that got three or three wanted 303.

68
00:05:17,560 --> 00:05:18,900
This should be status, OK?

69
00:05:23,720 --> 00:05:25,370
Because that's we're checking for here.

70
00:05:26,450 --> 00:05:31,240
Got three or three from post reservation with Invalid Remedy.

71
00:05:33,270 --> 00:05:42,930
So post reservation invalid remedy renders the template, model, template just OK.

72
00:05:42,980 --> 00:05:43,790
So that's OK.

73
00:05:48,910 --> 00:05:53,450
Got three or three, wanted 200, why am I getting three or three handlers, Tesco 214?

74
00:05:54,250 --> 00:05:55,900
This is why we write tests.

75
00:05:55,900 --> 00:06:01,090
Handlers go to 14, post reservation, handwritten Roller's post code for invalid remedy.

76
00:06:01,090 --> 00:06:02,910
And I'm passing an invalid remedy.

77
00:06:03,400 --> 00:06:10,540
And in my handler, when I get an invalid room ID, it is right here.

78
00:06:14,360 --> 00:06:18,570
So that's what I'm passing the remedy is giving me a status, see other OK.

79
00:06:18,590 --> 00:06:25,010
So what it should be giving me for that invalid data in my handler's test is a status of the other status.

80
00:06:25,040 --> 00:06:26,840
The other tried this one more time.

81
00:06:31,570 --> 00:06:32,200
That's good.

82
00:06:32,230 --> 00:06:37,870
All right, so now we've at least got our tests working, but our coverage is really bad, so I'll run

83
00:06:37,870 --> 00:06:40,090
my coverage and have a look at this.

84
00:06:41,960 --> 00:06:47,900
It pops this up, everything here is covered, everything here is covered, we get all the way down

85
00:06:47,900 --> 00:06:50,960
to here.

86
00:06:51,080 --> 00:06:52,660
So let's do the show login page.

87
00:06:52,730 --> 00:06:57,650
That would be a good one to to run a table driven test for.

88
00:06:58,040 --> 00:07:06,230
So let's close this and close this and go back to our tests and write a test for what I'm going to do

89
00:07:06,230 --> 00:07:12,860
is read a test, first of all, for anything that I can with as little effort as possible just by adapting

90
00:07:12,860 --> 00:07:14,840
my my table driven tests.

91
00:07:15,800 --> 00:07:18,800
So we have some routes that we're not actually testing.

92
00:07:18,800 --> 00:07:23,240
Like, for example, we never bothered to test for an invalid route, one that doesn't exist at all.

93
00:07:23,330 --> 00:07:29,090
So I'll just say the name of this test will be non-existent because it's a nonexistent route.

94
00:07:29,240 --> 00:07:36,800
And I'll put in something that I know doesn't exist, green eggs and ham, and that should give me an

95
00:07:36,800 --> 00:07:40,520
HBP status not found.

96
00:07:41,830 --> 00:07:43,610
OK, so what am I missing in there?

97
00:07:43,610 --> 00:07:44,750
It'll be a get request.

98
00:07:47,920 --> 00:07:52,240
Let's run that test, make sure that's going to work as expected, so go test.

99
00:07:54,670 --> 00:08:01,960
Perfect, but we also have a bunch of other routes that don't exist at all in our test file, and those

100
00:08:01,990 --> 00:08:06,900
would be ones like, well, let's see what we have in here in our set up test where we define our routes.

101
00:08:07,780 --> 00:08:08,740
They're here somewhere.

102
00:08:13,590 --> 00:08:20,570
Right here, so we've gone as far as make reservation, get and post and reservation summary in our

103
00:08:20,570 --> 00:08:26,060
routes file, we actually have these ones, user log in, user log.

104
00:08:26,220 --> 00:08:28,700
So copy those and put them in our setup test.

105
00:08:28,710 --> 00:08:33,920
I'm going to copy all the routes that don't currently exist and get rid of the handler's part because

106
00:08:33,920 --> 00:08:35,210
we're in the handler's package.

107
00:08:41,460 --> 00:08:47,250
And all of our admin rates as well, so it's Capito's, even though I'm not going to do them all for

108
00:08:47,250 --> 00:08:50,340
you in this lecture, we are, of course, going to test them all.

109
00:08:50,340 --> 00:08:51,540
So we may as well put them in there.

110
00:08:53,370 --> 00:08:56,910
And they don't need to be wrapped in anything because we're actually just testing the handlers, not

111
00:08:56,910 --> 00:08:57,840
our authentication.

112
00:08:57,960 --> 00:09:01,290
So get rid of that and that.

113
00:09:07,280 --> 00:09:12,350
Given my experience with global search and replace a moment ago, I am not going to do it this time

114
00:09:12,350 --> 00:09:12,740
around.

115
00:09:14,990 --> 00:09:16,280
I'll just do it manually.

116
00:09:18,690 --> 00:09:23,970
OK, so there's all of our roots, let's make sure they still work in our tests, that nothing broke.

117
00:09:25,470 --> 00:09:25,900
Good.

118
00:09:26,820 --> 00:09:30,750
Now, let's go back to our handlers test and see what other routes I can actually do.

119
00:09:30,750 --> 00:09:33,130
So new routes.

120
00:09:33,960 --> 00:09:40,430
I want to test for, say, log in just to see if the page shows up and the path for that.

121
00:09:40,590 --> 00:09:44,660
The route for that is slash user slash log in.

122
00:09:45,840 --> 00:09:52,540
It is a get request and I should see htp dot status OK for that one.

123
00:09:53,130 --> 00:09:54,080
So that's the first one.

124
00:09:54,330 --> 00:09:57,540
We also have a log entry and this gets should be in quotes.

125
00:10:02,020 --> 00:10:07,480
That also is a get request, so I should be able to run that test with no extra effort whatsoever in

126
00:10:07,480 --> 00:10:12,700
the same way the roll call, this log out will call this the dashboard.

127
00:10:15,090 --> 00:10:20,490
And that path for that one is admin dashboard.

128
00:10:23,220 --> 00:10:25,320
And that should just render properly good.

129
00:10:27,180 --> 00:10:30,810
And we also have one for it, new reservations.

130
00:10:30,810 --> 00:10:36,930
So new regs, new reservations, no reservations, new.

131
00:10:41,690 --> 00:10:49,220
And reservations, all OK, so those ones I should be able to check pretty easily and then I also should

132
00:10:49,220 --> 00:10:56,060
be able to show reservation, so let's do that one surance and the path for that or the are for that

133
00:10:56,060 --> 00:11:00,730
is admin reservations new and one.

134
00:11:01,580 --> 00:11:06,830
And since our test repo is actually just returning value and doesn't do any logic, this should all

135
00:11:06,860 --> 00:11:07,280
work.

136
00:11:07,520 --> 00:11:08,400
Let's see if it does.

137
00:11:08,420 --> 00:11:10,520
So clear the screen go test.

138
00:11:12,730 --> 00:11:18,500
And we have one fail, and that is expected 200 got four or four for Dashboard, I must have a path

139
00:11:18,520 --> 00:11:20,080
name wrong in here somehow.

140
00:11:21,070 --> 00:11:25,320
So admin dashboard, admin dashboard get status.

141
00:11:25,330 --> 00:11:30,340
OK, but I spelled out wrong, DHS, HBO, JRD.

142
00:11:33,720 --> 00:11:37,900
Now still going to fall for I must not have copy the route.

143
00:11:39,810 --> 00:11:43,860
Oh, yes, I've got to put it in front of all these because they're not grouped.

144
00:11:44,650 --> 00:11:46,650
I actually have to put them in their.

145
00:11:54,930 --> 00:11:57,360
Oops, look, I had an extra one in all of those.

146
00:11:57,540 --> 00:11:58,080
I do.

147
00:12:07,510 --> 00:12:13,360
So I have to added many here, because in the routes file, the admin is actually added by this group

148
00:12:13,570 --> 00:12:17,980
here where I put admin in mux route and I'm not using that here.

149
00:12:17,980 --> 00:12:20,920
So let's try this one more time.

150
00:12:21,520 --> 00:12:22,300
Go test.

151
00:12:24,990 --> 00:12:35,640
One more fail, 200, but got four or five show reds, 200 or five, so that is show race that is under

152
00:12:35,640 --> 00:12:42,240
the handlers test shows, admin reservations, new one show.

153
00:12:46,170 --> 00:12:48,450
Yeah, I left the show off of there.

154
00:12:49,230 --> 00:12:51,350
OK, one more try.

155
00:12:53,120 --> 00:12:54,090
OK, they passed.

156
00:12:54,110 --> 00:12:58,580
Now let's check our coverage and see what else has been covered already just by adding those to our

157
00:12:58,580 --> 00:12:59,620
table driven test.

158
00:13:01,460 --> 00:13:02,240
This is good.

159
00:13:02,720 --> 00:13:05,810
This is good all the way down.

160
00:13:05,820 --> 00:13:09,200
So show log in is now rendered and that's actually working.

161
00:13:09,530 --> 00:13:12,560
Hoshko log in, though, is not logout is.

162
00:13:12,980 --> 00:13:16,250
So we have a lot more covered just by adding that to our table driven test.

163
00:13:17,300 --> 00:13:21,910
So let's test this one which is post show log in.

164
00:13:21,920 --> 00:13:25,300
I want to test this one because there's a lot of cases I can test there pretty easily.

165
00:13:25,760 --> 00:13:29,570
So let me go over to my code and go to my handlers test.

166
00:13:29,570 --> 00:13:34,640
And right at the bottom, I'll go to the very bottom and I'll create a new test just before this.

167
00:13:34,640 --> 00:13:35,650
Get the context.

168
00:13:36,080 --> 00:13:37,640
Now, I want to create some data.

169
00:13:37,910 --> 00:13:40,040
I want to run this as a table driven test.

170
00:13:40,040 --> 00:13:47,390
I want to check for, say, three situations, one where everything is valid, one where the login credentials

171
00:13:47,390 --> 00:13:52,400
are invalid, and one where I don't actually enter correct information.

172
00:13:52,400 --> 00:13:57,830
Maybe I put a J or just one letter instead of a valid email address.

173
00:13:58,370 --> 00:14:00,710
So what I want to do is create some data for that.

174
00:14:00,710 --> 00:14:08,690
So I'll create a new variable, which I'll call login tests, and that will be a slice of struct.

175
00:14:10,880 --> 00:14:16,340
And let's define it, so I'm going to give my test a name, which will be a string, I'll give my test

176
00:14:16,340 --> 00:14:21,530
an email, which is the username that they're typing in, which is a string I'm not going to bother

177
00:14:21,530 --> 00:14:21,650
with.

178
00:14:21,650 --> 00:14:24,920
Password will say expected status code.

179
00:14:28,860 --> 00:14:32,880
Which will be rent and I'm going to do something we haven't done yet.

180
00:14:32,970 --> 00:14:39,150
I'm also going to say expected HTML, I'm actually going to pull the HTML out of the response and look

181
00:14:39,150 --> 00:14:42,670
for things that I know should be in there and that will be a string.

182
00:14:43,800 --> 00:14:46,290
And finally, I'll have expected location.

183
00:14:49,630 --> 00:14:57,250
What you, Earl, does the user have in his or her browser that will also be a string, OK, and now

184
00:14:57,250 --> 00:15:00,230
I need to populate that with some data, so we'll just do one to start with.

185
00:15:00,280 --> 00:15:04,840
So the first thing we'll put in here, our first test case and we'll just do one to start with will

186
00:15:04,870 --> 00:15:07,240
be called valid credentials.

187
00:15:10,990 --> 00:15:14,320
And for an email address, I'll use me at here, here.

188
00:15:18,090 --> 00:15:26,010
And the corrected the correct status code should be HTP, not status C other, because I'm going to

189
00:15:26,010 --> 00:15:31,040
do a redirect and when you do a redirect, that's the status where we're going to use.

190
00:15:31,830 --> 00:15:37,410
As for the next one, which is expected HTML, I'll leave that empty because I'm not going to examine

191
00:15:37,410 --> 00:15:37,560
that.

192
00:15:37,560 --> 00:15:42,320
In fact, you can't examine the HTML easily from a test when you're doing a redirect.

193
00:15:42,330 --> 00:15:45,600
If you're doing a direct render from the handler, then you get some HTML.

194
00:15:45,600 --> 00:15:50,160
If you're doing a redirect, it's actually sending a redirect to the browser and not HTML.

195
00:15:51,270 --> 00:15:54,900
And finally, what will we what are we going to be redirected to?

196
00:15:54,930 --> 00:16:00,120
Well, when we redirect after successfully logging in and our application, we take them to the homepage

197
00:16:00,120 --> 00:16:02,230
and that's the correct you URL for the homepage.

198
00:16:02,700 --> 00:16:05,400
So I have this set up now.

199
00:16:05,400 --> 00:16:10,020
I need to run the table tests and I'll add more situations in a bit.

200
00:16:10,770 --> 00:16:15,750
So I'll create a new function, which I'll call test log in.

201
00:16:16,890 --> 00:16:25,650
And it's a type or takes a parameter of a pointer to testing the T and we'll run our table tests so

202
00:16:25,650 --> 00:16:28,590
we'll range through all tests.

203
00:16:28,740 --> 00:16:31,210
Right now there's only one, but it'll be more before we're finished.

204
00:16:32,250 --> 00:16:34,200
So four don't care about the indexed.

205
00:16:34,200 --> 00:16:38,130
I'll call my individual test e range login tests.

206
00:16:40,410 --> 00:16:44,430
OK, so what are what's the very first thing we're going to do?

207
00:16:44,460 --> 00:16:48,660
Well, the same as we did in our other tests, we're going to create some posted data.

208
00:16:48,990 --> 00:16:57,780
So posted data is a sign the value of euro values, and I'll make it empty right now and then I'll add

209
00:16:57,780 --> 00:16:58,770
to it one at a time.

210
00:16:58,770 --> 00:17:01,300
So I need to add two things in our login form.

211
00:17:01,320 --> 00:17:03,900
We have our email address and we have our password.

212
00:17:04,470 --> 00:17:11,730
So posted data add and I'm going to add email, which is the key, the same thing we named the form

213
00:17:11,730 --> 00:17:15,810
on that form page and the value will be from our variable email

214
00:17:18,540 --> 00:17:21,780
and I need to have a password in their posted data.

215
00:17:22,710 --> 00:17:24,720
Add password.

216
00:17:24,960 --> 00:17:27,300
I'll just use password as a string.

217
00:17:30,640 --> 00:17:38,380
OK, now we need to create to create the request, so create the request and we'll do it the same way

218
00:17:38,380 --> 00:17:42,160
we did before request and nothing we're ignoring.

219
00:17:42,160 --> 00:17:45,340
The second parameter is assigned HTP the new request.

220
00:17:47,170 --> 00:17:49,960
The method will be post because this is a posted form.

221
00:17:50,380 --> 00:17:57,210
The euro will be user login, which is what the URL is in our form, and then we encode our data string's

222
00:17:57,460 --> 00:17:58,090
new reader.

223
00:18:00,220 --> 00:18:05,020
Posted data dot in code, so that creates a request.

224
00:18:06,430 --> 00:18:13,990
Now we need to get the context for a request and context is a sign the value of get context and we pass

225
00:18:13,990 --> 00:18:19,330
at our request and then we add the request to we add the context to the request.

226
00:18:19,330 --> 00:18:25,210
Request equals request with context and the context.

227
00:18:27,470 --> 00:18:28,490
Now we set the header.

228
00:18:32,250 --> 00:18:37,260
Which you probably don't have to do, but I always do it anyway, because it's good practice request

229
00:18:37,500 --> 00:18:50,880
header set and we're going to set the content type as application at Stasch w w w dash form dash Eurail

230
00:18:50,880 --> 00:18:51,510
encoded.

231
00:18:51,970 --> 00:18:54,550
And again, I don't think you have to do this, but I always do.

232
00:18:55,770 --> 00:18:57,900
So what do I have here to parentheses.

233
00:19:00,890 --> 00:19:08,690
There, so we sent the letter and we create a recorder, a response recorder is assigned the value of

234
00:19:08,690 --> 00:19:13,970
HTP test for HIV test, not new recorder.

235
00:19:17,210 --> 00:19:22,820
And now we call the handler, so call the handler.

236
00:19:24,690 --> 00:19:36,450
Handler is assigned the value of HTP, dog handler func and the handler I want to use is repo.

237
00:19:40,800 --> 00:19:42,120
Post show Longet.

238
00:19:43,900 --> 00:19:45,430
And I don't need parentheses there.

239
00:19:50,700 --> 00:20:00,840
That looks better and actually call the handler handler, not serve http and we want to pass in our

240
00:20:00,840 --> 00:20:04,650
response recorder for the first parameter and a request for the second parameter.

241
00:20:05,110 --> 00:20:05,390
All right.

242
00:20:06,150 --> 00:20:10,440
So this should actually work, but now we need to actually perform some tests.

243
00:20:10,770 --> 00:20:14,820
So that's the first thing we're going to check is our expected status code.

244
00:20:15,120 --> 00:20:26,820
If our code is not equal to IDOT expected status code, then throw an error teda error f.

245
00:20:30,060 --> 00:20:39,360
Failed and I'll put it in the name here, that placeholder expected code, what it is, but got what

246
00:20:39,360 --> 00:20:47,700
we got and that's idot name for the first place holder idot expected status code for the second one

247
00:20:47,850 --> 00:20:49,770
and our code for the third one.

248
00:20:50,240 --> 00:20:54,900
OK, so we should be able to we're only testing one thing right now, but let's just test this and run

249
00:20:54,900 --> 00:20:57,090
this test and see if it works though.

250
00:20:57,090 --> 00:20:58,770
Test should be everything.

251
00:21:01,820 --> 00:21:08,000
Everything passed good, so we've tested that first case in the first one, but what about other tests

252
00:21:08,000 --> 00:21:11,170
where we have HTML or we have an expected location?

253
00:21:11,180 --> 00:21:13,280
Well, for this form, we don't have expected e-mail.

254
00:21:13,290 --> 00:21:15,350
So we'll skip that for a moment and do that next.

255
00:21:16,010 --> 00:21:17,590
But let's try the expected location.

256
00:21:19,160 --> 00:21:24,590
So what we're checking here is when someone logs in successfully, they should be redirected to the

257
00:21:24,590 --> 00:21:25,250
home page.

258
00:21:25,430 --> 00:21:30,860
So we actually want to check to see what the location is, but we only want to do that for a test where

259
00:21:30,860 --> 00:21:32,660
the expected location is not empty.

260
00:21:32,990 --> 00:21:40,880
So we can say if IDOT expected location is not equal to nothing, if it's not an empty string, then

261
00:21:40,880 --> 00:21:42,280
we need to get the euro.

262
00:21:42,290 --> 00:21:46,790
So we need to get the euro from test.

263
00:21:47,480 --> 00:21:52,940
So we want the actual location and I'll ignore the error.

264
00:21:53,240 --> 00:21:55,540
We can get that from our response recorder.

265
00:21:57,300 --> 00:22:07,110
Result location so that stores the location that sent to the browser in this variable, then we just

266
00:22:07,110 --> 00:22:10,130
check to make sure that what we got is what we expected to get.

267
00:22:10,500 --> 00:22:16,980
So we can say if actual location, which is not a string but has a function on it that allows me to

268
00:22:16,980 --> 00:22:18,060
turn it into a string.

269
00:22:18,600 --> 00:22:31,740
If actual location string is not equal to idot expected location and throw an error teda error f.

270
00:22:34,960 --> 00:22:39,100
And we'll say failed and then the name of the test.

271
00:22:41,410 --> 00:22:43,270
Expected location.

272
00:22:46,800 --> 00:23:00,300
String, but got location string, so idot name idot expected location and then actual location and

273
00:23:00,300 --> 00:23:01,470
call the string method.

274
00:23:03,660 --> 00:23:08,100
So let's try that clear air test or clear a screen, run the tests.

275
00:23:10,780 --> 00:23:12,290
Everything passed good.

276
00:23:12,910 --> 00:23:23,740
All right, so the last situation we need to handle is if checking is checking for expected values in

277
00:23:23,740 --> 00:23:26,950
HTML, and again, we'll just use the same logic.

278
00:23:26,950 --> 00:23:32,410
If IDOT expected HTML is not empty, then run this test.

279
00:23:33,460 --> 00:23:37,180
And what we're going to do is to read the response body

280
00:23:40,750 --> 00:23:43,260
into a string and that's pretty easy.

281
00:23:44,020 --> 00:23:51,520
We can say HTML, which is what we're getting from the server, is equal to our response recorder body

282
00:23:52,600 --> 00:23:53,020
string.

283
00:23:56,120 --> 00:24:03,290
So now we have the e-mail that sent back by the browser and we just checked to see if the little fragment

284
00:24:03,290 --> 00:24:05,840
of you are out of e-mail, we expect to be in there.

285
00:24:05,840 --> 00:24:08,060
If it's in there, then we pass the test.

286
00:24:08,060 --> 00:24:09,710
If it's not that we failed the test.

287
00:24:10,010 --> 00:24:16,810
So we can just say, if not string's contains and the string we want to check is HTML.

288
00:24:16,820 --> 00:24:22,580
What we've got back from the browser and what we expect to find in there is in this variable idot expected

289
00:24:22,580 --> 00:24:23,210
HTML.

290
00:24:23,870 --> 00:24:34,310
So if that doesn't exist, throw an error t dot şeref failed percent s for the name and we'll say expected

291
00:24:34,880 --> 00:24:44,030
to find percent s which will be the e-mail we're searching for but did not and do our substitutions

292
00:24:44,030 --> 00:24:47,330
idot name idot expected html.

293
00:24:47,930 --> 00:24:53,600
OK, now this is never going to fire yet because we don't, we don't have a case where it's supposed

294
00:24:53,600 --> 00:24:57,470
to be there, but I'm going to run the tests anyway just to make sure that everything is correct.

295
00:24:59,420 --> 00:25:00,080
And it is.

296
00:25:00,300 --> 00:25:09,530
OK, so let's add another test case and the second test case I'm going to put in here will be one for

297
00:25:09,530 --> 00:25:11,410
invalid credentials.

298
00:25:13,280 --> 00:25:17,230
In other words, people logged in but didn't use the correct username and password.

299
00:25:17,660 --> 00:25:24,320
So we need to pass it a username and I'll pass it to a different email address this time, Jack, at

300
00:25:24,590 --> 00:25:26,150
nimble dot com.

301
00:25:27,110 --> 00:25:32,930
And we need a status which will again be HTP status C other because we're going to do a redirect.

302
00:25:32,930 --> 00:25:42,200
If they don't log in properly and we want to have no HTML, we're checking for what we want to make

303
00:25:42,200 --> 00:25:43,980
sure we're taken to user login.

304
00:25:45,920 --> 00:25:48,610
So what happens when someone logs in with the wrong information.

305
00:25:48,800 --> 00:25:55,400
We do it redirect, which gives the HTP status code of Status C other and we redirect them back to the

306
00:25:55,400 --> 00:25:56,420
user login page.

307
00:25:56,750 --> 00:26:02,060
Now, the only problem we have with this is if we go to our test repo and we look for authenticate,

308
00:26:02,060 --> 00:26:06,860
which is right here, we're always returning a valid login no matter what happens.

309
00:26:07,490 --> 00:26:13,890
But in my handler's test, when I want to check for valid credentials, I use the email address me out

310
00:26:13,890 --> 00:26:14,900
of here NCEA.

311
00:26:15,290 --> 00:26:21,350
When I'm using invalid correct credentials, I use something else so I can just modify my test repo

312
00:26:21,470 --> 00:26:22,400
as follows.

313
00:26:23,330 --> 00:26:27,650
If email is equal to me at here gutsier.

314
00:26:29,810 --> 00:26:37,160
Then say it's a valid slogan, otherwise, if that's not true, then I just need to return something

315
00:26:37,160 --> 00:26:37,520
else.

316
00:26:39,000 --> 00:26:46,680
I'll say return zero, nothing and then some error errors.

317
00:26:46,730 --> 00:26:49,070
Dot knew some error.

318
00:26:49,220 --> 00:26:50,660
And all I want to get there is an error.

319
00:26:50,810 --> 00:26:53,410
So this should actually handle that situation.

320
00:26:54,020 --> 00:27:01,160
So in our tests for the first one, I'm passing the email of me at here Dossie and my repo by test repo

321
00:27:01,170 --> 00:27:03,100
says, Oh that's me at here Dossie.

322
00:27:03,380 --> 00:27:04,640
So it's a valid login.

323
00:27:04,880 --> 00:27:10,750
In my second test I'm passing Jacquette nimble dot com, which is not me at here dossie.

324
00:27:10,760 --> 00:27:12,890
Therefore it will not allow the person to login.

325
00:27:12,890 --> 00:27:16,670
So I'm just faking or mocking what happens at the database level.

326
00:27:17,120 --> 00:27:19,310
So let's try that second test and see if we got that right.

327
00:27:23,630 --> 00:27:24,980
Everything passed good.

328
00:27:26,070 --> 00:27:28,820
Now, what's the third situation that we want to go for?

329
00:27:28,850 --> 00:27:30,800
The third situation is right here.

330
00:27:31,760 --> 00:27:33,620
I'll call it invalid.

331
00:27:35,860 --> 00:27:42,380
Data, in other words, they didn't enter all the information in the correct format in our situation.

332
00:27:42,400 --> 00:27:45,840
The only thing you can't enter in the correct format is an email address.

333
00:27:46,210 --> 00:27:49,830
So I'll just use the letter J for an email address, because that's not an email address.

334
00:27:50,410 --> 00:27:58,030
And in this situation, I want to get a status code of status, OK, because what's being rendered is

335
00:27:58,030 --> 00:28:00,040
the login form all over again.

336
00:28:00,070 --> 00:28:01,480
We're not doing a redirect.

337
00:28:02,140 --> 00:28:03,300
We're actually doing a render.

338
00:28:03,790 --> 00:28:08,730
And in this case, I want to find something that I know is going to be in the login screen.

339
00:28:10,030 --> 00:28:16,300
So what is going to be in the login screen in every situation?

340
00:28:16,330 --> 00:28:23,530
Well, if you think about it, what's always going to be available to us is this action equals user

341
00:28:23,800 --> 00:28:26,320
log in, because that's part of the form.

342
00:28:26,470 --> 00:28:32,200
And the last part, I'm going to ignore the location because I'm actually not getting a location in

343
00:28:32,200 --> 00:28:32,620
this case.

344
00:28:32,620 --> 00:28:34,210
I'm not being told to go somewhere else.

345
00:28:34,210 --> 00:28:35,900
I'm actually getting some HTML.

346
00:28:36,640 --> 00:28:38,980
So in this situation, I have invalid data.

347
00:28:39,490 --> 00:28:43,060
I'm passing in the invalid data of J4, an email address.

348
00:28:43,060 --> 00:28:47,410
I am going to get a status OK, back from the server because the page is rendered OK.

349
00:28:47,830 --> 00:28:49,990
It's just not going where the user wanted to go.

350
00:28:50,380 --> 00:28:56,800
And that HTML that sent back to the user will definitely have action equals user log in because if you

351
00:28:56,800 --> 00:28:59,050
look at your login page under templates.

352
00:29:00,740 --> 00:29:08,210
And find the login screen right here that has this text, and that's the only page in our site that

353
00:29:08,210 --> 00:29:11,960
has this text, therefore that is a valid thing to look for.

354
00:29:12,620 --> 00:29:14,810
So let's test this and see how it looks.

355
00:29:15,290 --> 00:29:16,160
Clear the screen.

356
00:29:19,320 --> 00:29:26,730
And it passes now, if I was to go back and to find that test log in case here, change this from user

357
00:29:26,730 --> 00:29:28,770
log in to user, put an extra R there.

358
00:29:28,950 --> 00:29:36,510
This test should fail now because there is not going to be user or login and it should fail.

359
00:29:37,780 --> 00:29:44,080
And it fails exactly, OK, so that seems to cover most of the cases, let's just check our coverage

360
00:29:44,080 --> 00:29:44,290
here.

361
00:29:48,980 --> 00:29:55,230
And our coverage is green at the top, as it should be all the way down to here.

362
00:29:55,250 --> 00:29:59,800
I'm looking for the login screen social repository.

363
00:29:59,810 --> 00:30:00,300
That's fine.

364
00:30:00,320 --> 00:30:03,230
OK, so this is where am I post login?

365
00:30:08,250 --> 00:30:14,880
So this post so long in here where so this first part is just logging in air and printing it, I don't

366
00:30:14,880 --> 00:30:16,410
care if that ever gets tested.

367
00:30:16,710 --> 00:30:21,540
And I mean, honestly, when I'm writing tests, if I have to jump through really strange hoops just

368
00:30:21,540 --> 00:30:26,670
to catch a situation like this, I'm making my code far more complex than it has to be.

369
00:30:26,670 --> 00:30:30,870
So I'm perfectly OK with that error not being tested.

370
00:30:32,040 --> 00:30:38,280
But everything else in here in the post log in, except for the errors like this, seems to get really

371
00:30:38,280 --> 00:30:38,850
good coverage.

372
00:30:38,850 --> 00:30:40,530
And that's exactly what I'm looking for.

373
00:30:40,530 --> 00:30:47,010
These things I don't worry about at all because I'm not going to make my code far more complex than

374
00:30:47,010 --> 00:30:50,970
it has to be just to get green text everywhere in my coverage report.

375
00:30:51,600 --> 00:30:56,760
So this seems to cover every situation I need to worry about or the majority of the situations I need

376
00:30:56,760 --> 00:31:00,020
to worry about for testing the post login handler.

377
00:31:01,230 --> 00:31:05,670
Now, the rest of these handlers, you should be able to write test for yourself using exactly the same

378
00:31:05,670 --> 00:31:07,950
kind of logic that I did just here.

379
00:31:08,400 --> 00:31:14,010
I am going to post to this lecture all of the completed tests, one that are done to my satisfaction

380
00:31:14,310 --> 00:31:15,080
to this lecture.

381
00:31:15,090 --> 00:31:18,120
So if you get stuck, you can use that code as a reference.

382
00:31:18,570 --> 00:31:23,400
But I think it's time to move on to the last few things we need to handle in order to get our application

383
00:31:23,400 --> 00:31:24,150
into production.
