Skip to content

Commit

Permalink
update(tests): tests are now functional
Browse files Browse the repository at this point in the history
  • Loading branch information
dependentmadani committed Sep 9, 2024
1 parent 0e3e8f0 commit 3adff28
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/presentation/http/router/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,13 @@ describe('Note API', () => {
expect(response?.json().message).toStrictEqual(expectedMessage);
});

test('Returns one object of note parent structure by note public id with 200 status', async () => {
test('Returns two objects of note parent structure by note public id with 200 status', async () => {
/** Create test user */
const user = await global.db.insertUser();

/** Create acces token for the user */
const accessToken = global.auth(user.id);

/** Create test note - a parent note */
const parentNote = await global.db.insertNote({
creatorId: user.id,
Expand All @@ -547,6 +550,9 @@ describe('Note API', () => {

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${accessToken}`,
},
url: `/note/${childNote.publicId}`,
});

Expand All @@ -558,6 +564,10 @@ describe('Note API', () => {
noteId: parentNote.publicId,
content: parentNote.content,
},
{
noteId: childNote.publicId,
content: childNote.content,
},
],
});
});
Expand All @@ -566,6 +576,9 @@ describe('Note API', () => {
/** Create test user */
const user = await global.db.insertUser();

/** Create acces token for the user */
const accessToken = global.auth(user.id);

/** Create test note - a parent note */
const parentNote = await global.db.insertNote({
creatorId: user.id,
Expand Down Expand Up @@ -600,29 +613,38 @@ describe('Note API', () => {

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${accessToken}`,
},
url: `/note/${grandchildNote.publicId}`,
});

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

expect(response?.json()).toMatchObject({
parentStructure: [
{
noteId: parentNote.publicId,
content: parentNote.content,
},
{
noteId: childNote.publicId,
content: childNote.content,
},
{
noteId: parentNote.publicId,
content: parentNote.content,
noteId: grandchildNote.publicId,
content: grandchildNote.content,
},
],
});
});

test('Returns empty array of note parent structure by note public id with 200 status', async () => {
test('Returns one object in array of note parent structure by note public id with 200 status', async () => {
/** Create test user */
const user = await global.db.insertUser();

/** Create acces token for the user */
const accessToken = global.auth(user.id);
/** Create test note */
const note = await global.db.insertNote({
creatorId: user.id,
Expand All @@ -636,13 +658,21 @@ describe('Note API', () => {

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${accessToken}`,
},
url: `/note/${note.publicId}`,
});

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

expect(response?.json()).toMatchObject({
parentStructure: [],
parentStructure: [
{
noteId: note.publicId,
content: note.content,
},
],
});
});
});
Expand Down
14 changes: 14 additions & 0 deletions src/presentation/http/router/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ const NoteRouter: FastifyPluginCallback<NoteRouterOptions> = (fastify, opts, don
$ref: 'EditorToolSchema',
},
},
parentStructure: {
type: 'array',
items: {
type: 'object',
properties: {
noteId: {
$ref: 'NoteSchema#/properties/id',
},
content: {
$ref: 'NoteSchema#/properties/content',
},
},
},
},
},
},
},
Expand Down

0 comments on commit 3adff28

Please sign in to comment.