Created
March 30, 2021 19:52
-
-
Save gabizinha12/afb431875c4a6adcadd042a4de29ca58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm test | |
> desafio@1.0.0 test D:\projetos\middlewares-ignite | |
> jest | |
FAIL src/__tests__/middlewares/checksTodoExists.spec.js | |
● Test suite failed to run | |
SyntaxError: D:\Projetos\middlewares-ignite\src\index.js: Identifier 'user' has already been declared (14:8) | |
12 | function checksExistsUserAccount(request, response, next) { | |
13 | const { user } = request; | |
> 14 | const user = users.find(user => user.username === username) | |
| ^ | |
15 | if (!user) { | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45) | |
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17) | |
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17) | |
at ScopeHandler.checkRedeclarationInScope (node_modules/@babel/parser/src/util/scope.js:141:12) | |
at ScopeHandler.declareName (node_modules/@babel/parser/src/util/scope.js:102:12) | |
at Parser.checkLVal (node_modules/@babel/parser/src/parser/lval.js:435:22) | |
at Parser.parseVarId (node_modules/@babel/parser/src/parser/statement.js:1051:10) | |
at Parser.parseVar (node_modules/@babel/parser/src/parser/statement.js:1012:12) | |
at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:706:10) | |
at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:223:21) | |
FAIL src/__tests__/middlewares/checksCreateTodosUserAvailability.spec.js | |
● Test suite failed to run | |
SyntaxError: D:\Projetos\middlewares-ignite\src\index.js: Identifier 'user' has already been declared (14:8) | |
12 | function checksExistsUserAccount(request, response, next) { | |
13 | const { user } = request; | |
> 14 | const user = users.find(user => user.username === username) | |
| ^ | |
15 | if (!user) { | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45) | |
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17) | |
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17) | |
at ScopeHandler.checkRedeclarationInScope (node_modules/@babel/parser/src/util/scope.js:141:12) | |
at ScopeHandler.declareName (node_modules/@babel/parser/src/util/scope.js:102:12) | |
at Parser.checkLVal (node_modules/@babel/parser/src/parser/lval.js:435:22) | |
at Parser.parseVarId (node_modules/@babel/parser/src/parser/statement.js:1051:10) | |
at Parser.parseVar (node_modules/@babel/parser/src/parser/statement.js:1012:12) | |
at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:706:10) | |
at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:223:21) | |
FAIL src/__tests__/todos.spec.js | |
● Test suite failed to run | |
SyntaxError: D:\Projetos\middlewares-ignite\src\index.js: Identifier 'user' has already been declared (14:8) | |
12 | function checksExistsUserAccount(request, response, next) { | |
13 | const { user } = request; | |
> 14 | const user = users.find(user => user.username === username) | |
| ^ | |
15 | if (!user) { | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45) | |
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17) | |
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17) | |
at ScopeHandler.checkRedeclarationInScope (node_modules/@babel/parser/src/util/scope.js:141:12) | |
at ScopeHandler.declareName (node_modules/@babel/parser/src/util/scope.js:102:12) | |
at Parser.checkLVal (node_modules/@babel/parser/src/parser/lval.js:435:22) | |
at Parser.parseVarId (node_modules/@babel/parser/src/parser/statement.js:1051:10) | |
at Parser.parseVar (node_modules/@babel/parser/src/parser/statement.js:1012:12) | |
at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:706:10) | |
at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:223:21) | |
FAIL src/__tests__/middlewares/findUserById.spec.js | |
● Test suite failed to run | |
SyntaxError: D:\Projetos\middlewares-ignite\src\index.js: Identifier 'user' has already been declared (14:8) | |
12 | function checksExistsUserAccount(request, response, next) { | |
13 | const { user } = request; | |
> 14 | const user = users.find(user => user.username === username) | |
| ^ | |
15 | if (!user) { | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45) | |
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17) | |
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17) | |
at ScopeHandler.checkRedeclarationInScope (node_modules/@babel/parser/src/util/scope.js:141:12) | |
at ScopeHandler.declareName (node_modules/@babel/parser/src/util/scope.js:102:12) | |
at Parser.checkLVal (node_modules/@babel/parser/src/parser/lval.js:435:22) | |
at Parser.parseVarId (node_modules/@babel/parser/src/parser/statement.js:1051:10) | |
at Parser.parseVar (node_modules/@babel/parser/src/parser/statement.js:1012:12) | |
at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:706:10) | |
at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:223:21) | |
FAIL src/__tests__/middlewares/checksExistsUserAccount.spec.js | |
● Test suite failed to run | |
SyntaxError: D:\Projetos\middlewares-ignite\src\index.js: Identifier 'user' has already been declared (14:8) | |
12 | function checksExistsUserAccount(request, response, next) { | |
13 | const { user } = request; | |
> 14 | const user = users.find(user => user.username === username) | |
| ^ | |
15 | if (!user) { | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45) | |
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17) | |
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17) | |
at ScopeHandler.checkRedeclarationInScope (node_modules/@babel/parser/src/util/scope.js:141:12) | |
at ScopeHandler.declareName (node_modules/@babel/parser/src/util/scope.js:102:12) | |
at Parser.checkLVal (node_modules/@babel/parser/src/parser/lval.js:435:22) | |
at Parser.parseVarId (node_modules/@babel/parser/src/parser/statement.js:1051:10) | |
at Parser.parseVar (node_modules/@babel/parser/src/parser/statement.js:1012:12) | |
at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:706:10) | |
at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:223:21) | |
FAIL src/__tests__/users.spec.js | |
● Test suite failed to run | |
SyntaxError: D:\Projetos\middlewares-ignite\src\index.js: Identifier 'user' has already been declared (14:8) | |
12 | function checksExistsUserAccount(request, response, next) { | |
13 | const { user } = request; | |
> 14 | const user = users.find(user => user.username === username) | |
| ^ | |
15 | if (!user) { | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
at Parser._raise (node_modules/@babel/parser/src/parser/error.js:97:45) | |
at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:92:17) | |
at Parser.raise (node_modules/@babel/parser/src/parser/error.js:41:17) | |
at ScopeHandler.checkRedeclarationInScope (node_modules/@babel/parser/src/util/scope.js:141:12) | |
at ScopeHandler.declareName (node_modules/@babel/parser/src/util/scope.js:102:12) | |
at Parser.checkLVal (node_modules/@babel/parser/src/parser/lval.js:435:22) | |
at Parser.parseVarId (node_modules/@babel/parser/src/parser/statement.js:1051:10) | |
at Parser.parseVar (node_modules/@babel/parser/src/parser/statement.js:1012:12) | |
at Parser.parseVarStatement (node_modules/@babel/parser/src/parser/statement.js:706:10) | |
at Parser.parseStatementContent (node_modules/@babel/parser/src/parser/statement.js:223:21) | |
Test Suites: 6 failed, 6 total | |
Tests: 0 total | |
Snapshots: 0 total | |
Time: 8.645 s | |
Ran all test suites. | |
npm ERR! Test failed. See above for more details. | |
Gabrielle Lima@DESKTOP-8L6ARFQ MINGW64 /d/projetos/middlewares-ignite (main) | |
$ npm test | |
> desafio@1.0.0 test D:\projetos\middlewares-ignite | |
> jest | |
FAIL src/__tests__/middlewares/checksExistsUserAccount.spec.js (5.417 s) | |
● checksExistsUserAccount › should be able to find user by username in header and pass it to request.user | |
ReferenceError: username is not defined | |
12 | function checksExistsUserAccount(request, response, next) { | |
13 | const { user } = request; | |
> 14 | const userFilter = users.find(user => user.username === username) | |
| ^ | |
15 | if (!userFiter) { | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
at find (src/index.js:14:59) | |
at Array.find (<anonymous>) | |
at checksExistsUserAccount (src/index.js:14:28) | |
at Object.<anonymous> (src/__tests__/middlewares/checksExistsUserAccount.spec.js:61:5) | |
● checksExistsUserAccount › should not be able to find a non existing user by username in header | |
ReferenceError: userFiter is not defined | |
13 | const { user } = request; | |
14 | const userFilter = users.find(user => user.username === username) | |
> 15 | if (!userFiter) { | |
| ^ | |
16 | return response.status(400).json({ error: 'User not found' }) | |
17 | } | |
18 | request.user = user; | |
at checksExistsUserAccount (src/index.js:15:3) | |
at Object.<anonymous> (src/__tests__/middlewares/checksExistsUserAccount.spec.js:77:5) | |
FAIL src/__tests__/middlewares/findUserById.spec.js (5.477 s) | |
● findUserById › should be able to find user by id route param and pass it to request.user | |
ReferenceError: id is not defined | |
44 | function findUserById(request, response, next) { | |
45 | const { user } = request; | |
> 46 | const userFind = users.find(user => user.id === id) | |
| ^ | |
47 | if (!userFind) { | |
48 | return response.status(400).json({ error: 'User not found' }) | |
49 | } | |
at find (src/index.js:46:51) | |
at Array.find (<anonymous>) | |
at findUserById (src/index.js:46:26) | |
at Object.<anonymous> (src/__tests__/middlewares/findUserById.spec.js:62:5) | |
● findUserById › should not be able to pass user to request.user when it does not exists | |
expect(jest.fn()).toBeCalledWith(...expected) | |
Expected: 404 | |
Received: 400 | |
Number of calls: 1 | |
77 | findUserById(mockRequest, mockResponse, mockNext); | |
78 | | |
> 79 | expect(mockResponse.status).toBeCalledWith(404); | |
| ^ | |
80 | | |
81 | expect(mockUserSetter).not.toBeCalled(); | |
82 | expect(mockNext).not.toBeCalled(); | |
at Object.<anonymous> (src/__tests__/middlewares/findUserById.spec.js:79:33) | |
FAIL src/__tests__/middlewares/checksTodoExists.spec.js (5.716 s) | |
● checksTodoExists › should be able to put user and todo in request when both exits | |
TypeError: Cannot read property 'todos' of undefined | |
35 | const { user } = request; | |
36 | const id = request.params; | |
> 37 | if (validate(id) || user.todos.id) { | |
| ^ | |
38 | request.todos = todos; | |
39 | request.user = user; | |
40 | } | |
at checksTodoExists (src/index.js:37:28) | |
at Object.<anonymous> (src/__tests__/middlewares/checksTodoExists.spec.js:75:5) | |
● checksTodoExists › should not be able to put user and todo in request when user does not exists | |
TypeError: Cannot read property 'todos' of undefined | |
35 | const { user } = request; | |
36 | const id = request.params; | |
> 37 | if (validate(id) || user.todos.id) { | |
| ^ | |
38 | request.todos = todos; | |
39 | request.user = user; | |
40 | } | |
at checksTodoExists (src/index.js:37:28) | |
at Object.<anonymous> (src/__tests__/middlewares/checksTodoExists.spec.js:113:5) | |
● checksTodoExists › should not be able to put user and todo in request when todo id is not uuid | |
TypeError: Cannot read property 'todos' of undefined | |
35 | const { user } = request; | |
36 | const id = request.params; | |
> 37 | if (validate(id) || user.todos.id) { | |
| ^ | |
38 | request.todos = todos; | |
39 | request.user = user; | |
40 | } | |
at checksTodoExists (src/index.js:37:28) | |
at Object.<anonymous> (src/__tests__/middlewares/checksTodoExists.spec.js:145:5) | |
● checksTodoExists › should not be able to put user and todo in request when todo does not exists | |
TypeError: Cannot read property 'todos' of undefined | |
35 | const { user } = request; | |
36 | const id = request.params; | |
> 37 | if (validate(id) || user.todos.id) { | |
| ^ | |
38 | request.todos = todos; | |
39 | request.user = user; | |
40 | } | |
at checksTodoExists (src/index.js:37:28) | |
at Object.<anonymous> (src/__tests__/middlewares/checksTodoExists.spec.js:177:5) | |
FAIL src/__tests__/middlewares/checksCreateTodosUserAvailability.spec.js | |
● checksCreateTodosUserAvailability › should be able to let user create a new todo when is in free plan and have less than ten todos | |
expect(jest.fn()).toBeCalled() | |
Expected number of calls: >= 1 | |
Received number of calls: 0 | |
58 | checksCreateTodosUserAvailability(mockRequest, mockResponse, mockNext); | |
59 | | |
> 60 | expect(mockNext).toBeCalled(); | |
| ^ | |
61 | }); | |
62 | | |
63 | it('should not be able to let user create a new todo when is not Pro and already have ten todos', () => { | |
at Object.<anonymous> (src/__tests__/middlewares/checksCreateTodosUserAvailability.spec.js:60:22) | |
● checksCreateTodosUserAvailability › should not be able to let user create a new todo when is not Pro and already have ten todos | |
expect(jest.fn()).toBeCalledWith(...expected) | |
Expected: 403 | |
Received: 200 | |
Number of calls: 1 | |
82 | checksCreateTodosUserAvailability(mockRequest, mockResponse, mockNext); | |
83 | | |
> 84 | expect(mockResponse.status).toBeCalledWith(403); | |
| ^ | |
85 | }); | |
86 | | |
87 | it('should be able to let user create infinite new todos when is in Pro plan', () => { | |
at Object.<anonymous> (src/__tests__/middlewares/checksCreateTodosUserAvailability.spec.js:84:33) | |
FAIL src/__tests__/users.spec.js | |
● Users › should be able to show user data | |
expect(received).toMatchObject(expected) | |
- Expected - 6 | |
+ Received + 1 | |
- Object { | |
- "name": "John Doe", | |
- "pro": false, | |
- "todos": Array [], | |
- "username": "johndoe3", | |
- } | |
+ Object {} | |
55 | .get(`/users/${userData.id}`); | |
56 | | |
> 57 | expect(response.body).toMatchObject({ | |
| ^ | |
58 | name: 'John Doe', | |
59 | username: 'johndoe3', | |
60 | todos: [], | |
at Object.<anonymous> (src/__tests__/users.spec.js:57:27) | |
FAIL src/__tests__/todos.spec.js | |
● Todos › should be able to list all user's todo | |
expect(received).toEqual(expected) // deep equality | |
Expected: ArrayContaining [{}] | |
Received: {} | |
27 | .set('username', userResponse.body.username); | |
28 | | |
> 29 | expect(response.body).toEqual( | |
| ^ | |
30 | expect.arrayContaining([ | |
31 | todoResponse.body | |
32 | ]), | |
at Object.<anonymous> (src/__tests__/todos.spec.js:29:27) | |
● Todos › should be able to create a new todo | |
expected 201 "Created", got 500 "Internal Server Error" | |
51 | }) | |
52 | .set('username', userResponse.body.username) | |
> 53 | .expect(201); | |
| ^ | |
54 | | |
55 | expect(response.body).toMatchObject({ | |
56 | title: 'test todo', | |
at Object.<anonymous> (src/__tests__/todos.spec.js:53:8) | |
---- | |
at Test.Object.<anonymous>.Test._assertStatus (node_modules/supertest/lib/test.js:296:12) | |
at node_modules/supertest/lib/test.js:80:15 | |
at Test.Object.<anonymous>.Test._assertFunction (node_modules/supertest/lib/test.js:311:11) | |
at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:201:21) | |
at Server.localAssert (node_modules/supertest/lib/test.js:159:12) | |
● Todos › should be able to update a todo | |
expect(received).toMatchObject(expected) | |
- Expected - 5 | |
+ Received + 1 | |
- Object { | |
- "deadline": "2021-03-30T19:28:38.430Z", | |
- "done": false, | |
- "title": "update title", | |
- } | |
+ Object {} | |
88 | .set('username', userResponse.body.username); | |
89 | | |
> 90 | expect(response.body).toMatchObject({ | |
| ^ | |
91 | title: 'update title', | |
92 | deadline: todoDate.toISOString(), | |
93 | done: false | |
at Object.<anonymous> (src/__tests__/todos.spec.js:90:27) | |
● Todos › should not be able to update a non existing todo | |
expected 404 "Not Found", got 500 "Internal Server Error" | |
112 | }) | |
113 | .set('username', userResponse.body.username) | |
> 114 | .expect(404); | |
| ^ | |
115 | | |
116 | expect(response.body.error).toBeTruthy(); | |
117 | }); | |
at Object.<anonymous> (src/__tests__/todos.spec.js:114:8) | |
---- | |
at Test.Object.<anonymous>.Test._assertStatus (node_modules/supertest/lib/test.js:296:12) | |
at node_modules/supertest/lib/test.js:80:15 | |
at Test.Object.<anonymous>.Test._assertFunction (node_modules/supertest/lib/test.js:311:11) | |
at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:201:21) | |
at Server.localAssert (node_modules/supertest/lib/test.js:159:12) | |
● Todos › should be able to mark a todo as done | |
expect(received).toMatchObject(expected) | |
- Expected - 3 | |
+ Received + 1 | |
- Object { | |
- "done": true, | |
- } | |
+ Object {} | |
139 | .set('username', userResponse.body.username); | |
140 | | |
> 141 | expect(response.body).toMatchObject({ | |
| ^ | |
142 | ...todoResponse.body, | |
143 | done: true | |
144 | }); | |
at Object.<anonymous> (src/__tests__/todos.spec.js:141:27) | |
● Todos › should not be able to mark a non existing todo as done | |
expected 404 "Not Found", got 500 "Internal Server Error" | |
156 | .patch(`/todos/${v4()}/done`) | |
157 | .set('username', userResponse.body.username) | |
> 158 | .expect(404); | |
| ^ | |
159 | | |
160 | expect(response.body.error).toBeTruthy(); | |
161 | }); | |
at Object.<anonymous> (src/__tests__/todos.spec.js:158:8) | |
---- | |
at Test.Object.<anonymous>.Test._assertStatus (node_modules/supertest/lib/test.js:296:12) | |
at node_modules/supertest/lib/test.js:80:15 | |
at Test.Object.<anonymous>.Test._assertFunction (node_modules/supertest/lib/test.js:311:11) | |
at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:201:21) | |
at Server.localAssert (node_modules/supertest/lib/test.js:159:12) | |
● Todos › should be able to delete a todo | |
expected 204 "No Content", got 500 "Internal Server Error" | |
182 | .delete(`/todos/${todo1Response.body.id}`) | |
183 | .set('username', userResponse.body.username) | |
> 184 | .expect(204); | |
| ^ | |
185 | | |
186 | const listResponse = await request(app) | |
187 | .get('/todos') | |
at Object.<anonymous> (src/__tests__/todos.spec.js:184:8) | |
---- | |
at Test.Object.<anonymous>.Test._assertStatus (node_modules/supertest/lib/test.js:296:12) | |
at node_modules/supertest/lib/test.js:80:15 | |
at Test.Object.<anonymous>.Test._assertFunction (node_modules/supertest/lib/test.js:311:11) | |
at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:201:21) | |
at Server.localAssert (node_modules/supertest/lib/test.js:159:12) | |
● Todos › should not be able to delete a non existing todo | |
expected 404 "Not Found", got 500 "Internal Server Error" | |
202 | .delete(`/todos/${v4()}`) | |
203 | .set('username', userResponse.body.username) | |
> 204 | .expect(404); | |
| ^ | |
205 | | |
206 | expect(response.body.error).toBeTruthy(); | |
207 | }); | |
at Object.<anonymous> (src/__tests__/todos.spec.js:204:8) | |
---- | |
at Test.Object.<anonymous>.Test._assertStatus (node_modules/supertest/lib/test.js:296:12) | |
at node_modules/supertest/lib/test.js:80:15 | |
at Test.Object.<anonymous>.Test._assertFunction (node_modules/supertest/lib/test.js:311:11) | |
at Test.Object.<anonymous>.Test.assert (node_modules/supertest/lib/test.js:201:21) | |
at Server.localAssert (node_modules/supertest/lib/test.js:159:12) | |
Test Suites: 6 failed, 6 total | |
Tests: 19 failed, 3 passed, 22 total | |
Snapshots: 0 total | |
Time: 9.508 s | |
Ran all test suites. | |
npm ERR! Test failed. See above for more details. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment