T-10: tests
This commit is contained in:
parent
b098bda462
commit
8888134503
1 changed files with 22 additions and 16 deletions
|
|
@ -96,21 +96,20 @@ describe('createJobHandler', () => {
|
|||
});
|
||||
|
||||
it('should support async operations', async () => {
|
||||
let resolveAsyncWork!: () => void;
|
||||
let asyncWorkCompleted = false;
|
||||
// Gate created before the wrapper runs, so the test does not assume synchronous invocation.
|
||||
let releaseAsyncWork!: () => void;
|
||||
const asyncWorkGate = new Promise<void>(resolve => {
|
||||
releaseAsyncWork = resolve;
|
||||
});
|
||||
let callbackFinished = false;
|
||||
|
||||
const handler = createJobHandler<TestPayload, TestResult>(async job => {
|
||||
await new Promise<void>(resolve => {
|
||||
resolveAsyncWork = () => {
|
||||
asyncWorkCompleted = true;
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
await asyncWorkGate;
|
||||
callbackFinished = true;
|
||||
return {
|
||||
success: true,
|
||||
processedBy: job.data.userId,
|
||||
timestamp: new Date(),
|
||||
timestamp: new Date(0),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -127,15 +126,22 @@ describe('createJobHandler', () => {
|
|||
updateProgress: async () => {},
|
||||
};
|
||||
|
||||
const resultPromise = handler(mockJob as any);
|
||||
expect(asyncWorkCompleted).toBe(false);
|
||||
let wrapperSettled = false;
|
||||
const resultPromise = handler(mockJob as any).finally(() => {
|
||||
wrapperSettled = true;
|
||||
});
|
||||
|
||||
resolveAsyncWork();
|
||||
// Drain microtasks: the wrapper must still be waiting on the callback.
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
expect(wrapperSettled).toBe(false);
|
||||
expect(callbackFinished).toBe(false);
|
||||
|
||||
releaseAsyncWork();
|
||||
const result = await resultPromise;
|
||||
|
||||
expect(asyncWorkCompleted).toBe(true);
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.processedBy).toBe('user-789');
|
||||
expect(callbackFinished).toBe(true);
|
||||
expect(result).toEqual({ success: true, processedBy: 'user-789', timestamp: new Date(0) });
|
||||
});
|
||||
|
||||
it('should maintain type safety for complex payloads', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue