Skip to content

Commit

Permalink
access_token is undefined
Browse files Browse the repository at this point in the history
- trying to fix test problem with auth
  • Loading branch information
e11sy committed Oct 26, 2023
1 parent ce0099e commit aa12af4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/presentation/http/router/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const AuthRouter: FastifyPluginCallback<AuthRouterOptions> = (fastify, opts, don
}>('/', async (request, reply) => {
const { token } = request.body;

console.log('token======================================');
console.log(token);
throw new Error(token);
console.log('======================================');

const userSession = await opts.authService.verifyRefreshToken(token);

/**
Expand Down
28 changes: 22 additions & 6 deletions src/presentation/http/router/noteList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@ import userSessions from '@tests/test-data/userSessions.json';
import { describe, test, expect } from 'vitest';

const refresh_token = userSessions[0]['refresh_token'];


console.log('ref============================================');
console.log(refresh_token);
console.log('============================================');

const access_token = await global.api?.fakeRequest({
headers : {
'Content-Type': 'application/json',
},
method: 'POST',
url: `/auth/?token=${refresh_token}`,
url: '/auth',
body : JSON.stringify({ token : refresh_token }),
// body : refresh_token,
});


console.log('acc============================================');
console.log(access_token);
console.log('============================================');

describe('NoteList API', () => {
describe('GET /notes?page', () => {
test('Returns noteList with specified lenght (not for last page)', async () => {
Expand All @@ -19,7 +35,7 @@ describe('NoteList API', () => {
headers: {
authorization: `Bearer ${access_token}`,
},
url: `/notes/&page=${pageNumber}`,
url: `/notes&page=${pageNumber}`,
});

expect(response?.statusCode).toBe(expectedStatus);
Expand All @@ -39,7 +55,7 @@ describe('NoteList API', () => {
headers: {
authorization: `Bearer ${access_token}`,
},
url: `/notes/&page=${pageNumber}`,
url: `/notes&page=${pageNumber}`,
});

expect(response?.statusCode).toBe(expectedStatus);
Expand All @@ -58,7 +74,7 @@ describe('NoteList API', () => {
headers: {
authorization: `Bearer ${access_token}`,
},
url: `/notes/&page=${pageNumber}`,
url: `/notes&page=${pageNumber}`,
});

expect(response?.statusCode).toBe(expectedStatus);
Expand All @@ -79,7 +95,7 @@ describe('NoteList API', () => {
headers: {
authorization: `Bearer ${access_token}`,
},
url: `/notes/&page=${pageNumber}`,
url: `/notes&page=${pageNumber}`,
});

expect(response?.statusCode).toBe(expextedStatus);
Expand All @@ -94,7 +110,7 @@ describe('NoteList API', () => {
headers: {
authorization: `Bearer ${access_token}`,
},
url: `/notes/&page=${pageNumber}`,
url: `/notes&page=${pageNumber}`,
});

expect(response?.statusCode).toBe(expextedStatus);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test-data/userSessions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"id" : 1,
"user_id" : 4,
"refresh_token" : "IqrTkSKmel",
"refresh_token_expites_at" : "2023-11-21 19:19:40.911+03"
"refresh_token_expites_at" : "2025-11-21 19:19:40.911+03"
}
]
7 changes: 7 additions & 0 deletions src/tests/test-data/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
"email": "[email protected]",
"name": "Test user 1",
"created_at": "2023-10-16T13:49:19.000Z"
},
{
"id": 4,
"email": "[email protected]",
"name": "Егор Амурин",
"created_at": "2023-10-22 19:19:40.892+03",
"photo": "https://lh3.googleusercontent.com/a/ACg8ocL9_uBaC7XMFhosJZfIkDLC8tTm1GhtbvDfSbjf9eI2=s96-c"
}
]

0 comments on commit aa12af4

Please sign in to comment.