Files
product_inventory/test_output.txt
Ben Miller 243f7057b7 fix(media-manager): resolve video preview issues and stabilize tests
- Backend (MediaService):
    - Implemented robust contentUrl generation for Drive files using drive.google.com/uc pattern.
    - Added mimeType exposure to unified media state.

- Frontend (MediaManager):
    - Replaced video tag with iframe embedding the Google Drive Preview player (/preview) for reliable playback.
    - Fixed syntax error in console logging causing UI freeze.
    - Updated gallery card logic to prioritize video content URLs.

- Tests (Integration):
    - Refactored mediaManager.integration.test.ts to align with new logic.
    - Mocked DriveApp completely to support orphan adoption flows.
    - Updated file renaming expectations to support timestamped filenames.

- Documentation:
    - Updated MEMORY.md with video preview strategy.
2025-12-28 15:51:56 -07:00

19 KiB
Raw Permalink Blame History


> product_inventory@0.0.1 test
> jest src/mediaManager.integration.test.ts
 
console.log
MediaService: Getting unified state for SKU SKU-123
 
at MediaService.log [as getUnifiedMediaState] (src/services/MediaService.ts:69:13)
 
console.warn
Failed to get properties for IMG_001.jpg
 
96 | }
97 | } catch (e) {
> 98 | console.warn(`Failed to get properties for ${f.getName()}`)
| ^
99 | }
100 | return { file: f, shopifyId, galleryOrder }
101 | })
 
at warn (src/services/MediaService.ts:98:21)
at Array.map (<anonymous>)
at MediaService.map [as getUnifiedMediaState] (src/services/MediaService.ts:86:39)
at Object.<anonymous> (src/mediaManager.integration.test.ts:99:36)
 
console.log
MediaService: Getting unified state for SKU SKU-123
 
at MediaService.log [as getUnifiedMediaState] (src/services/MediaService.ts:69:13)
 
console.warn
Failed to get properties for new.jpg
 
96 | }
97 | } catch (e) {
> 98 | console.warn(`Failed to get properties for ${f.getName()}`)
| ^
99 | }
100 | return { file: f, shopifyId, galleryOrder }
101 | })
 
at warn (src/services/MediaService.ts:98:21)
at Array.map (<anonymous>)
at MediaService.map [as getUnifiedMediaState] (src/services/MediaService.ts:86:39)
at Object.<anonymous> (src/mediaManager.integration.test.ts:120:36)
 
console.log
MediaService: Getting unified state for SKU SKU-123
 
at MediaService.log [as getUnifiedMediaState] (src/services/MediaService.ts:69:13)
 
console.log
MediaService: Processing changes for SKU SKU-123
 
at MediaService.log [as processMediaChanges] (src/services/MediaService.ts:162:13)
 
console.log
MediaService: Processing changes for SKU SKU-123
 
at MediaService.log [as processMediaChanges] (src/services/MediaService.ts:162:13)
 
console.log
MediaService: Processing changes for SKU SKU-123
 
at MediaService.log [as processMediaChanges] (src/services/MediaService.ts:162:13)
 
console.log
Adopting Orphan: backfill.jpg
 
at log (src/services/MediaService.ts:200:21)
at Array.forEach (<anonymous>)
 
console.log
MediaService: Processing changes for SKU SKU-123
 
at MediaService.log [as processMediaChanges] (src/services/MediaService.ts:162:13)
 
console.log
Deleting item: delete_me.jpg
 
at log (src/services/MediaService.ts:182:17)
at Array.forEach (<anonymous>)
 
console.log
MediaService: Processing changes for SKU SKU-123
 
at MediaService.log [as processMediaChanges] (src/services/MediaService.ts:162:13)
 
