Backend - Shares#69
Backend - Shares#69FelipeMonobe wants to merge 38 commits intonodebr:backendfrom FelipeMonobe:backend
Conversation
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", |
There was a problem hiding this comment.
Não tenho um motivo muito forte para retirar este comando daqui, mas precisa ter cuidado com ele.
resources/shares/handlers.js
Outdated
| const db = require('../../lib/db') | ||
| const Share = db.model('Share') | ||
|
|
||
| exports.findLimitedByPage = (req, res) => { |
resources/shares/handlers.js
Outdated
| const Share = db.model('Share') | ||
|
|
||
| exports.findLimitedByPage = (req, res) => { | ||
| const offset = req.query.page * req.query.limit |
There was a problem hiding this comment.
Achei que o offset e o limit estariam na query, está correto?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Isso, vamos fazer com que o offset também venha, não faz muito sentido ter page e limit, mas offset e limit sim :-)
resources/shares/handlers.js
Outdated
| } | ||
|
|
||
| exports.findOne = (req, res) => { | ||
| return Share |
There was a problem hiding this comment.
Acho que vai dar problema se o share não existir
resources/shares/handlers.js
Outdated
| } | ||
|
|
||
| exports.remove = (req, res) => { | ||
| return Share |
There was a problem hiding this comment.
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 * () { |
There was a problem hiding this comment.
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 * () { |
There was a problem hiding this comment.
Faltando o teste para remover apenas os shares que pertencem ao usuário
resources/shares/model.js
Outdated
| * @param {Function} bookshelf Uma instância do Bookshelf | ||
| */ | ||
| module.exports = bookshelf => bookshelf.model('Share', { | ||
| tableName: 'shares' |
There was a problem hiding this comment.
Faltando o relacionamento para a table users.
resources/shares/handlers.js
Outdated
| exports.findLimitedByPage = (req, res) => { | ||
| const offset = req.query.page * req.query.limit | ||
|
|
||
| return Share |
There was a problem hiding this comment.
Deve também retornar o usuário:
{
title: ..,
link: ..,
user: {
id: ...,
username: ...
}
}
resources/shares/handlers.js
Outdated
|
|
||
| exports.findOne = (req, res) => { | ||
| return Share | ||
| .findById(req.params.id) |
There was a problem hiding this comment.
Deve retornar o usuário também
- This follows `hello-world` structure - there are no `'use strict'` thingies because commonjs is strict by default :P - `email` is not in the specification but probably very important (?) - `password` is currently saved raw, missing bcrypt stuff
Implementa a sessão
|
@alanhoff @FelipeMonobe como está esse cara? |
test/resources/shares.js
Outdated
| yield fixtures.users.insertMultiple() | ||
| yield fixtures.shares.insertMultipleWithId([id]) | ||
|
|
||
| const req = yield request(server) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@arun1595 well spotted man. I'm switching the first req to a simple yield, it should fix this issue
|
The last three tests are still failing. I couldn't find out where's the issue in my code.
|
| return Shares | ||
| .forge({ id: req.params.id }) | ||
| .destroy() | ||
| .then(() => res.send({ success: true })) |
There was a problem hiding this comment.
Check this, you must implement an catch for this and other promises. Probably the error is generated for an error in constraint.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I need to look more closely. Will do some tests in the week
Current coverage is 96.60% (diff: 95.85%)@@ 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
|
Shares