caio-ribeiro-pereira / ntask-api

NTask - API de gestão de tarefas
109 stars 35 forks source link

this error happen when run all the tests #11

Open himanshu64 opened 7 years ago

himanshu64 commented 7 years ago

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

1) Routes: Token POST /token status 200 returns authenticated user token:

  Uncaught AssertionError: expected {} to contain key 'token'
  + expected - actual

  -[]
  +[
  +  "token"
  +]

  at Test.<anonymous> (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)
himanshu64 commented 7 years ago

@caio-ribeiro-pereira please check this

brotherhoodMonk commented 6 years ago

I'm facing the same issue.

kristianor commented 6 years ago

I'm facing the same issue.

sigit2306 commented 6 years ago

I'm facing the same issue

caio-ribeiro-pereira commented 5 years ago

Sorry for the delay of answering this issue......soon I will update all modules and code of this project to fix all current bugs and I will tell you guys, thanks!

allancmello commented 5 years ago

Olá Caio, o erro ainda continua.

` Routes: Index GET / √ returns the API status

Routes: Token POST /token status 200 1) returns authenticated user token status 401 √ throws error when password is incorrect √ throws error when email not exist √ throws error when email and password are blank

4 passing (1s) 1 failing

1) Routes: Token POST /token status 200 returns authenticated user token:

  Uncaught AssertionError: expected {} to contain key 'token'
  + expected - actual

  -[]
  +[
  +  "token"
  +]

  at Test.<anonymous> (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/token.js:25:41)
  at Test.assert (node_modules\supertest\lib\test.js:181:6)
  at Server.localAssert (node_modules\supertest\lib\test.js:131:12)
  at emitCloseNT (net.js:1618:8)
  at process._tickCallback (internal/process/next_tick.js:63:19)

npm ERR! Test failed. See above for more details.`

Tem uma solução para esse erro?

caio-ribeiro-pereira commented 5 years ago

Hi guys! Sorry for the delay....

To solve this current issue, please, try to initialize the api server first using npm start, this will run all database migrations, then close this api command (CTRL+C or COMMAND+C) and try to run again the npm test.

I know, this is not the best way, but it works here and I promise I will update this project codebase using all latest modules and new resources soon.

allancmello commented 5 years ago

Caio, continua dando o mesmo erro, mesmo após executar o npm start e demais processos descritos acima.

caio-ribeiro-pereira commented 5 years ago

@allancmello ja tentou excluir o ntastk.sqlite para rodar npm start, fecha e em seguida npm test?

allancmello commented 5 years ago

Caio, fiz o que vc pediu e o resultado agora e:

D:\Cursos\Nodejs\Api Restful\ntask>npm test

