Current section: Authenticated Integration 5 exercises

Intro to Auth Integration

Loading lesson


00:00 Okay, we're at the integration level and we want to do authenticated requests. And so there are a couple of things you have to do to make this work. All of our loaders and actions are talking directly to a database, and you could mock out that database if you want to. There's definitely some situations where that makes sense, but not very many.

00:17 It's awful, awful, awful to mock out a database. And so what you can do instead is just set up the database and use the actual database and just make sure you're cleaning up after yourself. Now, at this level of tests where you're running a bunch of tests, I really actually like to have a separate database, and we'll talk about that in a future exercise. But for this one, we're going to be using our development database,

00:38 just like we do with our end-to-end tests. Now, I talked about earlier why we use the regular database for end-to-end tests, and I still stand by that. But for this level of testing, I think it makes sense for them to have an individual database. But again, that's for another exercise. So for this one, we're going to be working with the development database

00:57 and you're going to have to insert a test user into the database, create a session for that user, set the session ID in a cookie header for those requests because that's where we get the session IDs from that cookie header, handle verification like two-factor auth potentially, and then assert the auth state is updated properly in the responses.

01:17 So here's how you can do some of that. We can make a request and then set the headers to this cookie value. The challenge is that we have utilities for creating a cookie that is a set cookie header, and we're going to use those utilities. That'll be great.

01:35 But those are for the response, not for the request. And so we're going to use a module that allows us to parse a set cookie header and get the cookie value so that we can stick it in here. And in fact, we've got a couple of cookies we've got to combine, which will be kind of interesting. And then in our integration test,

01:54 that's integration test for like just hitting the loader directly, and we're going to have some steps or exercise steps for that. And then for the entire route, we want to be able to cover not only the UI of the route, but also the loader and the action of the route. And so we've got, you know,

02:11 there's a fair bit of code going on in here that would be cool to cover. So we're going to grab the RemixDub, and then we can grab the actual loader, not just the type of the loader, but the actual loader itself, and then use that as is so that we can get coverage on the loader. And because we're able to talk to our actual database during tests,

02:29 then that is not a problem for us. And then if we need to authenticate that, then that's a little bit of a challenge. But what we can do is take the arguments that are given to the loader, take the request that is given to us, and then just set the cookie header that way. And that works out really well. So we got a couple of steps for this exercise.

02:50 I think you're going to have a good time. There's actually plenty of stuff that you could do on your own that Kelly kind of does for you. But if you want to really get some practice, then I suggest that you do some of those things on your own yourself. And yeah, plenty of work to do in this one. So have a good time.