From 8bdca44d84f9d81d884b1aa268c39bf3ca4e3800 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 12 Jul 2026 18:04:03 +0000 Subject: [PATCH 1/4] Handle missing-token activity log requests Co-authored-by: Neil Raina --- src/app/api/activity-logs/[id]/route.ts | 5 +++- .../tests/routes/activity-log-route.test.ts | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/app/api/tests/routes/activity-log-route.test.ts diff --git a/src/app/api/activity-logs/[id]/route.ts b/src/app/api/activity-logs/[id]/route.ts index a6d506f7a..921f6f04f 100644 --- a/src/app/api/activity-logs/[id]/route.ts +++ b/src/app/api/activity-logs/[id]/route.ts @@ -3,8 +3,9 @@ import authenticate from '@api/core/utils/authenticate' import { ActivityLogService } from '@api/activity-logs/services/activity-log.service' import { IdParams } from '@api/core/types/api' import { unstable_noStore as noStore } from 'next/cache' +import { withErrorHandler } from '@api/core/utils/withErrorHandler' -export const GET = async (req: NextRequest, props: IdParams) => { +const getActivityLog = async (req: NextRequest, props: IdParams) => { const params = await props.params const { id } = params @@ -18,3 +19,5 @@ export const GET = async (req: NextRequest, props: IdParams) => { return NextResponse.json({ activity }) } + +export const GET = withErrorHandler(getActivityLog) diff --git a/src/app/api/tests/routes/activity-log-route.test.ts b/src/app/api/tests/routes/activity-log-route.test.ts new file mode 100644 index 000000000..21949e8b0 --- /dev/null +++ b/src/app/api/tests/routes/activity-log-route.test.ts @@ -0,0 +1,24 @@ +import { GET } from '@api/activity-logs/[id]/route' +import { buildNextRequest } from '@api/tests/__utils__/testUtils' +import httpStatus from 'http-status' + +describe('activity log route', () => { + beforeEach(() => { + jest.clearAllMocks() + jest.spyOn(console, 'error').mockImplementation() + }) + + afterEach(() => { + jest.restoreAllMocks() + }) + + it('returns a quiet 401 response when token is missing', async () => { + const req = buildNextRequest('/api/activity-logs/activity-id') + const response = await GET(req, { params: Promise.resolve({ id: 'activity-id' }) }) + const body = await response.json() + + expect(response.status).toBe(httpStatus.UNAUTHORIZED) + expect(body.error).toBe('Please provide a valid token') + expect(console.error).not.toHaveBeenCalled() + }) +}) From 9549baeabe12879d1b16410cb99b9021b742cb6a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 12 Jul 2026 18:04:36 +0000 Subject: [PATCH 2/4] Mock Copilot API in activity log route test Co-authored-by: Neil Raina --- src/app/api/tests/routes/activity-log-route.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/api/tests/routes/activity-log-route.test.ts b/src/app/api/tests/routes/activity-log-route.test.ts index 21949e8b0..fe7254681 100644 --- a/src/app/api/tests/routes/activity-log-route.test.ts +++ b/src/app/api/tests/routes/activity-log-route.test.ts @@ -1,7 +1,12 @@ +import { mockCopilotAPI } from '@api/tests/__mocks__/CopilotAPI.mock' import { GET } from '@api/activity-logs/[id]/route' import { buildNextRequest } from '@api/tests/__utils__/testUtils' import httpStatus from 'http-status' +jest.mock('@/utils/CopilotAPI', () => ({ + CopilotAPI: jest.fn().mockImplementation((token: string) => mockCopilotAPI(token)), +})) + describe('activity log route', () => { beforeEach(() => { jest.clearAllMocks() From e741f0643c07ed2ccc1ad56477946402c6e4c9b9 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 12 Jul 2026 18:05:04 +0000 Subject: [PATCH 3/4] Isolate activity log route regression test Co-authored-by: Neil Raina --- .../api/tests/routes/activity-log-route.test.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/app/api/tests/routes/activity-log-route.test.ts b/src/app/api/tests/routes/activity-log-route.test.ts index fe7254681..9a3a9c553 100644 --- a/src/app/api/tests/routes/activity-log-route.test.ts +++ b/src/app/api/tests/routes/activity-log-route.test.ts @@ -1,16 +1,24 @@ -import { mockCopilotAPI } from '@api/tests/__mocks__/CopilotAPI.mock' import { GET } from '@api/activity-logs/[id]/route' +import APIError from '@api/core/exceptions/api' +import authenticate from '@api/core/utils/authenticate' import { buildNextRequest } from '@api/tests/__utils__/testUtils' import httpStatus from 'http-status' -jest.mock('@/utils/CopilotAPI', () => ({ - CopilotAPI: jest.fn().mockImplementation((token: string) => mockCopilotAPI(token)), +jest.mock('@api/activity-logs/services/activity-log.service', () => ({ + ActivityLogService: jest.fn().mockImplementation(() => ({ + get: jest.fn(), + })), })) +jest.mock('@api/core/utils/authenticate', () => jest.fn()) + describe('activity log route', () => { beforeEach(() => { jest.clearAllMocks() jest.spyOn(console, 'error').mockImplementation() + jest + .mocked(authenticate) + .mockRejectedValue(new APIError(httpStatus.UNAUTHORIZED, 'Please provide a valid token')) }) afterEach(() => { From b59f8d42fdc4c8f6e48d7948497c34c12c6c9e20 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 12 Jul 2026 18:05:59 +0000 Subject: [PATCH 4/4] Format activity log route test Co-authored-by: Neil Raina --- src/app/api/tests/routes/activity-log-route.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/api/tests/routes/activity-log-route.test.ts b/src/app/api/tests/routes/activity-log-route.test.ts index 9a3a9c553..5f5ec1403 100644 --- a/src/app/api/tests/routes/activity-log-route.test.ts +++ b/src/app/api/tests/routes/activity-log-route.test.ts @@ -16,9 +16,7 @@ describe('activity log route', () => { beforeEach(() => { jest.clearAllMocks() jest.spyOn(console, 'error').mockImplementation() - jest - .mocked(authenticate) - .mockRejectedValue(new APIError(httpStatus.UNAUTHORIZED, 'Please provide a valid token')) + jest.mocked(authenticate).mockRejectedValue(new APIError(httpStatus.UNAUTHORIZED, 'Please provide a valid token')) }) afterEach(() => {