caio-ribeiro-pereira / ntask-api Goto Github PK
View Code? Open in Web Editor NEWNTask - API de gestão de tarefas
NTask - API de gestão de tarefas
Caio,
na linha 13 meu código não estava conseguindo realizar post. Após ver um repositório teu building-apis-with-nodejs , tu colocou .then(() => done());
e fiz isto no meu e funcionou.
É necessário criar desta forma ou é alguma versão que existe essa diferença na promise .then(done());
?
Olá @caio-ribeiro-pereira, sobre esse código aqui: https://github.com/caio-ribeiro-pereira/ntask-api/blob/master/db.js
está funcionando pra você? É que estou fazendo aqui pelo livro mas deu problema com uma função. Talvez seja a versão.
Log:
db.models[key].associate(db.models);
^
TypeError: db.models[key].associate is not a function
Routes: Token
POST /token
status 200
**Unhandled rejection SequelizeBaseError: null**
at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14
at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18)
at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19)
at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
1) returns authenticated user token
status 401
Unhandled rejection SequelizeBaseError: null
at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14
at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18)
at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19)
at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
✓ throws error when password is incorrect
Unhandled rejection SequelizeBaseError: null
at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14
at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18)
at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19)
at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
✓ throws error when email not exist
Unhandled rejection SequelizeBaseError: null
at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14
at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18)
at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19)
at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
✓ throws error when email and password are blank
4 passing (187ms)
1 failing
Routes: Token POST /token status 200 returns authenticated user token:
Uncaught AssertionError: expected {} to contain key 'token'
-[]
+[
at Test. (token.js:24:41)
at Test.assert (node_modules/supertest/lib/test.js:156:6)
at Server.assert (node_modules/supertest/lib/test.js:127:12)
at emitCloseNT (net.js:1577:8)
at _combinedTickCallback (internal/process/next_tick.js:77:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Olá Caio,
Estou lendo o seu livro e estou tendo problemas com testes, mais especificamente da rota task / tasks/:id.
Não tá passando nenhum teste.
Segue um resumo:
- Routes: Tasks GET /tasks status 200 returns a list of tasks: Uncaught AssertionError: expected {} to have a property 'length'
- Routes: Tasks POST /tasks status 200 creates a new task: Uncaught AssertionError: expected undefined to deeply equal 'Run'
- Routes: Tasks GET /tasks/:id status 200 returns one task: Uncaught AssertionError: expected undefined to deeply equal 'Work'
- Routes: Tasks GET /tasks/:id status 404 throws error when task does not exist: Error: expected 404 "Not Found", got 401 "Unauthorized"
5 e 6 retorna Unauthorized tambem...
Verifiquei que o beforeEach ta rodando certinho, mas percebi que na tabela Tasks não tem o campo user_id que adicionamos ai, nem no seu repositório aqui no github. Tentei adicionar o campo mas ou não adicionei certo ou não fez efeito hehe.
Bom, fiz o upload pro github para que você possa dar uma olhada: https://github.com/esganzerla/ntask-api
Obrigado
npm start
[email protected] start /Users/adrianovasconcelos/Server/github/ntask-api
babel-node index.js
The CLI has been moved into the package babel-cli
. See http://babeljs.io/docs/usage/cli/
No package.son:
"dependencies": {
"babel": "^6.3.26",
"express": "^4.13.4"
},
Vi que você está usando babel-node para fazer o transpiling do es6, mas o node.js 4.x (depois da fusão com o io.js) já tem suporte ao es6 por padrão. Talvez fosse o caso de não precisar mais usá-lo. ;) (belo trabalho aqui, btw ;) )
Quando tento rodar o npm test
utilizando a configuração original...
module.exports = {
database: "ntask_test",
username: "",
password: "",
params: {
dialect: "sqlite",
storage: "ntask_test.sqlite",
logging: false,
sync: {
force: true
},
define: {
underscored: true
}
},
jwtSecret: "NTALK_TEST",
jwtSession: {session: false}
};
aparece o seguinte erro: Unhandled rejection SequelizeDatabaseError: SQLITE_ERROR: no such table: Users...
Então, mudei apenas o storage
para o arquivo sqlite
que o app criou. Ficando assim:
...
params: {
dialect: "sqlite",
storage: "ntask.sqlite",
...
Sucesso!!!
Mas a pergunta é: Por quê não funciona com o ntask_test.sqlite
?
Routes: Index
GET /
✓ returns the API status
Routes: Token
POST /token
status 200
Unhandled rejection SequelizeBaseError: null
at /home/dell/Workspace/Web/ntask-api/node_modules/sequelize/lib/instance-validator.js:74:14
at tryCatcher (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:638:18)
at PromiseArray._resolve (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:126:19)
at PromiseArray._promiseFulfilled (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise_array.js:144:14)
at Promise._settlePromise (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/home/dell/Workspace/Web/ntask-api/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
1) "before each" hook for "returns authenticated user token"
1 passing (2s)
1 failing
Routes: Token POST /token "before each" hook for "returns authenticated user token":
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
Olá Caio.
No capítulo 6, ao testar o método GET, rota http://localhost:3000/users/1
tenho o seguinte erro:
Users.findById is not a function
Poderia me ajudar?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.