Current section: End-to-End 6 exercises

Creating and Interacting with User Data

Loading solution


00:00 Let's go to our search right here, and we're going to create a new user. So let's get that new user from await prisma.user.create. And our data, we have a utility for this. This is create user from our dbutils. And I want to add a select. All that we're going to need here is,

00:22 let's see, the name, true, and the username, true. And that should be enough, actually. Okay, great. Now, let's look for the user's username instead of Cody. So new user.username. And then we'll have this as Cody, or Cody's no longer going to appear in the URL like he was before.

00:42 Now it's going to be new user.username will appear in the URL. But I don't really like doing this because it needs to be encoded properly. And you can use encode URI component, and that would work just fine. But I really like using URL search params for this. So let's add that. The search will be the user's username.

01:02 Okay, great. And then finally, instead of Cody showing up as the alt text, we're actually going to be finding that it's the user's name. So the new user.name falling back to the new user.username. And that should rerun our tests and everything's passing.

01:23 We're in a good spot. So if we watch this, it typed in that random username that was created, and then also found the page, and there's Marley Parker. And then we go non-existent, and that shows no users found.

01:41 So now we have the benefit of having a test that does its own setup by just using the utilities from our application that we have already. And that is the first part of this. But there's actually a little problem that we're going to deal with next.

01:59 But so far, so good.