Skip to content

Commit

Permalink
Added dummy delete post API endpoint (#354)
Browse files Browse the repository at this point in the history
refs [AP-810](https://linear.app/ghost/issue/AP-810/unblock-frontend-work-with-a-mock-deleteid-http-api)

Added a dummy delete post API endpoint that returns a 204 response for the purpose
of enabling the frontend to simulate a delete post action. This logic to be implemented
in this endpoint will be fleshed out at a later time
  • Loading branch information
mike182uk authored Mar 3, 2025
1 parent b9504cd commit de74a3a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 23 deletions.
5 changes: 5 additions & 0 deletions features/delete-post.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Delete a post

Scenario: Correct response code is returned
When an authenticated "delete" request is made to "/.ghost/activitypub/post/123"
Then the request is accepted with a 204
60 changes: 37 additions & 23 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,33 +594,38 @@ When('we request the outbox', async function () {
);
});

When('an authenticated request is made to {string}', async function (path) {
let requestPath = path;

// If this is a request to the /thread/ endpoint, we need to replace the
// object name with the object ID as we don't have a way to know the object
// ID ahead of time
if (path.includes('/thread/')) {
const objectName = path.split('/').pop(); // Object name is the last part of the path
const object = this.objects[objectName];
When(
/an authenticated (\"(delete|get|post|put)\"\s)?request is made to "(.*)"/,
async function (method, path) {
const requestMethod = method || 'get';
let requestPath = path;

// If this is a request to the /thread/ endpoint, we need to replace the
// object name with the object ID as we don't have a way to know the object
// ID ahead of time
if (path.includes('/thread/')) {
const objectName = path.split('/').pop(); // Object name is the last part of the path
const object = this.objects[objectName];

if (object) {
requestPath = path.replace(
objectName,
encodeURIComponent(object.id),
);
if (object) {
requestPath = path.replace(
objectName,
encodeURIComponent(object.id),
);
}
}
}

this.response = await fetchActivityPub(
`http://fake-ghost-activitypub${requestPath}`,
{
headers: {
Accept: 'application/ld+json',
this.response = await fetchActivityPub(
`http://fake-ghost-activitypub${requestPath}`,
{
method: requestMethod,
headers: {
Accept: 'application/ld+json',
},
},
},
);
});
);
},
);

When('an unauthenticated request is made to {string}', async function (path) {
this.response = await fetchActivityPub(
Expand Down Expand Up @@ -1341,6 +1346,15 @@ Then('the request is accepted', async function () {
);
});

Then('the request is accepted with a {int}', function (statusCode) {
assert(this.response.ok);
assert.equal(
this.response.status,
statusCode,
`Expected status code ${statusCode} - got ${this.response.status}`,
);
});

Then('a {string} activity is in the Outbox', async function (string) {
const [match, activity, object] = string.match(/(\w+)\((\w+)\)/) || [null];
if (!match) {
Expand Down
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import { getTraceContext } from './helpers/context-header';
import { getSiteSettings } from './helpers/ghost';
import { getRequestData } from './helpers/request-data';
import {
createDeletePostHandler,
createGetAccountFollowsHandler,
createGetAccountHandler,
createGetFeedHandler,
Expand Down Expand Up @@ -939,6 +940,11 @@ app.get(
requireRole(GhostRole.Owner),
spanWrapper(createGetFeedHandler(feedService, accountService, 'Inbox')),
);
app.delete(
'/.ghost/activitypub/post/:uuid',
requireRole(GhostRole.Owner),
spanWrapper(createDeletePostHandler()),
);
/** Federation wire up */

app.use(
Expand Down
1 change: 1 addition & 0 deletions src/http/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './activities';
export * from './account';
export * from './feed';
export * from './note';
export * from './post';
export * from './profile';
export * from './search';
export * from './thread';
Expand Down
13 changes: 13 additions & 0 deletions src/http/api/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Create a handler for a request to delete a post
*/
export function createDeletePostHandler() {
/**
* Handle a request to delete a post
*/
return async function handleDeletePost() {
return new Response(null, {
status: 204,
});
};
}

0 comments on commit de74a3a

Please sign in to comment.