Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix: switch feed fetch endpoint to POST and add E2E coverage (#2677)

Mohamed Bassemde65a47ce940
diff --git a/packages/api/routes/feeds.ts b/packages/api/routes/feeds.ts
index fe6f5d69..41943596 100644
--- a/packages/api/routes/feeds.ts
+++ b/packages/api/routes/feeds.ts
@@ -50,8 +50,8 @@ const app = new Hono()
return c.body(null, 204);
})
- // PUT /feeds/:feedId/fetch
- .put("/:feedId/fetch", async (c) => {
+ // POST /feeds/:feedId/fetch
+ .post("/:feedId/fetch", async (c) => {
const feedId = c.req.param("feedId");
await c.var.api.feeds.fetchNow({ feedId });
return c.body(null, 204);
diff --git a/packages/e2e_tests/tests/api/feeds.test.ts b/packages/e2e_tests/tests/api/feeds.test.ts
new file mode 100644
index 00000000..ac45c66b
--- /dev/null
+++ b/packages/e2e_tests/tests/api/feeds.test.ts
@@ -0,0 +1,223 @@
+import { assert, beforeEach, describe, expect, inject, it } from "vitest";
+
+import { createKarakeepClient } from "@karakeep/sdk";
+
+import { createTestUser } from "../../utils/api";
+import { waitUntil } from "../../utils/general";
+
+describe("Feeds API", () => {
+ const port = inject("karakeepPort");
+
+ if (!port) {
+ throw new Error("Missing required environment variables");
+ }
+
+ let client: ReturnType<typeof createKarakeepClient>;
+ let apiKey: string;
+
+ beforeEach(async () => {
+ apiKey = await createTestUser();
+ client = createKarakeepClient({
+ baseUrl: `http://localhost:${port}/api/v1/`,
+ headers: {
+ "Content-Type": "application/json",
+ authorization: `Bearer ${apiKey}`,
+ },
+ });
+ });
+
+ it("should list feeds", async () => {
+ const { data: firstFeed } = await client.POST("/feeds", {
+ body: {
+ name: "First Feed",
+ url: "https://example.com/first.xml",
+ enabled: true,
+ },
+ });
+ const { data: secondFeed } = await client.POST("/feeds", {
+ body: {
+ name: "Second Feed",
+ url: "https://example.com/second.xml",
+ enabled: false,
+ importTags: true,
+ },
+ });
+
+ const { data: listedFeeds, response } = await client.GET("/feeds", {});
+
+ expect(response.status).toBe(200);
+ expect(listedFeeds).toBeDefined();
+ expect(listedFeeds!.feeds.map((feed) => feed.id)).toEqual(
+ expect.arrayContaining([firstFeed!.id, secondFeed!.id]),
+ );
+ });
+
+ it("should create, get, update and delete a feed", async () => {
+ const {
+ data: createdFeed,
+ response: createResponse,
+ error,
+ } = await client.POST("/feeds", {
+ body: {
+ name: "Test Feed",
+ url: "https://example.com/feed.xml",
+ enabled: true,
+ },
+ });
+
+ if (error) {
+ throw error;
+ }
+
+ expect(createResponse.status).toBe(201);
+ expect(createdFeed).toBeDefined();
+ expect(createdFeed?.id).toBeDefined();
+ expect(createdFeed?.importTags).toBe(false);
+ expect(createdFeed?.lastFetchedStatus).toBe("pending");
+ expect(createdFeed?.lastFetchedAt).toBeNull();
+
+ const { data: retrievedFeed, response: getResponse } = await client.GET(
+ "/feeds/{feedId}",
+ {
+ params: {
+ path: {
+ feedId: createdFeed!.id,
+ },
+ },
+ },
+ );
+
+ expect(getResponse.status).toBe(200);
+ expect(retrievedFeed?.id).toBe(createdFeed!.id);
+ expect(retrievedFeed?.name).toBe("Test Feed");
+
+ const { data: updatedFeed, response: updateResponse } = await client.PATCH(
+ "/feeds/{feedId}",
+ {
+ params: {
+ path: {
+ feedId: createdFeed!.id,
+ },
+ },
+ body: {
+ name: "Updated Feed",
+ enabled: false,
+ importTags: true,
+ },
+ },
+ );
+
+ expect(updateResponse.status).toBe(200);
+ expect(updatedFeed?.name).toBe("Updated Feed");
+ expect(updatedFeed?.enabled).toBe(false);
+ expect(updatedFeed?.importTags).toBe(true);
+
+ const { response: deleteResponse } = await client.DELETE(
+ "/feeds/{feedId}",
+ {
+ params: {
+ path: {
+ feedId: createdFeed!.id,
+ },
+ },
+ },
+ );
+
+ expect(deleteResponse.status).toBe(204);
+
+ const { response: getDeletedResponse } = await client.GET(
+ "/feeds/{feedId}",
+ {
+ params: {
+ path: {
+ feedId: createdFeed!.id,
+ },
+ },
+ },
+ );
+
+ expect(getDeletedResponse.status).toBe(404);
+ });
+
+ it("should trigger an immediate fetch with POST and import feed entries", async () => {
+ const { data: createdFeed, error: createError } = await client.POST(
+ "/feeds",
+ {
+ body: {
+ name: "Fetched Feed",
+ url: "http://nginx:80/feed.xml",
+ enabled: true,
+ },
+ },
+ );
+
+ if (createError) {
+ throw createError;
+ }
+
+ const { response: fetchResponse } = await client.POST(
+ "/feeds/{feedId}/fetch",
+ {
+ params: {
+ path: {
+ feedId: createdFeed!.id,
+ },
+ },
+ },
+ );
+
+ expect(fetchResponse.status).toBe(204);
+
+ await waitUntil(async () => {
+ const { data: feed } = await client.GET("/feeds/{feedId}", {
+ params: {
+ path: {
+ feedId: createdFeed!.id,
+ },
+ },
+ });
+
+ return feed?.lastFetchedStatus === "success";
+ }, "feed fetch completes");
+
+ const { data: fetchedFeed, response: getFeedResponse } = await client.GET(
+ "/feeds/{feedId}",
+ {
+ params: {
+ path: {
+ feedId: createdFeed!.id,
+ },
+ },
+ },
+ );
+
+ expect(getFeedResponse.status).toBe(200);
+ expect(fetchedFeed?.lastFetchedStatus).toBe("success");
+ expect(fetchedFeed?.lastFetchedAt).toBeTruthy();
+
+ const { data: bookmarks, response: bookmarksResponse } = await client.GET(
+ "/bookmarks",
+ {
+ params: {
+ query: {
+ archived: false,
+ },
+ },
+ },
+ );
+
+ expect(bookmarksResponse.status).toBe(200);
+ expect(bookmarks?.bookmarks).toHaveLength(2);
+
+ const titles = bookmarks!.bookmarks.map((bookmark) => bookmark.title);
+ expect(titles).toContain("First Test Article");
+ expect(titles).toContain("Second Test Article");
+
+ const urls = bookmarks!.bookmarks.map((bookmark) => {
+ assert(bookmark.content.type === "link");
+ return bookmark.content.url;
+ });
+ expect(urls).toContain("http://nginx:80/hello.html");
+ expect(urls).toContain("http://nginx:80/hello.html?article=2");
+ });
+});
diff --git a/packages/open-api/karakeep-openapi-spec.json b/packages/open-api/karakeep-openapi-spec.json
index c121fdef..b4865f9a 100644
--- a/packages/open-api/karakeep-openapi-spec.json
+++ b/packages/open-api/karakeep-openapi-spec.json
@@ -4971,7 +4971,7 @@
}
},
"/feeds/{feedId}/fetch": {
- "put": {
+ "post": {
"operationId": "fetchFeedNow",
"description": "Trigger an immediate fetch of the RSS feed. The fetch is enqueued and processed asynchronously.",
"summary": "Trigger a feed fetch",
diff --git a/packages/open-api/lib/feeds.ts b/packages/open-api/lib/feeds.ts
index ef4e04e0..8a41ed1c 100644
--- a/packages/open-api/lib/feeds.ts
+++ b/packages/open-api/lib/feeds.ts
@@ -207,7 +207,7 @@ registry.registerPath({
registry.registerPath({
operationId: "fetchFeedNow",
- method: "put",
+ method: "post",
path: "/feeds/{feedId}/fetch",
description:
"Trigger an immediate fetch of the RSS feed. The fetch is enqueued and processed asynchronously.",
diff --git a/packages/sdk/src/karakeep-api.d.ts b/packages/sdk/src/karakeep-api.d.ts
index 855a0c8f..bf0d2a5e 100644
--- a/packages/sdk/src/karakeep-api.d.ts
+++ b/packages/sdk/src/karakeep-api.d.ts
@@ -732,12 +732,12 @@ export interface paths {
cookie?: never;
};
get?: never;
+ put?: never;
/**
* Trigger a feed fetch
* @description Trigger an immediate fetch of the RSS feed. The fetch is enqueued and processed asynchronously.
*/
- put: operations["fetchFeedNow"];
- post?: never;
+ post: operations["fetchFeedNow"];
delete?: never;
options?: never;
head?: never;