Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix track tests #120

Merged
merged 19 commits into from
May 15, 2017
Merged

Fix track tests #120

merged 19 commits into from
May 15, 2017

Conversation

miporto
Copy link
Member

@miporto miporto commented May 12, 2017

@miporto miporto requested a review from aibarbetta May 12, 2017 15:55
@codecov
Copy link

codecov bot commented May 12, 2017

Codecov Report

Merging #120 into tracks will increase coverage by 1.63%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           tracks     #120      +/-   ##
==========================================
+ Coverage   91.16%   92.79%   +1.63%     
==========================================
  Files          21       21              
  Lines         645      722      +77     
  Branches       30       43      +13     
==========================================
+ Hits          588      670      +82     
+ Misses         57       52       -5
Impacted Files Coverage Δ
src/handlers/db/generalHandler.js 100% <100%> (+6.45%) ⬆️
src/routes/track.js 87.03% <100%> (+8.37%) ⬆️
src/handlers/response.js 93.49% <100%> (+1.49%) ⬆️
src/database/migrations/migrations.js 100% <100%> (ø) ⬆️
src/handlers/db/trackHandler.js 97.56% <86.66%> (-2.44%) ⬇️
src/handlers/db/artistHandler.js 85.71% <0%> (-14.29%) ⬇️
src/middlewares/login-router.js 94.59% <0%> (+1.73%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 231e873...16aeaac. Read the comment docs.

@miporto miporto mentioned this pull request May 12, 2017
@@ -1,12 +1,22 @@
{
"initialArtist": {
"id": 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Estos ids los tenemos en varios pero creo que no esta bueno. No estoy segura de si se insertan asi o si no y despues los usamos asumiendo que quedaron con ese id. Nos complica mucho si guardamos las entries que devuelve knex una ve que creó y usamos ese id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si le agregas el id y el mismo no esta repetido o es invalido la entry va a tener ese id seguro. Si queremos usar el id que devuelve knex independientemente de su valor habria que borrar esos campos de los json y no determinar un id valido de antemano en los json.

res.body.track.should.have.property('artists')
.eql([
artistsConstants.initialShortArtist,
artistsConstants.testShortArtist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aca! mejor comparar contra lo que devovio knex y no contra la constante que suponemos que va a devolver, no?

dbHandler.general.createNewEntry(tables.artists,
[
artistsConstants.initialArtist,
artistsConstants.testArtist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si va a ser un initial siempre metele initialArtist2

return artistTrackHandler.insertAssociations(insertedTrack[0].id, body.artists)
.then(() => insertedTrack);
});
return db(tables.artists).whereIn('id', body.artists).then((artists) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como hay que verificar tanto la existencia de los artistas como del album lo que hay que hacer es correr estos dos chequeos en paralelo y unificarlos en un Promise.all(promises)

});
return db(tables.artists).whereIn('id', body.artists).then((artists) => {
if (artists.length < body.artists.length) {
logger.warn(`Req artists: ${JSON.stringify(body.artists)} vs DB artists: ${JSON.stringify(artists)}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug o se vuela


const formatAlbumFromTrackJson = (album) => {
const formatAlbumShortJson = (album) => {
// TODO: catch null artist earlier
if (!album) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

album no deberia llegar nunca nulo

album: formatAlbumFromTrackJson(track.album),
artists: track.artists.map((artist) => formatArtistFromTrackJson(artist)),
album: formatAlbumShortJson(track.album),
artists: (track.hasOwnProperty('artists')) ? track.artists.map((artist) => formatArtistShortJson(artist)) : [],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El campo artists siempre deberia existir y tener al menos un artista

dbHandler.track.createNewTrackEntry(constants.initialTrack)
.then(() => done())
.catch(error => done(error));
db.migrate.rollback().then(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encapsular esta logica repetida (en este archivo y track.spec.js)

Note: album find function not yet implemented as the table it's not
defined
@aibarbetta aibarbetta merged commit 688548b into tracks May 15, 2017
@aibarbetta aibarbetta deleted the SS-113 branch May 15, 2017 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants