Skip to content

Commit

Permalink
feat: stop setting empty flags header
Browse files Browse the repository at this point in the history
  • Loading branch information
polyrainbow committed Jun 16, 2024
1 parent d831720 commit bd7d689
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/lib/notes/noteUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ describe("serializeNote", () => {
:custom-header-1:custom-value-1
:custom-header-2:custom-value-2
This is a note`;

expect(
serializeNote(note),
).toBe(expectedResult);
},
);

it(
"should not send empty flags header",
async () => {
const note: ExistingNote = {
content: "This is a note",
meta: {
slug: "1",
createdAt: "2024-06-01T20:30:00+02:00",
updatedAt: "2024-06-01T20:31:00+02:00",
additionalHeaders: {},
flags: [],
},
};

const expectedResult = `:created-at:2024-06-01T20:30:00+02:00
:updated-at:2024-06-01T20:31:00+02:00
This is a note`;

expect(
Expand Down
10 changes: 6 additions & 4 deletions src/lib/notes/noteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@ const serializeNote = (note: ExistingNote): string => {
);
}

headersToSerialize.set(
CanonicalNoteHeader.FLAGS,
note.meta.flags.join(","),
);
if (note.meta.flags.length > 0) {
headersToSerialize.set(
CanonicalNoteHeader.FLAGS,
note.meta.flags.join(","),
);
}

for (const key in note.meta.additionalHeaders) {
if (Object.hasOwn(note.meta.additionalHeaders, key)) {
Expand Down

0 comments on commit bd7d689

Please sign in to comment.