Skip to content

Commit

Permalink
Testcases were written for the get note by id method
Browse files Browse the repository at this point in the history
New data for tests were added to the test database
  • Loading branch information
elizachi committed Oct 27, 2023
1 parent 1da02f9 commit 3c3e39a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
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', () => {
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',
});

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

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

expect(body).toStrictEqual(expectedNote);
});

test('Returns 403 when permission denied', async () => {
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 () => {
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"
}
]

0 comments on commit 3c3e39a

Please sign in to comment.