Skip to content
Open
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
6 changes: 6 additions & 0 deletions packages/endpoint-micropub/lib/post-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export const postData = {
const query = { "properties.url": url };
const postsCollection = application?.collections?.get("posts");

if (!postsCollection) {
throw IndiekitError.notImplemented(
"Reading, updating, deleting and restoring posts requires a database",
);
}

const data = await postsCollection.findOne(query);
if (!data) {
throw IndiekitError.notFound(url);
Expand Down
10 changes: 10 additions & 0 deletions packages/endpoint-micropub/test/unit/post-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ describe("endpoint-micropub/lib/post-data", async () => {
assert.equal(result.properties.url, url);
});

it("Throws reading post data without a database", async () => {
await assert.rejects(
postData.read({ ...application, collections: undefined }, url),
{
message:
"Reading, updating, deleting and restoring posts requires a database",
},
);
});

it("Updates post by adding properties", async () => {
const operation = { add: { syndication: ["https://website.example"] } };
const result = await postData.update(
Expand Down