@@ -3,7 +3,11 @@ import { HttpStatus } from '@nestjs/common';
33import { Task } from 'omniboxd/tasks/tasks.entity' ;
44import { TaskCallbackDto } from 'omniboxd/wizard/dto/task-callback.dto' ;
55import { isEmpty } from 'omniboxd/utils/is-empty' ;
6- import { TaskDto , TaskMetaDto } from 'omniboxd/tasks/dto/task.dto' ;
6+ import {
7+ InternalTaskDto ,
8+ TaskDto ,
9+ TaskMetaDto ,
10+ } from 'omniboxd/tasks/dto/task.dto' ;
711
812/**
913 * Mock wizard worker that simulates the wizard worker service behavior
@@ -198,7 +202,10 @@ class MockWizardWorker {
198202 * Simulates upsert_index task processing
199203 */
200204 private processUpsertIndexTask ( task : TaskDto ) : { output : any } {
201- console . log ( { taskId : task . id , function : 'upsertIndex' } ) ;
205+ expect ( task . input ) . toHaveProperty ( 'meta_info' ) ;
206+ expect ( task . input . meta_info ) . toHaveProperty ( 'resource_id' ) ;
207+ expect ( task . input . meta_info ) . toHaveProperty ( 'user_id' ) ;
208+ expect ( task . input . meta_info ) . toHaveProperty ( 'parent_id' ) ;
202209 return {
203210 output : {
204211 indexed : true ,
@@ -290,6 +297,70 @@ describe('Task Pipeline (e2e)', () => {
290297 } ) ;
291298
292299 describe ( 'Basic Task Processing' , ( ) => {
300+ it ( 'create resource trigger upsertIndex' , async ( ) => {
301+ mockWorker . startPolling ( ) ;
302+
303+ const createResponse = (
304+ await client
305+ . post ( `/api/v1/namespaces/${ client . namespace . id } /resources` )
306+ . send ( {
307+ name : 'Test Document' ,
308+ content : 'Sample content for the test document.' ,
309+ parentId : client . namespace . root_resource_id ,
310+ namespaceId : client . namespace . id ,
311+ resourceType : 'doc' ,
312+ } )
313+ ) . body ;
314+
315+ const taskMetas : TaskMetaDto [ ] = (
316+ await client . get ( `/api/v1/namespaces/${ client . namespace . id } /tasks` )
317+ ) . body ;
318+
319+ const upsertTaskMeta = taskMetas . find (
320+ ( t : TaskMetaDto ) =>
321+ t . function === 'upsert_index' &&
322+ t . attrs ?. resource_id === createResponse . id ,
323+ ) ;
324+
325+ expect ( upsertTaskMeta ) . toBeDefined ( ) ;
326+ const upsertTask : InternalTaskDto = (
327+ await client . get (
328+ `/api/v1/namespaces/${ client . namespace . id } /tasks/${ upsertTaskMeta ?. id } ` ,
329+ )
330+ ) . body ;
331+ expect ( upsertTask ) . toBeDefined ( ) ;
332+ expect ( upsertTask . input . meta_info . parent_id ) . toBeDefined ( ) ;
333+ expect ( upsertTask . input . meta_info . parent_id ) . not . toBeNull ( ) ;
334+
335+ const patchResponse = await client
336+ . patch (
337+ `/api/v1/namespaces/${ client . namespace . id } /resources/${ createResponse . id } ` ,
338+ )
339+ . send ( {
340+ namespaceId : client . namespace . id ,
341+ content : 'Updated content for the test document.' ,
342+ } ) ;
343+ expect ( patchResponse . status ) . toBe ( 200 ) ;
344+ const patchTaskMetas : TaskMetaDto [ ] = (
345+ await client . get ( `/api/v1/namespaces/${ client . namespace . id } /tasks` )
346+ ) . body ;
347+ const patchUpsertTaskMeta = patchTaskMetas . find (
348+ ( t : TaskMetaDto ) =>
349+ t . function === 'upsert_index' &&
350+ t . attrs ?. resource_id === createResponse . id &&
351+ t . id !== upsertTaskMeta ?. id ,
352+ ) ;
353+ expect ( patchUpsertTaskMeta ) . toBeDefined ( ) ;
354+ const patchUpsertTask : InternalTaskDto = (
355+ await client . get (
356+ `/api/v1/namespaces/${ client . namespace . id } /tasks/${ patchUpsertTaskMeta ?. id } ` ,
357+ )
358+ ) . body ;
359+ expect ( patchUpsertTask ) . toBeDefined ( ) ;
360+ expect ( patchUpsertTask . input . meta_info . parent_id ) . toBeDefined ( ) ;
361+ expect ( patchUpsertTask . input . meta_info . parent_id ) . not . toBeNull ( ) ;
362+ } ) ;
363+
293364 it ( 'should process a collect task end-to-end' , async ( ) => {
294365 // Start the mock worker
295366 mockWorker . startPolling ( ) ;
@@ -343,6 +414,19 @@ describe('Task Pipeline (e2e)', () => {
343414 expect ( resourceResponse . status ) . toBe ( 200 ) ;
344415 expect ( resourceResponse . body . id ) . toBe ( resourceId ) ;
345416 expect ( resourceResponse . body . content ) . toContain ( 'Test Page Title' ) ;
417+
418+ const taskMetas : TaskMetaDto [ ] = (
419+ await client . get ( `/api/v1/namespaces/${ client . namespace . id } /tasks` )
420+ ) . body ;
421+ const upsertTaskMeta = taskMetas . find (
422+ ( t : TaskMetaDto ) => t . function === 'upsert_index' ,
423+ ) ;
424+ const upsertTask : InternalTaskDto = (
425+ await client . get (
426+ `/api/v1/namespaces/${ client . namespace . id } /tasks/${ upsertTaskMeta ?. id } ` ,
427+ )
428+ ) . body ;
429+ expect ( upsertTask ) . toBeDefined ( ) ;
346430 } ) ;
347431
348432 it ( 'should handle task exceptions properly' , async ( ) => {
0 commit comments