@@ -24,6 +24,7 @@ const SOURCE_SCHEMA = 'public';
2424const SOURCE_TABLE = 'test_process_file_uploads' ;
2525const BUCKET = 'test-bucket' ;
2626const USER_ID = 'aaaaaaaa-0000-0000-0000-000000000001' ;
27+ const TEST_DB_ID = 'aaaaaaaa-0000-0000-0000-000000000099' ;
2728
2829const ENV : Record < string , string > = {
2930 PGHOST : 'localhost' ,
@@ -139,9 +140,10 @@ describe('process-image handler file mode e2e', () => {
139140 `INSERT INTO ${ OBJECT_STORE_SCHEMA } .files
140141 (id, database_id, bucket_key, key, status, etag, created_by,
141142 source_table, source_column, source_id)
142- VALUES ($1, 1 , 'default', $2 , 'pending', 'etag-origin', $3 , $4 , 'image', $5 )` ,
143+ VALUES ($1, $2 , 'default', $3 , 'pending', 'etag-origin', $4 , $5 , 'image', $6 )` ,
143144 [
144145 opts . fileId ,
146+ TEST_DB_ID ,
145147 opts . key ,
146148 USER_ID ,
147149 `${ SOURCE_SCHEMA } .${ SOURCE_TABLE } ` ,
@@ -154,23 +156,23 @@ describe('process-image handler file mode e2e', () => {
154156 await pg . query (
155157 `INSERT INTO ${ OBJECT_STORE_SCHEMA } .files
156158 (id, database_id, bucket_key, key, status, etag, created_by)
157- VALUES ($1, 1 , 'default', $2 , 'pending', 'etag-origin', $3 )` ,
158- [ opts . fileId , opts . key , USER_ID ]
159+ VALUES ($1, $2 , 'default', $3 , 'pending', 'etag-origin', $4 )` ,
160+ [ opts . fileId , TEST_DB_ID , opts . key , USER_ID ]
159161 ) ;
160162 }
161163
162164 async function callHandler ( fileId : string ) {
163165 const ctx = createMockContext ( { env : ENV } ) ;
164- return handler ( { file_id : fileId , database_id : 1 } , ctx as any ) ;
166+ return handler ( { file_id : fileId , database_id : TEST_DB_ID } , ctx as any ) ;
165167 }
166168
167- it ( 'processes an attached image into ready thumbnail and medium versions' , async ( ) => {
169+ it ( 'processes an attached image into ready with versions JSONB ' , async ( ) => {
168170 const fileId = randomUUID ( ) ;
169171 const sourceId = randomUUID ( ) ;
170172 const baseId = randomUUID ( ) ;
171- const originKey = `1 /default/${ baseId } _origin` ;
172- const thumbKey = `1 /default/${ baseId } _thumbnail` ;
173- const mediumKey = `1 /default/${ baseId } _medium` ;
173+ const originKey = `${ TEST_DB_ID } /default/${ baseId } _origin` ;
174+ const thumbKey = `${ TEST_DB_ID } /default/${ baseId } _thumbnail` ;
175+ const mediumKey = `${ TEST_DB_ID } /default/${ baseId } _medium` ;
174176 const imageBuffer = await generateTestImage ( 1600 , 900 ) ;
175177
176178 await putOriginImage ( originKey , imageBuffer ) ;
@@ -197,44 +199,33 @@ describe('process-image handler file mode e2e', () => {
197199 s3Keys . add ( thumbKey ) ;
198200 s3Keys . add ( mediumKey ) ;
199201
202+ // Only 1 row — origin with versions JSONB
200203 const files = await pg . query (
201- `SELECT key, status, source_table, source_column, source_id
204+ `SELECT key, status, versions, source_table, source_column, source_id
202205 FROM ${ OBJECT_STORE_SCHEMA } .files
203- WHERE key LIKE $1
204- ORDER BY key` ,
205- [ `1/default/${ baseId } %` ]
206+ WHERE id = $1` ,
207+ [ fileId ]
206208 ) ;
207209
208- expect ( files . rows ) . toEqual ( [
209- {
210- key : mediumKey ,
211- status : 'ready' ,
212- source_table : `${ SOURCE_SCHEMA } .${ SOURCE_TABLE } ` ,
213- source_column : 'image' ,
214- source_id : sourceId ,
215- } ,
216- {
217- key : originKey ,
218- status : 'ready' ,
219- source_table : `${ SOURCE_SCHEMA } .${ SOURCE_TABLE } ` ,
220- source_column : 'image' ,
221- source_id : sourceId ,
222- } ,
223- {
224- key : thumbKey ,
225- status : 'ready' ,
226- source_table : `${ SOURCE_SCHEMA } .${ SOURCE_TABLE } ` ,
227- source_column : 'image' ,
228- source_id : sourceId ,
229- } ,
230- ] ) ;
210+ expect ( files . rows ) . toHaveLength ( 1 ) ;
211+ const row = files . rows [ 0 ] ;
212+ expect ( row . status ) . toBe ( 'ready' ) ;
213+ expect ( row . key ) . toBe ( originKey ) ;
214+ expect ( row . source_table ) . toBe ( `${ SOURCE_SCHEMA } .${ SOURCE_TABLE } ` ) ;
215+ expect ( row . versions ) . toHaveLength ( 2 ) ;
216+ expect ( row . versions ) . toEqual (
217+ expect . arrayContaining ( [
218+ expect . objectContaining ( { key : thumbKey , mime : 'image/jpeg' , width : 150 } ) ,
219+ expect . objectContaining ( { key : mediumKey , mime : 'image/jpeg' , width : 1200 } ) ,
220+ ] )
221+ ) ;
231222
223+ // Domain table also has versions
232224 const sourceRow = await pg . query (
233225 `SELECT image FROM ${ SOURCE_SCHEMA } .${ SOURCE_TABLE } WHERE id = $1` ,
234226 [ sourceId ]
235227 ) ;
236228 const versions = sourceRow . rows [ 0 ] . image . versions ;
237-
238229 expect ( versions ) . toHaveLength ( 2 ) ;
239230 expect ( versions ) . toEqual (
240231 expect . arrayContaining ( [
@@ -243,16 +234,17 @@ describe('process-image handler file mode e2e', () => {
243234 ] )
244235 ) ;
245236
237+ // Idempotency
246238 const secondRun : any = await callHandler ( fileId ) ;
247239 expect ( secondRun ) . toEqual ( { skipped : true , reason : 'not_pending_or_locked' } ) ;
248240 } ) ;
249241
250242 it ( 'processes an unattached image without writing domain metadata' , async ( ) => {
251243 const fileId = randomUUID ( ) ;
252244 const baseId = randomUUID ( ) ;
253- const originKey = `1 /default/${ baseId } _origin` ;
254- const thumbKey = `1 /default/${ baseId } _thumbnail` ;
255- const mediumKey = `1 /default/${ baseId } _medium` ;
245+ const originKey = `${ TEST_DB_ID } /default/${ baseId } _origin` ;
246+ const thumbKey = `${ TEST_DB_ID } /default/${ baseId } _thumbnail` ;
247+ const mediumKey = `${ TEST_DB_ID } /default/${ baseId } _medium` ;
256248 const imageBuffer = await generateTestImage ( 1600 , 900 ) ;
257249
258250 await putOriginImage ( originKey , imageBuffer ) ;
@@ -266,36 +258,17 @@ describe('process-image handler file mode e2e', () => {
266258 s3Keys . add ( thumbKey ) ;
267259 s3Keys . add ( mediumKey ) ;
268260
261+ // Only 1 row with versions JSONB
269262 const files = await pg . query (
270- `SELECT key, status, source_table, source_column, source_id
263+ `SELECT key, status, versions, source_table
271264 FROM ${ OBJECT_STORE_SCHEMA } .files
272- WHERE key LIKE $1
273- ORDER BY key` ,
274- [ `1/default/${ baseId } %` ]
265+ WHERE id = $1` ,
266+ [ fileId ]
275267 ) ;
276268
277- expect ( files . rows ) . toEqual ( [
278- {
279- key : mediumKey ,
280- status : 'ready' ,
281- source_table : null ,
282- source_column : null ,
283- source_id : null ,
284- } ,
285- {
286- key : originKey ,
287- status : 'ready' ,
288- source_table : null ,
289- source_column : null ,
290- source_id : null ,
291- } ,
292- {
293- key : thumbKey ,
294- status : 'ready' ,
295- source_table : null ,
296- source_column : null ,
297- source_id : null ,
298- } ,
299- ] ) ;
269+ expect ( files . rows ) . toHaveLength ( 1 ) ;
270+ expect ( files . rows [ 0 ] . status ) . toBe ( 'ready' ) ;
271+ expect ( files . rows [ 0 ] . versions ) . toHaveLength ( 2 ) ;
272+ expect ( files . rows [ 0 ] . source_table ) . toBeNull ( ) ;
300273 } ) ;
301274} ) ;
0 commit comments