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

feat: return fields updatedAt and createdAt with note #262

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/presentation/http/router/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -600,6 +604,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';

Expand Down
8 changes: 8 additions & 0 deletions src/presentation/http/schema/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ export const NoteSchema = {
},
},
},
createdAt: {
type: 'string',
format: 'date-time',
},
updatedAt: {
type: 'string',
format: 'date-time',
},
},
};
Loading