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
44 changes: 44 additions & 0 deletions src/app/api/label-mapping/label-mapping.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const mockLabelFindFirst = jest.fn()
const mockLabelDelete = jest.fn()

jest.mock('@/lib/db', () => ({
__esModule: true,
default: {
getInstance: () => ({
label: { findFirst: mockLabelFindFirst, delete: mockLabelDelete },
}),
},
}))

jest.mock('@/utils/CopilotAPI', () => ({ CopilotAPI: jest.fn() }))

import { LabelMappingService } from '@api/label-mapping/label-mapping.service'
import User from '@api/core/models/User.model'
import { UserRole } from '@api/core/types/user'

const user = {
workspaceId: 'ws-1',
role: UserRole.IU,
internalUserId: 'iu-1',
token: 'token',
} as unknown as User

describe('LabelMappingService#deleteLabel', () => {
beforeEach(() => jest.clearAllMocks())

it('deletes the matching label row', async () => {
mockLabelFindFirst.mockResolvedValue({ id: 'label-1' })

await new LabelMappingService(user).deleteLabel('ASS10-009')

expect(mockLabelDelete).toHaveBeenCalledWith({ where: { id: 'label-1' } })
})

it('no-ops when the label row is already gone', async () => {
mockLabelFindFirst.mockResolvedValue(null)

await new LabelMappingService(user).deleteLabel('ASS10-009')

expect(mockLabelDelete).not.toHaveBeenCalled()
})
})
3 changes: 2 additions & 1 deletion src/app/api/label-mapping/label-mapping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ export class LabelMappingService extends BaseService {
label,
},
})
if (!currentLabel) return
await this.db.label.delete({
where: {
id: currentLabel?.id,
id: currentLabel.id,
},
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/instrumentation-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import * as Sentry from '@sentry/nextjs'

import { browserSentryIgnoredErrors } from '@/utils/sentryIgnoredErrors'

const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN || process.env.SENTRY_DSN
const vercelEnv = process.env.NEXT_PUBLIC_VERCEL_ENV
const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === 'production'
Expand Down Expand Up @@ -33,7 +35,7 @@ if (dsn) {
// }),
],

ignoreErrors: [/fetch failed/i, /failed to fetch/i],
ignoreErrors: browserSentryIgnoredErrors,

beforeSend(event) {
if (!isProd && event.type === undefined) {
Expand Down
30 changes: 30 additions & 0 deletions src/utils/sentryIgnoredErrors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { isIgnoredBrowserSentryError } from './sentryIgnoredErrors'

describe('isIgnoredBrowserSentryError', () => {
it('ignores browser history pushState instrumentation noise', () => {
expect(isIgnoredBrowserSentryError('Error: NS Pushstate prevention')).toBe(true)
expect(isIgnoredBrowserSentryError('ns pushstate prevention')).toBe(true)
})

it('ignores cross-origin history replaceState security errors', () => {
expect(
isIgnoredBrowserSentryError(
'SecurityError: Blocked attempt to use history.replaceState() to change session history URL from https://help.kudzu.digital/login?step=signIn to https://auth.copilot.app/auth/google/callback.',
),
).toBe(true)
expect(
isIgnoredBrowserSentryError(
'SecurityError: Blocked attempt to use history.pushState() to change session history URL from https://portal.example.com/login to https://auth.copilot.app/auth/google/callback.',
),
).toBe(true)
})

it('keeps ignoring generic browser fetch failures', () => {
expect(isIgnoredBrowserSentryError('TypeError: Failed to fetch')).toBe(true)
expect(isIgnoredBrowserSentryError('Error: fetch failed')).toBe(true)
})

it('does not ignore unrelated application errors', () => {
expect(isIgnoredBrowserSentryError('Error: Unable to create task')).toBe(false)
})
})
10 changes: 10 additions & 0 deletions src/utils/sentryIgnoredErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const browserSentryIgnoredErrors = [
/fetch failed/i,
/failed to fetch/i,
/NS Pushstate prevention/i,
/Blocked attempt to use history\.(replace|push)State\(\)/i,
]

export function isIgnoredBrowserSentryError(errorMessage: string) {
return browserSentryIgnoredErrors.some((ignoredError) => ignoredError.test(errorMessage))
}
Loading