Skip to content

Backend - Shares#69

Open
FelipeMonobe wants to merge 38 commits intonodebr:backendfrom
FelipeMonobe:backend
Open

Backend - Shares#69
FelipeMonobe wants to merge 38 commits intonodebr:backendfrom
FelipeMonobe:backend

Conversation

@FelipeMonobe
Copy link

Shares

  • Handlers
  • Model
  • Routes
  • Schemas
  • Fixtures
  • Tests

package.json Outdated
"test": "standard && lab --verbose --colors --assert code --ignore __core-js_shared__",
"test-cov": "npm test -- -r console -o stdout -r html -o coverage/coverage.html -r lcov -o coverage/lcov.info",
"knex": "knex --knexfile ./lib/db/knexfile.js",
"fix": "standard --fix",
Copy link
Member

Choose a reason for hiding this comment

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

Não tenho um motivo muito forte para retirar este comando daqui, mas precisa ter cuidado com ele.

const db = require('../../lib/db')
const Share = db.model('Share')

exports.findLimitedByPage = (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

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

mudar o nome para findAll

const Share = db.model('Share')

exports.findLimitedByPage = (req, res) => {
const offset = req.query.page * req.query.limit
Copy link
Member

Choose a reason for hiding this comment

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

Achei que o offset e o limit estariam na query, está correto?

Copy link
Author

Choose a reason for hiding this comment

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

O que vem na query é o limit e a page.
Ai dessa forma o offset teria que ser calculado, vai trocar pra vir o offset direto do front?

Copy link
Member

Choose a reason for hiding this comment

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

Isso, vamos fazer com que o offset também venha, não faz muito sentido ter page e limit, mas offset e limit sim :-)

}

exports.findOne = (req, res) => {
return Share
Copy link
Member

Choose a reason for hiding this comment

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

Acho que vai dar problema se o share não existir

}

exports.remove = (req, res) => {
return Share
Copy link
Member

Choose a reason for hiding this comment

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

Quando implementar a sessão precisamos ter certeza que apenas o usuário que criou o share poderá excluir o mesmo

})

lab.describe(`GET ${ENDPOINT}/:id`, () => {
lab.test('deve retornar a linha selecionada', co.wrap(function * () {
Copy link
Member

Choose a reason for hiding this comment

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

Faltando um teste para quando não achar o share

})

lab.describe(`DELETE ${ENDPOINT}/:id`, () => {
lab.test('deve remover do banco de dados a linha selecionada', co.wrap(function * () {
Copy link
Member

Choose a reason for hiding this comment

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

Faltando o teste para remover apenas os shares que pertencem ao usuário

* @param {Function} bookshelf Uma instância do Bookshelf
*/
module.exports = bookshelf => bookshelf.model('Share', {
tableName: 'shares'
Copy link
Member

Choose a reason for hiding this comment

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

Faltando o relacionamento para a table users.

exports.findLimitedByPage = (req, res) => {
const offset = req.query.page * req.query.limit

return Share
Copy link
Member

Choose a reason for hiding this comment

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

Deve também retornar o usuário:

{
  title: ..,
  link: ..,
  user: {
    id: ...,
    username: ...
  }
}


exports.findOne = (req, res) => {
return Share
.findById(req.params.id)
Copy link
Member

Choose a reason for hiding this comment

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

Deve retornar o usuário também

@thebergamo
Copy link
Member

@alanhoff @FelipeMonobe como está esse cara?

yield fixtures.users.insertMultiple()
yield fixtures.shares.insertMultipleWithId([id])

const req = yield request(server)
Copy link

@arku arku Dec 17, 2016

Choose a reason for hiding this comment

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

@FelipeMonobe

From MDN docs,

A constant cannot share its name with a function or a variable in the same scope.

The constant variable req is used in the same scope, again in line 174. And that is why, CI build fails. Can you rename the variable to something else?

Copy link
Author

Choose a reason for hiding this comment

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

@arun1595 well spotted man. I'm switching the first req to a simple yield, it should fix this issue

Copy link

Choose a reason for hiding this comment

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

👍

@FelipeMonobe
Copy link
Author

#69

The last three tests are still failing. I couldn't find out where's the issue in my code.

  • GET /compartilhamentos/:id with a different id should expect status code 404 but the request is timing out with Unhandled rejection CustomError: EmptyResponse, maybe it has something to do with error handling;

  • DELETE /compartilhamentos/:id both tests there's something wrong going on with sessions resource, it fails with Cannot read property 'map' of undefined at /test/fixtures/sessions.js:14:3

return Shares
.forge({ id: req.params.id })
.destroy()
.then(() => res.send({ success: true }))
Copy link
Member

Choose a reason for hiding this comment

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

Check this, you must implement an catch for this and other promises. Probably the error is generated for an error in constraint.

Copy link
Author

@FelipeMonobe FelipeMonobe Dec 30, 2016

Choose a reason for hiding this comment

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

Dude, I'm not sure that's the problem, since the sessions handler also has an uncaught function:

exports.findOne = (req, res) => {
  User.findById(req.session.user_id)
  .then((user) => res.send(user))
}

I've put catches to all my functions and they didn't work

Copy link
Member

Choose a reason for hiding this comment

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

I need to look more closely. Will do some tests in the week

@codecov-io
Copy link

Current coverage is 96.60% (diff: 95.85%)

Merging #69 into backend will increase coverage by 0.46%

@@            backend        #69   diff @@
==========================================
  Files            15         25    +10   
  Lines           311        560   +249   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            299        541   +242   
- Misses           12         19     +7   
  Partials          0          0          

Powered by Codecov. Last update aabd929...ded0f5c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants