Skip to content

Commit

Permalink
update(tests): add different tests for the note parent structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dependentmadani committed Sep 8, 2024
1 parent a11d1f8 commit 0e3e8f0
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/presentation/http/router/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,133 @@ 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 () => {
/** Create test user */
const user = await global.db.insertUser();

/** Create test note - a parent note */
const parentNote = await global.db.insertNote({
creatorId: user.id,
});

/** Create test note - a child note */
const childNote = await global.db.insertNote({
creatorId: user.id,
});

/** Create test note settings */
await global.db.insertNoteSetting({
noteId: childNote.id,
isPublic: true,
});

/** Create test note relation */
await global.db.insertNoteRelation({
parentId: parentNote.id,
noteId: childNote.id,
});

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

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

expect(response?.json()).toMatchObject({

Check failure on line 555 in src/presentation/http/router/note.test.ts

View workflow job for this annotation

GitHub Actions / tests (feat/return-note)

src/presentation/http/router/note.test.ts > Note API > GET note/:notePublicId > Returns one object of note parent structure by note public id with 200 status

AssertionError: expected { …(4) } to match object { parentStructure: [ { …(2) } ] } - Expected + Received Object { - "parentStructure": Array [ + "accessRights": Object { + "canEdit": false, + }, + "note": Object { + "content": Object { + "blocks": Array [ Object { + "data": Object { + "text": "text", + }, + "id": "mJDq8YbvqO", + "type": "paragraph", + }, + Object { + "data": Object { + "level": 2, + "text": "fdgsfdgfdsg", + }, + "id": "DeL0QehzGe", + "type": "header", + }, + ], + }, + "createdAt": "2024-09-08T16:42:37.826Z", + "id": "lfov8VsJC7", + "updatedAt": "2024-09-08T16:42:37.826Z", + }, + "parentNote": Object { "content": Object { "blocks": Array [ Object { "data": Object { "text": "text", }, "id": "mJDq8YbvqO", "type": "paragraph", }, Object { "data": Object { "level": 2, "text": "fdgsfdgfdsg", }, "id": "DeL0QehzGe", "type": "header", }, ], }, - "noteId": "w1z9hd4Mhp", + "createdAt": "2024-09-08T16:42:37.823Z", + "id": "w1z9hd4Mhp", + "updatedAt": "2024-09-08T16:42:37.823Z", + }, + "tools": Array [ + Object { + "exportName": "Header", + "id": "1", + "isDefault": true, + "name": "header", + "source": Object { + "cdn": "https://cdn.jsdelivr.net/npm/@editorjs/header@2.8.1/dist/header.umd.min.js", + }, + "title": "Heading", + "userId": null, + }, + Object { + "exportName": "Paragraph", + "id": "2", + "isDefault": true, + "name": "paragraph", + "source": Object { + "cdn": "https://cdn.jsdelivr.net/npm/@editorjs/paragraph@2.11.3/dist/paragraph.umd.min.js", + }, + "title": "Paragraph", + "userId": null, }, ], } ❯ src/presentation/http/router/note.test.ts:555:32
parentStructure: [
{
noteId: parentNote.publicId,
content: parentNote.content,
},
],
});
});

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

/** Create test note - a parent note */
const parentNote = await global.db.insertNote({
creatorId: user.id,
});

/** Create test note - a child note */
const childNote = await global.db.insertNote({
creatorId: user.id,
});

/** Create test note - a grandchild note */
const grandchildNote = await global.db.insertNote({
creatorId: user.id,
});

/** Create test note settings */
await global.db.insertNoteSetting({
noteId: grandchildNote.id,
isPublic: true,
});

/** Create test note relation */
await global.db.insertNoteRelation({
parentId: parentNote.id,
noteId: childNote.id,
});

await global.db.insertNoteRelation({
parentId: childNote.id,
noteId: grandchildNote.id,
});

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

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

