Message generator and tests
In this section you are going to break out some functionality currently in server.js
into a separate file, and we're also going to set up our test suite so that we can verify if those utility functions are working as expected.
For the moment, our goal is going to be to create a function that helps us generate the newMessage
object. Instead of having to define the object every single time, we'll simply pass in two arguments to a function, the name and the text, and it'll generate the object so we don't have to do that work.
Generating the newMessage object using the utility function
To generate newMessage
, we are going to make a separate file that we load into server.js
with a method we call instead of defining the object. Inside the server
folder, we'll make a new directory called utils
.
Inside utils
we'll make a file called message.js
. This will store our utility functions related to messaging, and in our case, we'll make a new one called generateMessage
. Let's make...