The following course addresses a few pain points that a lot of teams had in our experience when they are migrating to Node.js Micro-Services from technologies such as PHP (Laravel, Wordpress), Ruby on Rails, and Java.
- A lot of courses omit testing, which arguably is one of the highest priority requirements for teams who migrate to new technology.
Part I - Chapter 1 - Ice Cream
Create New Project and Install Cucumber
Length: <10 minutes.
We will create a new project and install the most important dependencies -
chai. We will go through the basics of due-diligence on how to make sure which version of dependency to install, by checking npmjs.org website, and corresponding repository, page, and continuous integration environments. Finally, we will write the first sanity test, to make sure that the installation is working.
Goal: Make sure that team understands how to create a new Node project if one is not available in the repo, and minimal actions when it comes to installing dependencies.
Dissect Ice Cream
Once it’s done we can start writing our high-level test, on how to test if something has sufficient information to be ice cream.
Goal: Get the team to discuss the basic requirement, and jump into the code by writing first Feature file, and Step Definition, and obviously validating that test framework is running by failing the first test.
Length: <20 minutes. Now that we have a high-level user story, we will implement a subtask, and write a test to make sure that we understand what is Scoop of Ice Cream, and what properties do we want it to have.
Implement Ice Cream Cone with Scoops
Lengths: <20 minutes. Create an Ice Cream cone that can contain multiple scoops, we will update our test, and see how to write tests around edge cases, what if there are too many scoops?
Goal: Build on the previous lesson, we will work with complex objects, and see how to test trees of data.
Length: <20 minutes.
We have change request from a business, we have to stay competitive, and we need to add diversity to our Ice Creams to become a Starbucks of Ice Cream! We will add toppings to the cones, and let people chose different kinds of cones.
Goal: Get developers to think on how to update existing tests with a change request, and build on the complexity of the objects.
Length: <20 minutes.
Build a new process, - Calculate the price of the Ice Cream depending on the number of features, and put the ice-cream in the right pricing tier.
Part I - Chapter 2 - Ice Cream Trucks
Length: <20 minutes. Before we start with the trucks, we will quickly revisit what we did last time, and add new functionality, and refresh the memory. We will add new functionality, and a new step to the data processing pipeline - to apply a random discount.
Evaluate Trucks - What is a Truck?
Lenth: <20 minutes. Our glorious leaders decided to reach full vertical integration in Ice Cream business, just like Amazon we don’t want to be simply providers of commodity, but also provide fulfilment, and as a first step, we shall acquire trucks that will serve as Ice cream Trucks.
Let’s define how a Truck will look in our data model, and start creating mocks for our tests.
Lengths: <30 minutes. Let’s create a simple Truck Evaluation algorithm, that will create a new evaluation for a given truck. Let’s expand our tests to understand different cases.
Goal: Give developers some practice time, to write tests and logic without interrupting them for too long, to solidify what they’ve learned so far.
Evaluate Trucks - What’s not a Truck?
Length: <30 minutes. Now that we know what is a truck, let’s write tests that will screw with our evaluation by providing them with something that’s not a truck. We will then add constraints to our Truck model, to make sure it can validate incoming data, and throw appropriate errors.
Goals: Expand on tests by adding edge cases, and teach the team on how to work with tests that could throw errors.
Part II - Chapter 1 - RESTful Service
Set-Up RESTful Service with Express
Length: <10 minutes
We will install RESTful framework
express and will remind developers on how to make basic checks to make sure we are installing safe modules, and try to document the process in a short checklist that will go into
Goal: Start with something we already did in the last course, to remind people of our progress, and start engraining good practices.
Length: <10 minutes
Before we start working on the business functionality, we need to make sure that our services comply with Availability and Testability requirements, by exposing a
GET /health endpoint.
Goal:Continue with best-practices, and make sure that our installation of the
express works, and functioning as expected in basic examples.
Primer on RESTful APIs
Length: <15 minutes We are going to follow a RESTful approach to the APIs, which will ensure that in future we can convert our shop into microservices. We will start with explaining how RESTful works, and basic concepts of what is Resource, Noun and a Verb, and how RESTful APIs map to the database design.
Goal: Get team some theory on how to write RESTful APIs. We will not explore all the bonuses, namely automatic documentation tools, and test tools, but will instead show it in later stages.
Create Ice Cream
Length: <10 minutes Let team design first end-point, and make decisions on how to name, and which HTTP methods to use to create ice cream. Later on, we will review and ask questions, to guide the team towards the right decision.
Goal: Let team code, and make mistakes! And obviously, implement first Ice Cream.
Get List of Ordered Ice-Creams
- Length: <20 minutes.* Similar to the previous step, now that we’ve created an Ice-Cream let’s return a list of previously created Ice-Creams, and create a database mock.
Goal: Empower the team to create an endpoint on their own, and learn from mistakes.
- Length: <30 minutes.* Let’s add Swagger if something is not documented - it doesn’t exist and Swagger is an easier way to create interactive documentation and playground for APIs. We will finish off by documenting our Ice Cream Resource.
Goal: If it’s not documented it doesn’t exist. Show the team power of RESTful APIs, and how easy it is to create documentation with a tool like Swagger.
Part II - Chapter 2 - Event Loop
Working with File System
Length: < 10 minutes Let’s remind ourselves how do Trucks look like, by generating a few good and bad trucks, and then serializing them into JSON, and finally saving files of good and bad trucks and saving them as assets to our project.
Goal: Let team shuffle in, and refresh their memory on how do trucks look like.
Length: <10 minutes. Let’s use async/await, and Promise APIs to save files on the system.
Goal: Promises and Async/Await are two different interfaces to the same underlying way of working with async data. We will introduce the team by showing a simple example of how to work with both of them.
Saving and Verifying Truck JSON
Length: <35 minutes Saving files automatically is not safe, let’s automate this process, by using Node.js filesystem to create a file, writing to file, and checking the integrity of the file.
Goal: We will add complexity, in real life examples async operations rarely come alone, and instead we need to make them work together. We will explore ways to test async operations, and stub them.
Length: <15 minutes. Let’s make sure we didn’t forget how to create RESTful endpoints, by creating a new one for the truck, and going through the motions of creating interactive documentation with Swagger.