expect(response?.json()).toMatchObject({

Check failure on line 608 in src/presentation/http/router/note.test.ts

View workflow job for this annotation

GitHub Actions / tests (feat/return-note)

src/presentation/http/router/note.test.ts > Note API > GET note/:notePublicId > Returns multiple objects of note parent structure by note public id with 200 status

AssertionError: expected { …(4) } to match object { parentStructure: [ { …(2) }, …(1) ] } - Expected + Received Object { - "parentStructure": Array [ - Object { + "accessRights": Object { + "canEdit": false, + }, + "note": Object { "content": Object { "blocks": Array [ Object { "data": Object { "text": "text", }, "id": "mJDq8YbvqO", "type": "paragraph", }, Object { "data": Object { "level": 2, "text": "fdgsfdgfdsg", }, "id": "DeL0QehzGe", "type": "header", }, ], }, - "noteId": "7gnY08ku_7", + "createdAt": "2024-09-08T16:42:37.912Z", + "id": "Ji05hOlGjY", + "updatedAt": "2024-09-08T16:42:37.912Z", }, - Object { + "parentNote": Object { "content": Object { "blocks": Array [ Object { "data": Object { "text": "text", }, "id": "mJDq8YbvqO", "type": "paragraph", }, Object { "data": Object { "level": 2, "text": "fdgsfdgfdsg", }, "id": "DeL0QehzGe", "type": "header", }, ], }, - "noteId": "1yiKr8U5js", + "createdAt": "2024-09-08T16:42:37.910Z", + "id": "7gnY08ku_7", + "updatedAt": "2024-09-08T16:42:37.910Z", + }, + "tools": Array [ + Object { + "exportName": "Header", + "id": "1", + "isDefault": true, + "name": "header", + "source": Object { + "cdn": "https://cdn.jsdelivr.net/npm/@editorjs/header@2.8.1/dist/header.umd.min.js", + }, + "title": "Heading", + "userId": null, + }, + Object { + "exportName": "Paragraph", + "id": "2", + "isDefault": true, + "name": "paragraph", + "source": Object { + "cdn": "https://cdn.jsdelivr.net/npm/@editorjs/paragraph@2.11.3/dist/paragraph.umd.min.js", + }, + "title": "Paragraph", + "userId": null, }, ], } ❯ src/presentation/http/router/note.test.ts:608:32
parentStructure: [
{
noteId: childNote.publicId,
content: childNote.content,
},
{
noteId: parentNote.publicId,
content: parentNote.content,
},
],
});
});

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

/** Create test note */
const note = await global.db.insertNote({
creatorId: user.id,
});

/** Create test note settings */
await global.db.insertNoteSetting({
noteId: note.id,
isPublic: true,
});

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

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

expect(response?.json()).toMatchObject({

Check failure on line 644 in src/presentation/http/router/note.test.ts

View workflow job for this annotation

GitHub Actions / tests (feat/return-note)

src/presentation/http/router/note.test.ts > Note API > GET note/:notePublicId > Returns empty array of note parent structure by note public id with 200 status

AssertionError: expected { …(3) } to match object { parentStructure: [] } - Expected + Received Object { - "parentStructure": Array [], + "accessRights": Object { + "canEdit": false, + }, + "note": Object { + "content": Object { + "blocks": Array [ + Object { + "data": Object { + "text": "text", + }, + "id": "mJDq8YbvqO", + "type": "paragraph", + }, + Object { + "data": Object { + "level": 2, + "text": "fdgsfdgfdsg", + }, + "id": "DeL0QehzGe", + "type": "header", + }, + ], + }, + "createdAt": "2024-09-08T16:42:37.991Z", + "id": "wssuSRaJJt", + "updatedAt": "2024-09-08T16:42:37.991Z", + }, + "tools": Array [ + Object { + "exportName": "Header", + "id": "1", + "isDefault": true, + "name": "header", + "source": Object { + "cdn": "https://cdn.jsdelivr.net/npm/@editorjs/header@2.8.1/dist/header.umd.min.js", + }, + "title": "Heading", + "userId": null, + }, + Object { + "exportName": "Paragraph", + "id": "2", + "isDefault": true, + "name": "paragraph", + "source": Object { + "cdn": "https://cdn.jsdelivr.net/npm/@editorjs/paragraph@2.11.3/dist/paragraph.umd.min.js", + }, + "title": "Paragraph", + "userId": null, + }, + ], } ❯ src/presentation/http/router/note.test.ts:644:32
parentStructure: [],
});
});
});

describe('PATCH note/:notePublicId ', () => {
Expand Down

0 comments on commit 0e3e8f0

Please sign in to comment.