ntask@1.0.0 test D:\Cursos\Nodejs\Api Restful\ntask SET NODE_ENV=test&&mocha test/*/.js

Routes: Index GET / 1) returns the API status

Routes: Tasks GET /tasks status 200 2) returns a list of tasks POST /tasks status 200 3) creates a new task GET /tasks/:id status 200 4) returns one task status 404 5) throws error when task not exist PUT /tasks/:id status 204 6) updates a task DELETE /tasks/:id status 204 7) removes a task

Routes: Token POST /token status 200 8) returns authenticated user token status 401 √ throws error when password is incorrect √ throws error when email not exist √ throws error when email and password are blank

3 passing (4s) 8 failing

1) Routes: Index GET / returns the API status:

  Uncaught AssertionError: expected { status: 'Task API' } to deeply equal { status: 'NTask API' }
  + expected - actual

   {
  -  "status": "Task API"
  +  "status": "NTask API"
   }

  at Test.<anonymous> (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/index.js:10:41)
  at Test.assert (node_modules\supertest\lib\test.js:181:6)
  at Server.localAssert (node_modules\supertest\lib\test.js:131:12)
  at emitCloseNT (net.js:1618:8)
  at process._tickCallback (internal/process/next_tick.js:63:19)

2) Routes: Tasks GET /tasks status 200 returns a list of tasks: Uncaught AssertionError: expected {} to have property 'length' at Test. (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/tasks.js:43:46) at Test.assert (node_modules\supertest\lib\test.js:181:6) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)

3) Routes: Tasks POST /tasks status 200 creates a new task: Uncaught AssertionError: expected undefined to deeply equal 'Run' at Test. (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/tasks.js:60:47) at Test.assert (node_modules\supertest\lib\test.js:181:6) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)

4) Routes: Tasks GET /tasks/:id status 200 returns one task: Uncaught AssertionError: expected undefined to deeply equal 'Work' at Test. (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/tasks.js:75:47) at Test.assert (node_modules\supertest\lib\test.js:181:6) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)

5) Routes: Tasks GET /tasks/:id status 404 throws error when task not exist: Error: expected 404 "Not Found", got 401 "Unauthorized" at Test._assertStatus (node_modules\supertest\lib\test.js:268:12) at Test._assertFunction (node_modules\supertest\lib\test.js:283:11) at Test.assert (node_modules\supertest\lib\test.js:173:18) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)

6) Routes: Tasks PUT /tasks/:id status 204 updates a task: Error: expected 204 "No Content", got 401 "Unauthorized" at Test._assertStatus (node_modules\supertest\lib\test.js:268:12) at Test._assertFunction (node_modules\supertest\lib\test.js:283:11) at Test.assert (node_modules\supertest\lib\test.js:173:18) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)

7) Routes: Tasks DELETE /tasks/:id status 204 removes a task: Error: expected 204 "No Content", got 401 "Unauthorized" at Test._assertStatus (node_modules\supertest\lib\test.js:268:12) at Test._assertFunction (node_modules\supertest\lib\test.js:283:11) at Test.assert (node_modules\supertest\lib\test.js:173:18) at Server.localAssert (node_modules\supertest\lib\test.js:131:12) at emitCloseNT (net.js:1618:8) at process._tickCallback (internal/process/next_tick.js:63:19)

8) Routes: Token POST /token status 200 returns authenticated user token:

  Uncaught AssertionError: expected {} to contain key 'token'
  + expected - actual

  -[]
  +[
  +  "token"
  +]

  at Test.<anonymous> (D:/Cursos/Nodejs/Api Restful/ntask/test/routes/token.js:24:49)
  at Test.assert (node_modules\supertest\lib\test.js:181:6)
  at Server.localAssert (node_modules\supertest\lib\test.js:131:12)
  at emitCloseNT (net.js:1618:8)
  at process._tickCallback (internal/process/next_tick.js:63:19)

npm ERR! Test failed. See above for more details.

Erros que antes de apagar o ntask.sqlite não apareciam.

Creio que estes erros devem ter relação com as versões atuais. Meu packge.json:

{ "name": "ntask", "version": "1.0.0", "description": "Api Task", "main": "index.js", "scripts": { "dev": "nodemon index.js", "start": "npm run apidoc && npm run clusters", "clusters": "babel-node cluster.js", "apidoc": "apidoc -i routes/ -o public/apidoc", "test": "SET NODE_ENV=test&&mocha test/*/.js" }, "apidoc": { "name": "Documentação - Node Task API", "template": { "forceLanguage": "pt_br" } }, "author": "Alan Melo", "devDependencies": { "apidoc": "^0.17.7", "babel-cli": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-register": "^6.26.0", "bcrypt": "^3.0.5", "body-parser": "^1.18.3", "chai": "^4.2.0", "compression": "^1.7.4", "consign": "^0.1.6", "cors": "^2.8.5", "express": "^4.16.4", "helmet": "^3.16.0", "jwt-simple": "^0.5.5", "mocha": "^6.0.2", "morgan": "^1.9.1", "passport": "^0.4.0", "passport-jwt": "^4.0.0", "supertest": "^4.0.2", "winston": "^3.2.1" }, "dependencies": { "sequelize": "^5.1.1", "sqlite3": "^4.0.6" } }

Para suas considerações.

caio-ribeiro-pereira commented 5 years ago

@allancmello sugiro que utilize a versão antiga do sequelize, pois surgiram diversas break changes desde a versão desse repositorio vs com a versão atual, repare que os erros dos seus testes ocorrem somente em rotas que tentam consumir o bando de dados, sugestão ou vc utiliza a versão antiga ou se aventure nas documentações do sequelize para aplicar os códigos novos da versão 5.x.

TMendesO commented 1 year ago

No meu caso estava dando o mesmo erro o motivo foi o fechamento das chaves do "describe("POST /token", () => { }"estava fechando antes "describe("status 200", () => {}"