Skip to content
Draft
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
5 changes: 4 additions & 1 deletion src/app/api/activity-logs/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,3 +19,5 @@ export const GET = async (req: NextRequest, props: IdParams) => {

return NextResponse.json({ activity })
}

export const GET = withErrorHandler(getActivityLog)
35 changes: 35 additions & 0 deletions src/app/api/tests/routes/activity-log-route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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('@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(() => {
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()
})
})
Loading