1 00:00:01,300 --> 00:00:04,690 In this video we're going to take a look at the different kinds of tests we're going to try to write 2 00:00:04,690 --> 00:00:08,230 out for the different services inside of our ticketing project. 3 00:00:08,230 --> 00:00:13,030 So again we're not going to focus too much on testing or trying to launch multiple services together 4 00:00:13,300 --> 00:00:14,770 and try to test how they interact. 5 00:00:14,800 --> 00:00:19,640 Instead we're going to try to look at each service individually and test them one at a time. 6 00:00:19,660 --> 00:00:23,860 So I want to show you the different kinds of tests we're going to write as we're looking at say just 7 00:00:23,860 --> 00:00:26,230 the auto service by itself. 8 00:00:26,280 --> 00:00:30,720 The first kind of tests are we're going to write out is going to try to test basic request handling. 9 00:00:30,720 --> 00:00:35,430 So for example we might want to try to make sure that if we make a request to our service to sign up 10 00:00:35,430 --> 00:00:40,950 for something then perhaps we should get back a response with a cookie that has a just on web token 11 00:00:40,950 --> 00:00:46,380 inside of it or we might want to try to assert that we write some data into our Mongo DB database. 12 00:00:46,380 --> 00:00:49,530 So this is the first kind of test we're going to write we're going to make sure that we can issue a 13 00:00:49,530 --> 00:00:55,940 request to the service and then make sure that it gets handled some in some very particular fashion. 14 00:00:55,960 --> 00:01:00,130 The second test we're going to write is going to be more of a unit test style approach. 15 00:01:00,280 --> 00:01:04,300 So the second test we're gonna write might take a look at a very particular model inside of our app 16 00:01:04,600 --> 00:01:07,080 and try to test some functionality around it. 17 00:01:07,090 --> 00:01:11,920 This is not very relevant for the auto service because our user model right now is very simple in nature 18 00:01:12,300 --> 00:01:17,010 but some of these services that we work on later will have models that are a little bit more complicated. 19 00:01:17,320 --> 00:01:21,130 And so we are going to wants to write some tests around them and make sure that they function in a very 20 00:01:21,130 --> 00:01:22,670 particular way. 21 00:01:22,690 --> 00:01:26,590 So again the second kind of test we're gonna write is going to take a look at individual models and 22 00:01:26,590 --> 00:01:32,290 just try to make sure that they have some particular piece of functionality the final kind of test that 23 00:01:32,290 --> 00:01:38,050 we're going to write is going to handle the receiving and emitting of events inside of our service at 24 00:01:38,050 --> 00:01:42,790 present are off service is not sending out or receiving any events and we haven't even discussed event 25 00:01:42,790 --> 00:01:45,460 handling inside this community's environment yet. 26 00:01:45,460 --> 00:01:50,020 So we're not going to really worry about testicle number three either for the auto service but for our 27 00:01:50,020 --> 00:01:54,480 later services we put together we will be writing out some code to make sure that we can receive incoming 28 00:01:54,490 --> 00:01:59,560 events to make sure that they get processed in some particular way and to make sure that we can issue 29 00:01:59,560 --> 00:02:02,920 events or send events to the outside world as well. 30 00:02:02,920 --> 00:02:07,800 So again those are the three kinds of tests that we're going to be focusing on test gold number three 31 00:02:07,800 --> 00:02:13,770 right here emitting and receiving events is how we are really going to accomplish simulating different 32 00:02:13,770 --> 00:02:15,270 services working together. 33 00:02:15,270 --> 00:02:19,560 So even though we are not going to directly at launch say in orders and ticketing service at the same 34 00:02:19,560 --> 00:02:26,190 time and try to test them together this idea of testing events or receiving them any minimum is very 35 00:02:26,190 --> 00:02:30,070 similar in nature and it will achieve a very similar goal. 36 00:02:30,070 --> 00:02:30,430 All right. 37 00:02:30,430 --> 00:02:31,630 One last thing. 38 00:02:31,630 --> 00:02:34,120 How are we going to actually execute these tests. 39 00:02:34,120 --> 00:02:37,290 In other words at a very practical level when I say to you. 40 00:02:37,320 --> 00:02:39,370 Okay let's go and run our tests. 41 00:02:39,370 --> 00:02:40,060 How do we do that. 42 00:02:40,060 --> 00:02:42,820 How do we actually execute our tests at all. 43 00:02:42,820 --> 00:02:46,150 Well we're going to take a very simple indirect approach. 44 00:02:46,150 --> 00:02:48,720 We're going to run all of our tests directly at our terminal. 45 00:02:48,730 --> 00:02:49,700 We're not going to Docker. 46 00:02:49,750 --> 00:02:52,440 We're not going use coordinators or anything like that. 47 00:02:52,450 --> 00:02:56,800 So when I say let's go run our tests we're going to pretty much go over to our terminal and run a command 48 00:02:56,830 --> 00:03:02,920 like NPM run test that's going to start up our server on our local machine or individual service and 49 00:03:02,920 --> 00:03:05,980 then tried to run some number of tests against it. 50 00:03:06,010 --> 00:03:08,230 Now this has a very strong implication. 51 00:03:08,230 --> 00:03:14,470 This is really implying that our local environment is capable 100 percent of running each of these services 52 00:03:15,040 --> 00:03:17,060 and that probably makes a lot of sense right now. 53 00:03:17,260 --> 00:03:22,300 Think about our auth service what dependencies or what software do we need to have installed on our 54 00:03:22,300 --> 00:03:24,460 local system to run the service. 55 00:03:24,460 --> 00:03:28,400 Well we pretty much just need no J.S. and a copy of Mongo DB. 56 00:03:28,420 --> 00:03:32,990 That's all we really have to have installed on our local system to run the service. 57 00:03:33,310 --> 00:03:39,340 But in the future you might be working on way more complex projects projects where your services have 58 00:03:39,340 --> 00:03:41,570 way more dependencies. 59 00:03:41,680 --> 00:03:46,480 In other words at some point in time the future you might be trying to test a service that requires 60 00:03:46,480 --> 00:03:52,300 you to have a very particular operating system or a very particular and very complex and hard to run 61 00:03:52,300 --> 00:03:54,460 hard to set up database. 62 00:03:54,460 --> 00:03:59,080 So even though this approach is going to be just fine for this current application in the future it 63 00:03:59,080 --> 00:04:01,250 might not work out so well. 64 00:04:01,300 --> 00:04:05,410 So I am going to show you some way that we can still run tests very easily. 65 00:04:05,410 --> 00:04:10,930 Let's a little bit more complex in nature but it can also handle way more complex setup requirements 66 00:04:11,620 --> 00:04:13,120 if not that makes sense right now. 67 00:04:13,120 --> 00:04:14,100 Don't sweat it. 68 00:04:14,170 --> 00:04:19,760 Keep in mind I'm going to give you a quick guide on how to handle more complex testing in the future. 69 00:04:19,780 --> 00:04:20,050 OK. 70 00:04:20,080 --> 00:04:24,340 So if all this in mind I think we've got a good overview on what we're doing so we can take a quick 71 00:04:24,340 --> 00:04:27,430 pause right now and then actually get down to the nitty gritty. 72 00:04:27,490 --> 00:04:29,110 What are we really doing here. 73 00:04:29,110 --> 00:04:31,900 What code are we really writing to test out our all service.