Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/app/api/webhooks/[id]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { withAuth } from '@/lib/api/middleware/auth.js';
/** Delete a webhook by ID */
export const DELETE = withAuth(async (event) => {
const { supabase, user } = event.locals;
const { id } = params;
const { id } = (await event.context?.params) || {};

const { error } = await supabase
.from('webhooks')
Expand Down
40 changes: 40 additions & 0 deletions src/app/api/webhooks/[id]/route.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it, vi } from 'vitest';

const mocks = vi.hoisted(() => ({
deleteMock: vi.fn(),
eqMock: vi.fn()
}));

vi.mock('@/lib/api/middleware/auth.js', () => ({
withAuth: (handler) => (request, context) =>
handler({
request,
locals: {
supabase: {
from: vi.fn(() => ({
delete: mocks.deleteMock
}))
},
user: { id: 'auth-user-id' }
},
context
})
}));

describe('DELETE /api/webhooks/[id]', () => {
it('reads the webhook id from route context params', async () => {
mocks.eqMock.mockReturnThis();
mocks.deleteMock.mockReturnValue({ eq: mocks.eqMock });

const { DELETE } = await import('./route.js');
const response = await DELETE(new Request('https://qrypt.chat/api/webhooks/hook-1'), {
params: Promise.resolve({ id: 'hook-1' })
});
const body = await response.json();

expect(response.status).toBe(200);
expect(body).toEqual({ success: true });
expect(mocks.eqMock).toHaveBeenCalledWith('id', 'hook-1');
expect(mocks.eqMock).toHaveBeenCalledWith('user_id', 'auth-user-id');
});
});
Loading