|
1 | 1 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { OracleFusionHcmOperationError } from '@/lib/internal/oracle-fusion-hcm/errors' |
2 | 3 | import { selectorManifest } from '@/lib/selectors/manifest' |
3 | 4 | import { |
4 | 5 | SelectorConnectionUnavailableError, |
@@ -116,6 +117,7 @@ describe('Oracle Fusion HCM selectors', () => { |
116 | 117 | absences: [ |
117 | 118 | { |
118 | 119 | absenceId: '3', |
| 120 | + personId: '1', |
119 | 121 | absenceType: 'Vacation', |
120 | 122 | startDate: '2026-01-01', |
121 | 123 | endDate: '2026-01-02', |
@@ -311,6 +313,76 @@ describe('Oracle Fusion HCM selectors', () => { |
311 | 313 | ).rejects.toBeInstanceOf(SelectorContextUnavailableError) |
312 | 314 | }) |
313 | 315 |
|
| 316 | + it.each([undefined, '2'])('rejects a listed absence with personId %s', async (personId) => { |
| 317 | + mocks.listAbsences.mockResolvedValueOnce({ |
| 318 | + success: true, |
| 319 | + output: { |
| 320 | + absences: [{ absenceId: '3', personId, absenceType: 'Vacation' }], |
| 321 | + count: 1, |
| 322 | + hasMore: false, |
| 323 | + limit: 50, |
| 324 | + offset: 0, |
| 325 | + }, |
| 326 | + }) |
| 327 | + const attachment = oracleFusionHcmSelectorAttachments['oracle_fusion_hcm.absences'] |
| 328 | + const input = args({ |
| 329 | + selectorKey: 'oracle_fusion_hcm.absences', |
| 330 | + context: { |
| 331 | + domain: 'https://acme.fa.ocs.oraclecloud.com', |
| 332 | + username: 'reader', |
| 333 | + password: 'secret', |
| 334 | + personId: '1', |
| 335 | + }, |
| 336 | + }) |
| 337 | + |
| 338 | + await expect( |
| 339 | + attachment.execute(input, await prepare(attachment, input)) |
| 340 | + ).rejects.toBeInstanceOf(SelectorContextUnavailableError) |
| 341 | + }) |
| 342 | + |
| 343 | + it('returns a missing detail when Oracle reports 404', async () => { |
| 344 | + const context = { |
| 345 | + domain: 'https://acme.fa.ocs.oraclecloud.com', |
| 346 | + username: 'reader', |
| 347 | + password: 'secret', |
| 348 | + personId: '1', |
| 349 | + } |
| 350 | + for (const [key, id, mock] of [ |
| 351 | + ['workers', '1', mocks.getWorker], |
| 352 | + ['assignments', '2', mocks.getAssignment], |
| 353 | + ['absences', '3', mocks.getAbsence], |
| 354 | + ] as const) { |
| 355 | + mock.mockRejectedValueOnce(new OracleFusionHcmOperationError('not found', 404)) |
| 356 | + const attachment = oracleFusionHcmSelectorAttachments[`oracle_fusion_hcm.${key}`] |
| 357 | + const input = args({ |
| 358 | + selectorKey: `oracle_fusion_hcm.${key}`, |
| 359 | + context, |
| 360 | + request: { kind: 'detail', id }, |
| 361 | + }) |
| 362 | + |
| 363 | + await expect(attachment.execute(input, await prepare(attachment, input))).resolves.toEqual({ |
| 364 | + kind: 'detail', |
| 365 | + item: null, |
| 366 | + }) |
| 367 | + } |
| 368 | + }) |
| 369 | + |
| 370 | + it('keeps malformed detail requests and list 404s as context errors', async () => { |
| 371 | + const attachment = oracleFusionHcmSelectorAttachments['oracle_fusion_hcm.workers'] |
| 372 | + for (const [status, request] of [ |
| 373 | + [400, { kind: 'detail', id: '1' }], |
| 374 | + [404, { kind: 'list' }], |
| 375 | + ] as const) { |
| 376 | + const mock = request.kind === 'detail' ? mocks.getWorker : mocks.listWorkers |
| 377 | + mock.mockRejectedValueOnce(new OracleFusionHcmOperationError('invalid context', status)) |
| 378 | + const input = args({ request }) |
| 379 | + |
| 380 | + await expect( |
| 381 | + attachment.execute(input, await prepare(attachment, input)) |
| 382 | + ).rejects.toBeInstanceOf(SelectorContextUnavailableError) |
| 383 | + } |
| 384 | + }) |
| 385 | + |
314 | 386 | it.each(['../workers/1', '1,absenceTypeId=2', '0', '9223372036854775808'])( |
315 | 387 | 'rejects invalid dependent person ID %s before provider preparation', |
316 | 388 | async (invalidId) => { |
|
0 commit comments