Rock on, dude! We're going to build Band/Musician organizer.
GOAL: We’ll be creating a database that contains 3 models:
MusicianBandSong
We will be working on this across multiple days. The work on this repository will be split across two days
- Once the forked repository has been cloned, make sure to run:
npm install- Additionally, you’ll need to create the following file in the root of the project:
db.sqlite. This database file is considered sensitive in nature, so it will not be pushed up to a repository when the project is pushed. - To run the tests, run
npm test. The test file is created, but each test is currently empty. Initially, you’ll get many errors and messages likeTest suite failed to run since there are missing parts.
Code in all the spots where it says TODO in the project (you can search across files to find the spots to edit!). Below are the instructions:
- In
db.js, create a new sequelize connection. - In
/models/Band.js, define aBandmodel. TheBandmodel should have the following properties:name: a stringgenre: a string
- In
/models/Musician.js, define aMusicianmodel. TheMusicianmodel should have the following properties:name: a stringinstrument: a string
- In
/models/Song.js, define aSongmodel. TheSongmodel should have the following properties:title: a stringyear: a numberlength: a number
- Now that we have our models defined, it is time to create some tests in
index.test.jsto verify that our models function as intended. Create tests that do the following:- Can create a new
Band - Can create a new
Musician - Can create a new
Song - Can update a
Bandinstance - Can update a
Musicianinstance - Can update a
Songinstance - Can delete a
Bandinstance - Can delete a
Musicianinstance - Can delete a
Songinstance
- Can create a new
When testing your code you will need to first create and band, musician, or song and then verify that it has been added. For example, a test with a User database, may look something like:
test('can create a Band', async () => { const testUser = await User.create({ name: 'George', password: '123' }); expect(testUser.name).toBe('George'); }
- Add a
showCountproperty to theBandmodel (number) and account for the new column in the tests. - Implement data seeding to populate the
Band,Musician, andSongmodels with initial data usingbulkCreate(). - Research the provided increment and decrement methods. Create tests to verify that you can increment and decrement
- Research how to create instance methods with Sequelize. Create some instance methods and tests to verify that they work as intended. A few instance methods to consider:
- A
toString()method that converts the data stored into a simple string like Band: Queen Genre: Rock. - A
toMinutes()method for the Song model that takes the duration in seconds and returns the number of minutes. - A
getLongestSong()model for the Song model that returns the song with the longest duration.
- A
- In the
index.jsfile, before themodule.exports, associate theBandandMusicianmodels.- Multiple musicians can be added to a band.
- Every musician has only one band.
- In
index.test.js, create a test to account for this association. In the test:- Use
Band.findAll()to get the bands (if there aren’t any from the previous tests, you’ll have toBand.create()some!) - For each of the bands, use something like
foundBand.getMusicians()to check that they have been added correctly!
- Use
- Run
npm testto verify the test runs properly.
- In the
./index.jsfile, before themodule.exports, associate theSongandBandmodels.- Multiple songs can be added to a Band.
- Multiple bands can have the same Song.
- In
index.test.js, add another test to account for theSongandMusicianassociation. - Run
npm test - Write a test to add multiple musicians to a band. In the test:
Band.create()to make some bands. Use the data you’ve added in previous tests you’ve created!- Create at least 2 songs
- For one band, add both songs
- For each of the songs, use something like
foundBand.getSongs()to check that they have been added correctly! - Do the same with the bands.
- Create a new model called
Managerthat will represent the person managing aBandhas made.Managercan have properties of your choice, but a few you may want to add:name: a stringemail: a stringsalary: a numberdateHired: a date
- In the
./index.jsfile, before themodule.exports, associate the two models.- A single
Bandcan be added to aManager - A single
Managercan be added to aBand.
- A single
- Write a test to add a manager to a band and test the association.
- Run
npm test - Create test data and associate the models as in previous tests.
- Find all the Bands
- In the
Band.findAll()call, include theMusicianmodel. - Do the same again, but this time include the
Songmodel. - Test the output
