A developer writes end-to-end test suites for reservation functionality. The process includes refactoring authentication to handle JWT headers, updating guard logic, and executing tests via Docker Compose to verify successful reservation creation and retrieval.
Length 10:52
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #typescript #end-to-end testing #docker #authentication #jwt #api #coding #software development #microservices #jest
0:00 Around creating a reservation. I'll create a new spec 0:04 called 0:04 reservations.endtoend.spec.ts. 0:09 And let's go ahead and actually rename our health check file. 0:14 We can remove the .app here. So 0:18 we'll open up a new describe block and describe the reservations, 0:22 and then open up a function where we will test reservations. 0:25 Our first test will be to create. 0:29 So we'll call this create and open up a function where we'll now 0:33 we'll 0:33 create a new reservation. So of course, before we actually create the 0:37 reservation, we will need to authenticate with our 0:39 authentication service. 0:41 So let's set up a new before all block, 0:45 which will contain an async function. 0:48 And inside of here, we're going to do the setup work for our 0:51 test, where we'll 0:52 create a new user and get an authorization header 0:55 for that user after some refactoring to our auth service. 0:59 First, we will call await fetch and reach out 1:02 to our 1:04 auth service listening on port three thousand and one. 1:08 We will provide an options object to fetch. 1:10 We'll specify the method and make sure this is a POST request, 1:14 and we'll specify a body where we'll call JSON.stringify, 1:18 provide a new object, and here we can provide our email, call it 1:22 sleepernestapp@gmail.com, and the 1:26 password. I will give it a strong password as 1:30 usual. Let's go ahead and actually take this object out 1:33 and declare 1:34 it a new variable that we'll call user 1:38 and paste it here. 1:40 Now we'll JSON.stringify the user. 1:42 And now I wanna call our auth service with our credentials to log in. 1:46 And instead of using a set cookie to set a JWT 1:50 cookie, I wanna get the JWT sent back directly 1:53 from the login 1:54 call, and then we can provide it as a header to 1:57 our authentication 1:58 service. So to accomplish this, let's firstly go to our auth
The rest of the transcript is for members.
Sign in