Skip to content

Commit

Permalink
chore(tests) : documentation added
Browse files Browse the repository at this point in the history
- added documentation for global.auth method
- deleted commented temporary method
  • Loading branch information
e11sy committed Nov 5, 2023
1 parent a8c995b commit 3e73277
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 45 deletions.
28 changes: 3 additions & 25 deletions src/presentation/http/router/noteList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,11 @@
import userSessions from '@tests/test-data/userSessions.json';
import { describe, test, expect, beforeAll } from 'vitest';

let accessToken = '';
/**
* Util for authorization
*
* @param refreshToken - refresh token. There should be a user session with this refresh token in database
* @todo Move this function to tests/utils
* Access token that will be used for Auhorization header
*/
//
// async function authorize(refreshToken: string): Promise<string> {
// const response = await global.api?.fakeRequest({
// method: 'POST',
// url: '/auth',
// headers: {
// // eslint-disable-next-line @typescript-eslint/naming-convention
// 'Content-Type': 'application/json',
// },
// body : JSON.stringify({ token : refreshToken }),
// });
//
// const body: AuthSession = response?.body !== undefined ? JSON.parse(response?.body) : {};
//
// return body.accessToken;
// }
//
let accessToken = '';


describe('NoteList API', () => {
beforeAll(async () => {
Expand All @@ -34,9 +15,6 @@ describe('NoteList API', () => {
*/
const id = userSessions[0]['user_id'];

/**
* Access token that will be used for Auhorization header
*/
accessToken = global.auth(id);
});

Expand Down
24 changes: 4 additions & 20 deletions src/tests/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ declare global {
var api: Api | undefined;

/**
* Globslly exposed method for creating accessToken using id
* Is accessed as 'global.server' in tests
*
* @param refreshToken - token for finding user session and making accessToken
* @param id - id for making accessToken
* @returns accessToken for authorization
*/
function auth(refreshToken: number) : string;
function auth(id: number) : string;
}

/**
Expand Down Expand Up @@ -60,24 +62,6 @@ beforeAll(async () => {
global.auth = (id: number) => {
return domainServices.authService.signAccessToken({ id : id });
};

// global.auth = (id: string) => {
// return jwt.sign(id, 'JWT_SECRET');

//
// const response = await global.api?.fakeRequest({
// method: 'POST',
// url: '/auth',
// headers: {
// // eslint-disable-next-line @typescript-eslint/naming-convention
// 'Content-Type': 'application/json',
// },
// body : JSON.stringify({ id : id }),
// });
//
// const body: AuthSession = response?.body !== undefined ? JSON.parse(response?.body) : {};
//
//
}, TIMEOUT);

afterAll(async () => {
Expand Down

0 comments on commit 3e73277

Please sign in to comment.