Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for get note by id #99

Merged
merged 12 commits into from
Nov 3, 2023
59 changes: 59 additions & 0 deletions src/presentation/http/router/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,62 @@ describe('Note API', () => {
});
});
});

describe('Note API', () => {
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
describe('GET note/:notePublicId ', () => {
test('Returns note by public id', async () => {
const expectedStatus = 200;

const expectedNote = {
'id': 2,
'publicId': 'testnote11',
'creatorId': 1,
'content': null,
'createdAt': '2023-10-16T13:49:19.000Z',
'updatedAt': '2023-10-16T13:49:19.000Z',
};

const response = await global.api?.fakeRequest({
method: 'GET',
url: '/note/testnote11',
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
});

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

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

expect(body).toStrictEqual(expectedNote);
TatianaFomina marked this conversation as resolved.
Show resolved Hide resolved
});

test('Returns 403 when permission denied', async () => {
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
const expectedStatus = 403;

const response = await global.api?.fakeRequest({
method: 'GET',
url: '/note/testnote22',
});

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

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

expect(body).toStrictEqual({ message: 'Permission denied' });
});

test('Returns 406 when public id incorrect', async () => {
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
const expectedStatus = 406;

const response = await global.api?.fakeRequest({
method: 'GET',
url: '/note/wrong_1_id',
});

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

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

expect(body).toStrictEqual({ message: 'Note not found' });
});

});
});
14 changes: 14 additions & 0 deletions src/tests/test-data/notes-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,19 @@
"note_id": 1,
"custom_hostname": "codex.so",
"is_public": true
},

{
"id": 2,
"note_id": 2,
"custom_hostname": "codex.so",
"is_public": true
},

{
"id": 3,
"note_id": 3,
"custom_hostname": "codex.so",
"is_public": false
}
]
18 changes: 18 additions & 0 deletions src/tests/test-data/notes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,23 @@
"content": [],
"created_at": "2023-10-16T13:49:19.000Z",
"updated_at": "2023-10-16T13:49:19.000Z"
},

{
"id": 2,
"public_id": "testnote11",
"creator_id": 1,
"content": [],
"created_at": "2023-10-16T13:49:19.000Z",
"updated_at": "2023-10-16T13:49:19.000Z"
},

{
"id": 3,
"public_id": "testnote22",
"creator_id": 1,
"content": [],
"created_at": "2023-10-16T13:49:19.000Z",
"updated_at": "2023-10-16T13:49:19.000Z"
}
]