node.exe : FAIL src/mediaManager.integration.test.ts
At C:\nvm4w\nodejs\npm.ps1:29 char:3
+ & $NODE_EXE $NPM_CLI_JS $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (FAIL src/mediaM...gration.test.ts:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
 
MediaService V2 Integration Logic
getUnifiedMediaState (Phase A)
× should match Drive and Shopify items by ID (Strong Link) (34 ms)
√ should identify Drive-Only items (New Uploads) (3 ms)
√ should identify Shopify-Only items (1 ms)
processMediaChanges (Phase B)
× should rename Drive files sequentially (3 ms)
× should call Shopify Reorder Mutation (1 ms)
× should backfill Shopify-Only items to Drive (1 ms)
√ should delete removed items (2 ms)
√ should upload Drive-Only items (1 ms)
 
● MediaService V2 Integration Logic › getUnifiedMediaState (Phase A) › should match Drive and Shopify
items by ID (Strong Link)
 
expect(received).toHaveLength(expected)
 
Expected length: 1
Received length: 2
Received array: [{"contentUrl": "https://drive.google.com/uc?export=download&id=drive_1", "driveId":
"drive_1", "filename": "IMG_001.jpg", "galleryOrder": 9999, "id": "drive_1", "mimeType": "image/jpeg",
"shopifyId": null, "source": "drive_only", "status": "active", "thumbnail":
"data:image/jpeg;base64,base64encoded"}, {"driveId": null, "filename": "Orphaned Media", "galleryOrder": 10000,
"id": "gid://shopify/Media/100", "shopifyId": "gid://shopify/Media/100", "source": "shopify_only", "status":
"active", "thumbnail": "http://shopify.com/img.jpg"}]
 
100 |
101 | // Expect
> 102 | expect(result).toHaveLength(1)
| ^
103 |
expect(result[0].driveId).toBe("drive_1")
104 |
expect(result[0].shopifyId).toBe("gid://shopify/Media/100")
105 |
expect(result[0].source).toBe("synced")
 
at Object.<anonymous> (src/mediaManager.integration.test.ts:102:28)
 
● MediaService V2 Integration Logic › processMediaChanges (Phase B) › should rename Drive files
sequentially
 
expect(jest.fn()).toHaveBeenCalledWith(...expected)
 
Expected: "d1", "SKU-123_0001.jpg"
Received
1: "d1", "SKU-123_1766961960369.jpg"
2: "d2", "SKU-123_1766961960369.jpg"
 
Number of calls: 2
 
157 |
158 | // Assert
> 159 |
expect(mockDrive.renameFile).toHaveBeenCalledWith("d1",
"SKU-123_0001.jpg")
| ^
160 |
expect(mockDrive.renameFile).toHaveBeenCalledWith("d2",
"SKU-123_0002.jpg")
161 | })
162 |
 
at Object.<anonymous> (src/mediaManager.integration.test.ts:159:42)
 
● MediaService V2 Integration Logic › processMediaChanges (Phase B) › should call Shopify Reorder
Mutation
 
expect(jest.fn()).toHaveBeenCalledWith(...expected)
 
Expected: "gid://shopify/Product/123", [{"id": "s10", "newPosition": "0"}, {"id": "s20", "newPosition":
"1"}]
 
Number of calls: 0
 
170 | service.processMediaChanges("SKU-123",
finalState, dummyPid)
171 |
> 172 |
expect(mockShopify.productReorderMedia).toHaveBeenCalledWith(dummyPid, [
| ^
173 | { id: "s10", newPosition:
"0" },
174 | { id: "s20", newPosition:
"1" }
175 | ])
 
at Object.<anonymous> (src/mediaManager.integration.test.ts:172:53)
 
● MediaService V2 Integration Logic › processMediaChanges (Phase B) › should backfill Shopify-Only
items to Drive
 
expect(jest.fn()).toHaveBeenCalled()
 
Expected number of calls: >= 1
Received number of calls: 0
 
189 | service.processMediaChanges("SKU-123",
finalState, dummyPid)
190 |
> 191 |
expect(mockDrive.createFile).toHaveBeenCalled()
| ^
192 | expect(mockDrive.updateFileProperties).toHaveBeenCalledWit
h("new_created_file_id", { shopify_media_id: "s99" })
193 | })
194 |
 
at Object.<anonymous> (src/mediaManager.integration.test.ts:191:42)
 
-----------------|---------|----------|---------|---------|-------------------------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------------------------------------
All files | 70.98 | 61.7 | 80 | 72.18 |
MediaService.ts | 70.98 | 61.7 | 80 | 72.18 | 28-65,91-95,105-108,117-118,207-226,280-281,330
-----------------|---------|----------|---------|---------|-------------------------------------------------
Test Suites: 1 failed, 1 total
Tests: 4 failed, 4 passed, 8 total
Snapshots: 0 total
Time: 1.344 s, estimated 3 s
Ran all test suites matching /src\\mediaManager.integration.test.ts/i.