From f4073a5b20dfaaadbed48aa003eeccfcc1ffbaee Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 2 Jul 2024 19:43:43 +0300 Subject: [PATCH 1/3] Add updatedAt and createdAt to note schema --- src/presentation/http/schema/Note.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/presentation/http/schema/Note.ts b/src/presentation/http/schema/Note.ts index 70cdfe36..e1e13b1b 100644 --- a/src/presentation/http/schema/Note.ts +++ b/src/presentation/http/schema/Note.ts @@ -28,5 +28,13 @@ export const NoteSchema = { }, }, }, + createdAt: { + type: 'string', + format: 'date-time', + }, + updatedAt: { + type: 'string', + format: 'date-time', + }, }, }; From fea0fe397b5a349042cfbfb2876536836d12bd65 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 2 Jul 2024 20:44:20 +0300 Subject: [PATCH 2/3] Add test --- src/presentation/http/router/note.test.ts | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/presentation/http/router/note.test.ts b/src/presentation/http/router/note.test.ts index 684ecd64..8fa73454 100644 --- a/src/presentation/http/router/note.test.ts +++ b/src/presentation/http/router/note.test.ts @@ -600,6 +600,65 @@ describe('Note API', () => { } }); + test('UpdatedAt field is updated when note is modified', async () => { + /** Create test user */ + const user = await global.db.insertUser(); + + const accessToken = global.auth(user.id); + + /** Create test note */ + let note = await global.db.insertNote({ + creatorId: user.id, + }); + + /** Create test note settings */ + await global.db.insertNoteSetting({ + noteId: note.id, + isPublic: true, + }); + + /** Save the original value of updatedAt */ + const originalUpdatedAt = note.updatedAt; + + const newContent = { + blocks: [ + { + id: 'qxnjUh9muR', + type: headerTool.name, + data: { + text: 'sample text', + level: 1, + }, + }, + ], + }; + + const newTools = [ + { + name: headerTool.name, + id: headerTool.id, + }, + ]; + + /** Modify the note */ + const response = await global.api?.fakeRequest({ + method: 'PATCH', + headers: { + authorization: `Bearer ${accessToken}`, + }, + url: `/note/${note.publicId}`, + body: { + content: newContent, + tools: newTools, + }, + }); + + /** Check if note was modified successfully */ + expect(response?.statusCode).toBe(200); + + expect(response?.json().updatedAt).not.toEqual(originalUpdatedAt); + }); + test('Returns status 406 when the public id does not exist', async () => { const nonexistentId = 'ishvm5qH84'; From d3334c5b49bfd19f5ec58f2bf6974d99c4ad2547 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 2 Jul 2024 21:21:10 +0300 Subject: [PATCH 3/3] Add test case --- src/presentation/http/router/note.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/presentation/http/router/note.test.ts b/src/presentation/http/router/note.test.ts index 8fa73454..abb7f452 100644 --- a/src/presentation/http/router/note.test.ts +++ b/src/presentation/http/router/note.test.ts @@ -236,6 +236,10 @@ describe('Note API', () => { }, tools: [headerTool, paragraphTool], }); + + /** Check if response has createdAt and updatedAt fields */ + expect(response?.json().note.createdAt).not.toBeNull(); + expect(response?.json().note.updatedAt).not.toBeNull(); } else { expect(response?.json()).toStrictEqual({ message: expectedMessage,