Skip to content

Commit

Permalink
fix timestamp error
Browse files Browse the repository at this point in the history
  • Loading branch information
sora committed Jan 13, 2022
1 parent 879cc4f commit 396d755
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
24 changes: 1 addition & 23 deletions packages/feed-builder/src/plugins/lib/__tests__/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@ describe("Util/Merge", () => {
});

it("Feed/Metadata update", async () => {
const existing: JsonFeed = {
version: "Mock version",
title: "Mock title",
description: "Mock description",
items: [],
};

const incoming: JsonFeed = {
version: "Mock version",
title: "Mock title new",
description: "Mock description new",
items: [],
};

const merged = mergeJsonFeed(incoming, existing);

await expect(merged.items.length).toEqual(0);
await expect(merged.title).toEqual("Mock title new");
await expect(merged.description).toEqual("Mock description new");
});

it("Feed/Metadata update/Persist publish time", async () => {
const existing: JsonFeed = {
version: "Mock version",
title: "Mock title",
Expand All @@ -70,7 +48,7 @@ describe("Util/Merge", () => {
await expect(merged.items.length).toEqual(0);
await expect(merged.title).toEqual("Mock title new");
await expect(merged.description).toEqual("Mock description new");
await expect(merged._ext.date_published).toEqual("2000-01-01T00:00:00Z");
await expect(merged._ext.date_published).toEqual("2000-01-02T00:00:00Z");
});

it("Items/Addition", async () => {
Expand Down
5 changes: 0 additions & 5 deletions packages/feed-builder/src/plugins/lib/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ export function mergeJsonFeed<T extends JsonFeed>(newFeed: T, existingFeed: T):
return {
...existingFeed,
...newFeed,
_ext: {
...existingFeed._ext,
...newFeed._ext,
date_published: existingFeed._ext?.date_published ?? newFeed._ext?.date_published, // publish timestamp is considered immutable
},
items: mergeFeedItems(newFeed.items, existingFeed.items, mergeItems).sort(sortItems),
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/feed-builder/src/plugins/synthetic-publish-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export function useSyntheticPublishTime(): Plugin {
_ext: {
...feed._ext,
date_published:
(feed as ParsedJsonFeed)._ext?.date_published ??
(feed as ParsedJsonFeed)._ext?.date_modified ??
feed.items[0]?.date_published ??
feed.items[0]?.date_modified ??
(feed as ParsedJsonFeed)._ext?.date_published ??
(feed as ParsedJsonFeed)._ext?.date_modified ??
new Date().toISOString(),
},
})),
Expand Down

0 comments on commit 396d755

Please sign in to comment.