Fix Drive video upload to Shopify
- Detect video mime types in MediaService to set correct resource ('VIDEO') and mediaContentType.
- Add fileSize to stagedUploadsCreate payload as required by Shopify for videos.
- Add safety check for missing upload targets to prevent crashes.
- Implement getSize in MockDriveService.
- Add unit test in MediaService.test.ts to verify correct resource and fileSize handling for video uploads.
- Update mock in mediaManager.integration.test.ts to support getSize().
This commit is contained in:
@ -163,4 +163,46 @@ describe("MediaService Robust Sync", () => {
|
||||
expect(spyRename).toHaveBeenCalledWith(f1.getId(), expect.stringMatching(/^SKU123_\d+\.jpg$/))
|
||||
expect(spyRename).not.toHaveBeenCalledWith(f2.getId(), expect.anything())
|
||||
})
|
||||
test("Upload: Handles Video Uploads with correct resource type", () => {
|
||||
const folder = driveService.getOrCreateFolder("SKU_VIDEO", "root")
|
||||
|
||||
// Mock Video Blob
|
||||
const videoBlob = {
|
||||
getName: () => "video.mp4",
|
||||
getBytes: () => [],
|
||||
getContentType: () => "video/mp4",
|
||||
getThumbnail: () => ({ getBytes: () => [] })
|
||||
} as any
|
||||
|
||||
const vidFile = driveService.saveFile(videoBlob, folder.getId())
|
||||
|
||||
const finalState = [{
|
||||
id: vidFile.getId(),
|
||||
driveId: vidFile.getId(),
|
||||
filename: "video.mp4",
|
||||
source: "drive_only"
|
||||
}]
|
||||
|
||||
const spyStaged = jest.spyOn(shopifyService, 'stagedUploadsCreate')
|
||||
const spyCreate = jest.spyOn(shopifyService, 'productCreateMedia')
|
||||
|
||||
mediaService.processMediaChanges("SKU_VIDEO", finalState, "pid")
|
||||
|
||||
// 1. Verify stagedUploadsCreate called with resource="VIDEO" and fileSize
|
||||
expect(spyStaged).toHaveBeenCalledWith(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
resource: "VIDEO",
|
||||
mimeType: "video/mp4",
|
||||
filename: "video.mp4",
|
||||
fileSize: "0" // 0 because mock bytes are empty
|
||||
})
|
||||
]))
|
||||
|
||||
// 2. Verify productCreateMedia called with mediaContentType="VIDEO"
|
||||
expect(spyCreate).toHaveBeenCalledWith("pid", expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
mediaContentType: "VIDEO"
|
||||
})
|
||||
]))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user