Rock on, dude! We're going to build Band/Musician organizer.
GOAL: We’ll be creating a database that contains 3 models:
Musician
Band
Song
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 aBand
model. TheBand
model should have the following properties:name
: a stringgenre
: a string
- In
/models/Musician.js
, define aMusician
model. TheMusician
model should have the following properties:name
: a stringinstrument
: a string
- In
/models/Song.j
s, define aSong
model. TheSong
model 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.js
to 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
Band
instance - Can update a
Musician
instance - Can update a
Song
instance - Can delete a
Band
instance - Can delete a
Musician
instance - Can delete a
Song
instance
- 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
showCount
property to theBand
model (number) and account for the new column in the tests. - Implement data seeding to populate the
Band
,Musician
, andSong
models 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.js
file, before themodule.exports
, associate theBand
andMusician
models.- 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 test
to verify the test runs properly.
- In the
./index.js
file, before themodule.exports
, associate theSong
andBand
models.- 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 theSong
andMusician
association. - 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
Manager
that will represent the person managing aBand
has made.Manager
can 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.js
file, before themodule.exports
, associate the two models.- A single
Band
can be added to aManager
- A single
Manager
can 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 theMusician
model. - Do the same again, but this time include the
Song
model. - Test the output