Skip to content

Commit

Permalink
feat(noteList.test)
Browse files Browse the repository at this point in the history
*added test added for /notes of one user
*added insertUserSessions function
*added json file for insertUserSessions function
*added notes to notes.json (now 50) with one user_id
*renamed notes-settings to camelcase
notesSettings now
  • Loading branch information
e11sy committed Oct 22, 2023
1 parent e72b453 commit ef2e923
Show file tree
Hide file tree
Showing 5 changed files with 511 additions and 2 deletions.
97 changes: 97 additions & 0 deletions src/presentation/http/router/noteList.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { describe, test, expect } from 'vitest';
import userSessions from 'tests/test-data/userSessions.json';

const refresh_token = userSessions[0]['refresh_tocken'];
const access_token = await global.api?.fakeRequest({
method: 'POST',
url: `/auth/?token=${refresh_token}`,
});

describe('NoteList API', () => {
describe('GET notes?page', () => {
test('Returns noteList with specified lenght (not for last page)', async () => {
const expectedStatus = 200;
const portionSize = 30;

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${access_token}`,
},
url: '/notes/&page=1',
});

expect(response?.statusCode).toBe(expectedStatus);

const body = response?.body !== undefined ? JSON.parse(response?.body) : {};

expect(body).toHaveLength(portionSize);
});

test('Returns noteList with specified lenght (for last page)', async () => {
const expectedStatus = 200;
const portionSize = 20;

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${access_token}`,
},
url: '/notes/&page=2',
});

expect(response?.statusCode).toBe(expectedStatus);

const body = response?.body !== undefined ? JSON.parse(response?.body) : {};

expect(body).toHaveLength(portionSize);
});

test('Returns noteList with no items if page*portionSize > numberOfNotes', async () => {
const expectedStatus = 200;

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${access_token}`,
},
url: '/notes/&page=3',
});

expect(response?.statusCode).toBe(expectedStatus);

const body = response?.body !== undefined ? JSON.parse(response?.body) : {};

expect(body).toEqual([]);
expect(body).toHaveLength(0);
});

test('Returns 400 when page < 0', async () => {
const expextedStatus = 400;

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${access_token}`,
},
url: '/notes/&page=0',
});

expect(response?.statusCode).toBe(expextedStatus);
});

test('Returns 400 when page > 0', async () => {
const expextedStatus = 400;

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${access_token}`,
},
url: '/notes/&page=31',
});

expect(response?.statusCode).toBe(expextedStatus);
});
});
});
Loading

0 comments on commit ef2e923

Please sign in to comment.