aboutsummaryrefslogtreecommitdiffstats
path: root/frontend-vanilla/src
diff options
context:
space:
mode:
Diffstat (limited to 'frontend-vanilla/src')
-rw-r--r--frontend-vanilla/src/main.test.ts8
-rw-r--r--frontend-vanilla/src/main.ts10
2 files changed, 16 insertions, 2 deletions
diff --git a/frontend-vanilla/src/main.test.ts b/frontend-vanilla/src/main.test.ts
index eb9e615..40acd83 100644
--- a/frontend-vanilla/src/main.test.ts
+++ b/frontend-vanilla/src/main.test.ts
@@ -371,14 +371,20 @@ describe('main application logic', () => {
expect(apiFetch).toHaveBeenCalledWith('/api/feed/123', expect.objectContaining({ method: 'DELETE' }));
});
- it('updateFeed should call API', async () => {
+ it('updateFeed should call API with merged data', async () => {
+ store.setFeeds([{ _id: 123, title: 'Test Feed', url: 'http://example.com' } as any]);
vi.mocked(apiFetch).mockResolvedValueOnce({ ok: true } as Response);
const { updateFeed } = await import('./main');
await updateFeed(123, { category: 'New Tag' });
+
expect(apiFetch).toHaveBeenCalledWith('/api/feed', expect.objectContaining({
method: 'PUT',
body: expect.stringContaining('"category":"New Tag"')
}));
+ // Should verify it merged the title
+ expect(apiFetch).toHaveBeenCalledWith('/api/feed', expect.objectContaining({
+ body: expect.stringContaining('"title":"Test Feed"')
+ }));
});
it('renderSettings should show manage feeds section', () => {
diff --git a/frontend-vanilla/src/main.ts b/frontend-vanilla/src/main.ts
index b826760..418b9be 100644
--- a/frontend-vanilla/src/main.ts
+++ b/frontend-vanilla/src/main.ts
@@ -552,11 +552,19 @@ export async function deleteFeed(id: number): Promise<boolean> {
}
export async function updateFeed(id: number, updates: Partial<Feed>): Promise<boolean> {
+ const existing = store.feeds.find(f => f._id === id);
+ if (!existing) {
+ console.error('Feed not found in store', id);
+ return false;
+ }
+
+ const payload = { ...existing, ...updates };
+
try {
const res = await apiFetch('/api/feed', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ ...updates, _id: id })
+ body: JSON.stringify(payload)
});
return res.ok;
} catch (err) {