|
| 1 | +import { describe, expect, test } from 'bun:test'; |
| 2 | +import type { AnyRobotsJob } from './_shared.ts'; |
| 3 | +import { assertJobCompleted } from './_shared.ts'; |
| 4 | + |
| 5 | +const baseJob = { |
| 6 | + id: 'rjob_xyz', |
| 7 | + workflow: 'summarize', |
| 8 | + created_at: 0, |
| 9 | + updated_at: 0, |
| 10 | + units_consumed: 0, |
| 11 | + parameters: { asset_id: 'asset_x' }, |
| 12 | +} as unknown as AnyRobotsJob; |
| 13 | + |
| 14 | +describe('assertJobCompleted', () => { |
| 15 | + test('returns silently on status=completed', () => { |
| 16 | + expect(() => |
| 17 | + assertJobCompleted({ ...baseJob, status: 'completed' } as AnyRobotsJob), |
| 18 | + ).not.toThrow(); |
| 19 | + }); |
| 20 | + |
| 21 | + test('throws on status=errored', () => { |
| 22 | + expect(() => |
| 23 | + assertJobCompleted({ ...baseJob, status: 'errored' } as AnyRobotsJob), |
| 24 | + ).toThrow(/errored/i); |
| 25 | + }); |
| 26 | + |
| 27 | + test('throws on status=cancelled', () => { |
| 28 | + expect(() => |
| 29 | + assertJobCompleted({ ...baseJob, status: 'cancelled' } as AnyRobotsJob), |
| 30 | + ).toThrow(/cancelled/i); |
| 31 | + }); |
| 32 | + |
| 33 | + test('includes job.errors details when present', () => { |
| 34 | + const job = { |
| 35 | + ...baseJob, |
| 36 | + status: 'errored', |
| 37 | + errors: [ |
| 38 | + { type: 'processing_error', message: 'asset not ready' }, |
| 39 | + { type: 'timeout', message: 'took too long' }, |
| 40 | + ], |
| 41 | + } as unknown as AnyRobotsJob; |
| 42 | + expect(() => assertJobCompleted(job)).toThrow( |
| 43 | + /processing_error: asset not ready.*timeout: took too long/, |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + test('includes job id in the error message', () => { |
| 48 | + expect(() => |
| 49 | + assertJobCompleted({ |
| 50 | + ...baseJob, |
| 51 | + id: 'rjob_abc123', |
| 52 | + status: 'errored', |
| 53 | + } as AnyRobotsJob), |
| 54 | + ).toThrow(/rjob_abc123/); |
| 55 | + }); |
| 56 | +}); |
0 commit comments