- 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.
217 lines
19 KiB
Plaintext
217 lines
19 KiB
Plaintext
|
||
> 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
|
||
|
||
[0m [90m 96 |[39m }
|
||
[90m 97 |[39m } [36mcatch[39m (e) {
|
||
[31m[1m>[22m[39m[90m 98 |[39m console[33m.[39mwarn([32m`Failed to get properties for ${f.getName()}`[39m)
|
||
[90m |[39m [31m[1m^[22m[39m
|
||
[90m 99 |[39m }
|
||
[90m 100 |[39m [36mreturn[39m { file[33m:[39m f[33m,[39m shopifyId[33m,[39m galleryOrder }
|
||
[90m 101 |[39m })[0m
|
||
|
||
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
|
||
|
||
[0m [90m 96 |[39m }
|
||
[90m 97 |[39m } [36mcatch[39m (e) {
|
||
[31m[1m>[22m[39m[90m 98 |[39m console[33m.[39mwarn([32m`Failed to get properties for ${f.getName()}`[39m)
|
||
[90m |[39m [31m[1m^[22m[39m
|
||
[90m 99 |[39m }
|
||
[90m 100 |[39m [36mreturn[39m { file[33m:[39m f[33m,[39m shopifyId[33m,[39m galleryOrder }
|
||
[90m 101 |[39m })[0m
|
||
|
||
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"}]
|
||
|
||
[0m [90m 100 |[39m
|
||
[90m 101 |[39m [90m// Expect[39m
|
||
[31m[1m>[22m[39m[90m 102 |[39m expect(result)[33m.[39mtoHaveLength([35m1[39m)
|
||
[90m |[39m [31m[1m^[22m[39m
|
||
[90m 103 |[39m
|
||
expect(result[[35m0[39m][33m.[39mdriveId)[33m.[39mtoBe([32m"drive_1"[39m)
|
||
[90m 104 |[39m
|
||
expect(result[[35m0[39m][33m.[39mshopifyId)[33m.[39mtoBe([32m"gid://shopify/Media/100"[39m)
|
||
[90m 105 |[39m
|
||
expect(result[[35m0[39m][33m.[39msource)[33m.[39mtoBe([32m"synced"[39m)[0m
|
||
|
||
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
|
||
|
||
[0m [90m 157 |[39m
|
||
[90m 158 |[39m [90m// Assert[39m
|
||
[31m[1m>[22m[39m[90m 159 |[39m
|
||
expect(mockDrive[33m.[39mrenameFile)[33m.[39mtoHaveBeenCalledWith([32m"d1"[39m[33m,[39m
|
||
[32m"SKU-123_0001.jpg"[39m)
|
||
[90m |[39m [31m[1m^[22m[39m
|
||
[90m 160 |[39m
|
||
expect(mockDrive[33m.[39mrenameFile)[33m.[39mtoHaveBeenCalledWith([32m"d2"[39m[33m,[39m
|
||
[32m"SKU-123_0002.jpg"[39m)
|
||
[90m 161 |[39m })
|
||
[90m 162 |[39m[0m
|
||
|
||
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
|
||
|
||
[0m [90m 170 |[39m service[33m.[39mprocessMediaChanges([32m"SKU-123"[39m[33m,[39m
|
||
finalState[33m,[39m dummyPid)
|
||
[90m 171 |[39m
|
||
[31m[1m>[22m[39m[90m 172 |[39m
|
||
expect(mockShopify[33m.[39mproductReorderMedia)[33m.[39mtoHaveBeenCalledWith(dummyPid[33m,[39m [
|
||
[90m |[39m [31m[1m^[22m[39m
|
||
[90m 173 |[39m { id[33m:[39m [32m"s10"[39m[33m,[39m newPosition[33m:[39m
|
||
[32m"0"[39m }[33m,[39m
|
||
[90m 174 |[39m { id[33m:[39m [32m"s20"[39m[33m,[39m newPosition[33m:[39m
|
||
[32m"1"[39m }
|
||
[90m 175 |[39m ])[0m
|
||
|
||
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
|
||
|
||
[0m [90m 189 |[39m service[33m.[39mprocessMediaChanges([32m"SKU-123"[39m[33m,[39m
|
||
finalState[33m,[39m dummyPid)
|
||
[90m 190 |[39m
|
||
[31m[1m>[22m[39m[90m 191 |[39m
|
||
expect(mockDrive[33m.[39mcreateFile)[33m.[39mtoHaveBeenCalled()
|
||
[90m |[39m [31m[1m^[22m[39m
|
||
[90m 192 |[39m expect(mockDrive[33m.[39mupdateFileProperties)[33m.[39mtoHaveBeenCalledWit
|
||
h([32m"new_created_file_id"[39m[33m,[39m { shopify_media_id[33m:[39m [32m"s99"[39m })
|
||
[90m 193 |[39m })
|
||
[90m 194 |[39m[0m
|
||
|
||
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.
|