|
1 | 1 | /** @vitest-environment node */ |
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
3 | | -import { GoogleApiError } from '@/connectors/google-workspace/api-errors' |
| 3 | +import { GoogleApiError, readGoogleApiError } from '@/connectors/google-workspace/api-errors' |
4 | 4 | import { |
5 | 5 | getGoogleWorkspaceDocument, |
6 | 6 | InvalidGoogleWorkspaceCursor, |
@@ -501,26 +501,37 @@ describe('Google Workspace per-user central crawl', () => { |
501 | 501 | expect((await list(context(), undefined, CONFIG, 'google_calendar')).documents).toHaveLength(1) |
502 | 502 | }) |
503 | 503 |
|
504 | | - it.each([{ reasons: [] }, { reasons: ['forbidden'] }])( |
505 | | - 'isolates Calendar list access failures without claiming a disabled service (%j)', |
506 | | - async ({ reasons }) => { |
507 | | - listUserDocuments.mockRejectedValueOnce( |
508 | | - new GoogleApiError('calendar.events.list', 403, reasons) |
509 | | - ) |
510 | | - const first = await list(context(), undefined, CONFIG, 'google_calendar') |
511 | | - expect(first.listingFailures?.samples[0]).toEqual({ |
512 | | - scope: 'alice@corp.com', |
513 | | - operation: 'calendar.events.list', |
514 | | - status: 403, |
515 | | - reasons, |
516 | | - }) |
517 | | - const second = await list(context(), first.nextCursor, CONFIG, 'google_calendar') |
518 | | - expect(second.documents[0].acl).toEqual(['u:bob@corp.com']) |
519 | | - expect(second.reconciliationSafe).toBe(false) |
| 504 | + it('isolates explicit Calendar list access failures without claiming a disabled service', async () => { |
| 505 | + listUserDocuments.mockRejectedValueOnce( |
| 506 | + new GoogleApiError('calendar.events.list', 403, ['forbidden']) |
| 507 | + ) |
| 508 | + const first = await list(context(), undefined, CONFIG, 'google_calendar') |
| 509 | + expect(first.listingFailures?.samples[0]).toEqual({ |
| 510 | + scope: 'alice@corp.com', |
| 511 | + operation: 'calendar.events.list', |
| 512 | + status: 403, |
| 513 | + reasons: ['forbidden'], |
| 514 | + }) |
| 515 | + const second = await list(context(), first.nextCursor, CONFIG, 'google_calendar') |
| 516 | + expect(second.documents[0].acl).toEqual(['u:bob@corp.com']) |
| 517 | + expect(second.reconciliationSafe).toBe(false) |
| 518 | + }) |
| 519 | + |
| 520 | + it.each([{ error: { code: 403 } }, { error: { code: 403, errors: [], details: [] } }])( |
| 521 | + 'propagates a Calendar 403 without reason codes: %j', |
| 522 | + async (body) => { |
| 523 | + const error = await readGoogleApiError(json(body, 403), 'calendar.events.list') |
| 524 | + listUserDocuments.mockRejectedValueOnce(error) |
| 525 | + const ctx: Record<string, unknown> = context() |
| 526 | + |
| 527 | + await expect(list(ctx, undefined, CONFIG, 'google_calendar')).rejects.toBe(error) |
| 528 | + expect(ctx.reconciliationUnsafe).toBeUndefined() |
| 529 | + expect(listUserDocuments).toHaveBeenCalledOnce() |
520 | 530 | } |
521 | 531 | ) |
522 | 532 |
|
523 | 533 | it.each([ |
| 534 | + [403, []], |
524 | 535 | [403, ['rateLimitExceeded']], |
525 | 536 | [403, ['userRateLimitExceeded']], |
526 | 537 | [403, ['quotaExceeded']], |
|
0 commit comments