This week we are going to build part of a Restaurants app, like Deliveroo or Uber Eats. On this first day we are going to start by designing our data model. An app's data model is like the foundations of a building. Everything is build on top of this foundation.
In a restaurant ordering system what are some of the objects you would expect to find?
What are the relationships between these? A Restaurant can have many menus, for example:
A Restaurant can have 1 or more menus. A Menu belongs to a Restaurant. A Menu has many Items. An Item belongs to a Menu. Can you figure out all of that? It confusing and quite complicated to imaging if some one is just verbally explaining it to us. We need a way to draw this out or represent it.
Unified Modeling Language is a standardized way to represent abstract structures in programming, like a data model.
Example of Airports in UML
Can you design a data model for the following classes:
A Menu belongs to a Restaurant. A Menu has many Items. An Item belongs to a Menu. Can you figure out all of that? It confusing and quite complicated to imaging if some one is just verbally explaining it to us. We need a way to draw this out so we can clearly communicate our design.
When you think you have something save your model and share the diagram with your coach.
From the design you can begin to write a set of tests that will prove your model is sound. Use the examples from the Airport exercise to implement your data model for your restaurant ordering app.
When you have completed these tasks, can you create a coverage report using Jest? A coverage report is going to run your tests and analysis the code that your tests hit or execute. This data can be compiled into a coverage report. The "coverage" metric is how much of your code is executed during your tests. Add the following line to your package.json
{
"scripts": {
"test": "jest",
"test:report": "jest --coverage=true"
},
"dependencies": {
"jest": "^26.4.2"
}
}
Then run npm run test:report
you are aiming for 100% test coverage. When you run this you should see that Jest generated a 'coverage' report in your project folder. If you navigate to /coverage/Icov-report/index.html
and open it in your browser you'll see a helpful report of your test coverage.
This is interactive try clicking on one of the class definitions.
Create a new project folder and use npm init
to start a new Node.js app. Create 3 class definitions with tests. You should be able to: